Skip to content

Commit

Permalink
Merge pull request #28 from XbyOrange/v1.2.1
Browse files Browse the repository at this point in the history
V1.2.1
  • Loading branch information
javierbrea authored Oct 22, 2019
2 parents 650b9eb + a22baab commit 1bf25f2
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Removed
### BREAKING CHANGES

## [1.2.1] - 2019-10-22
### Fixed
- Do not throw an error on duplicated ids detected while reading server side data.

## [1.2.0] - 2019-10-19
### Changed
- Upgrade dependencies
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const ConnectedModule = connect(

Methods for prefetching data on server side rendering are available too. When data is prefetched in server side, the connect function will pass the `value` property calculated on server side to the components directly. It will not modify the `loading` property until the first load on client side is finished (At first client-side load, the resource will not be considered as `loading` to maintain the server-side value in the component until it finish loading).

> __It is important to define custom an unique "uuids" for your mercury sources when are going to be read on server side. Otherwise, the `readServerSide` method will throw an error if detects duplicated "ids".__
> __It is important to define custom an unique "uuids" for your mercury sources when are going to be read on server side. Otherwise, the `readServerSide` method will trace a warning if detects duplicated "ids".__
### Server side data methods and components

Expand Down
45 changes: 32 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xbyorange/react-mercury",
"version": "1.2.0",
"version": "1.2.1",
"description": "Plugin for connecting React components with Mercury origins or selectors",
"keywords": [
"reactive",
Expand Down
4 changes: 2 additions & 2 deletions src/readServerSideData.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const resultsToObject = results => {
return Promise.resolve(
results.reduce((allResults, result) => {
if (allResults.hasOwnProperty(result.id)) {
throw new Error(
`Duplicated mercury id ${result.id} detected in server-side-data. Data will not be assigned properly to correspondent sources in client-side`
console.warn(
`Duplicated mercury id ${result.id} detected in server-side-data. Data may not be assigned properly to correspondent sources in client-side`
);
}
allResults[result.id] = result.value;
Expand Down
20 changes: 12 additions & 8 deletions test/connect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,22 @@ describe("react connect plugin", () => {
wrapper.unmount();
});

it("should throw an error when reading server side data if there are duplicated mercury sources ids", async () => {
it("should trace a warning when reading server side data if there are duplicated mercury sources ids", async () => {
expect.assertions(1);
const fooBooksServerSideSelector = new Selector(booksServerSide, result => result, []);
const fooBooksServerSideSelector2 = new Selector(booksServerSide, result => result, []);
sandbox.spy(console, "warn");
const fooBooksServerSideSelector = new Selector(booksServerSide, result => result, {
defaultValue: [],
uuid: "foo-id"
});
const fooBooksServerSideSelector2 = new Selector(booksServerSide, result => result, {
defaultValue: [],
uuid: "foo-id"
});
readOnServerSide(fooBooksServerSideSelector);
readOnServerSide(fooBooksServerSideSelector2);

try {
await readServerSideData();
} catch (err) {
expect(err.message).toEqual(expect.stringContaining(fooBooksServerSideSelector2._id));
}
await readServerSideData();
expect(console.warn.getCall(0).args[0]).toEqual(expect.stringContaining("foo-id"));
});

it("should render serverSide properties of different selectors with defined uuid, even when are using same origin", async () => {
Expand Down

0 comments on commit 1bf25f2

Please sign in to comment.