Skip to content

Commit 650b9eb

Browse files
authored
Merge pull request #26 from XbyOrange/v1.2.0
V1.2.0
2 parents 6144299 + ae0f98b commit 650b9eb

18 files changed

Lines changed: 5107 additions & 9856 deletions

.eslintrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
2+
"env": {
3+
"node": true,
4+
"es6": true
5+
},
26
"parser": "babel-eslint",
37
"plugins": ["prettier"],
48
"rules": {
@@ -9,6 +13,7 @@
913
"parser": "flow"
1014
}
1115
],
16+
"no-undef": "error",
1217
"no-unused-vars": ["error", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }]
1318
},
1419
"extends": ["plugin:react/recommended", "prettier"],

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111
### Removed
1212
### BREAKING CHANGES
1313

14+
## [1.2.0] - 2019-10-19
15+
### Changed
16+
- Upgrade dependencies
17+
- Rename server side data methods. Maintain old ones due to retrocompatibility.
18+
- Use mercury ids for identification during server-side-data.
19+
20+
### Fixed
21+
- Fix demo installation
22+
1423
## [1.1.0] - 2019-08-21
1524
### Added
1625
- Add server side data behavior tests and documentation.

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,23 @@ export const ConnectedModule = connect(
181181

182182
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).
183183

184+
> __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".__
185+
184186
### Server side data methods and components
185187

186-
* `addServerSideData(source)`
188+
* `readOnServerSide(source)`
189+
* Alias - `addServerSideData`
187190
* Arguments
188-
* source - `<Object> or <Array> of <Objects>` Mercury source or sources that should be read when `readServerSideData` method is executed. Can be Mercury origins or selectors of any type, queried or not.
189-
* `readServerSideData([source])`
191+
* source - `<Object> or <Array> of <Objects>` Mercury source or sources that should be read when `readServerSide` method is executed. Can be Mercury origins or selectors of any type, queried or not.
192+
* `readServerSide([source])`
193+
* Alias - `readServerSideData`
190194
* Arguments
191-
* source - `<Object> or <Array> of <Objects>` Mercury source or sources that should be read when `readServerSideData` method is executed. Can be Mercury origins or selectors of any type, queried or not.
195+
* source - `<Object> or <Array> of <Objects>` Mercury source or sources. Will be added to be read with the `readOnServerSide` method.
192196
* Returns
193-
* `<Object>` This method is asynchronous, and returns an object containing all server side data ready to be set on the `<ServerSideData>` context component.
194-
* `<ServerSideData data={data} clientSide={true}><App/></ServerSideData>` Component that sets the result of the `readServerSideData` method in a context to make it available from all mercury connected children components.
197+
* `<Object>` This method is asynchronous, and, when resolved, it returns an object containing all server side data ready to be set on the `<ServerSideData>` context component.
198+
* `<ServerSideData data={data} clientSide={true}><App/></ServerSideData>` Component that sets the result of the `readServerSide` method in a context to make it available from all mercury connected children components.
195199
* Props
196-
* data - `<Object>` Object containing the result of the `readServerSideData` method.
200+
* data - `<Object>` Object containing the result of the `readServerSide` method.
197201
* clientSide - `<Boolean>` If false, the connect method will not dispatch automatically the read method of the sources marked as "server-side", so, for example, api requests will not be repeated on client side, and data retrieved in server side will be always passed to connected components.
198202

199203
### Example of server side prefecth implementation in a Next project:
@@ -202,10 +206,10 @@ In the next example, the data of the "myDataSource" mercury source will be fetch
202206

203207
```jsx
204208
// src/home.js
205-
import { addServerSideData, connect } from "@xbyorange/react-mercury";
209+
import { readOnServerSide, connect } from "@xbyorange/react-mercury";
206210
import { myDataSource } from "src/data";
207211

208-
addServerSideData(myDataSource); // source is marked to be read when readServerSideData method is executed.
212+
readOnServerSide(myDataSource); // source is marked to be read when readServerSide method is executed.
209213

210214
export const HomeComponent = ({data}) => {
211215
if(data.loading) {
@@ -224,7 +228,7 @@ export const Home = connect(mapDataSourceToProps)(HomeComponent)
224228

225229
```jsx
226230
// pages/index.js
227-
import { readServerSideData, ServerSideData } from "@xbyorange/react-mercury";
231+
import { readServerSide, ServerSideData } from "@xbyorange/react-mercury";
228232
import { Home } from "src/home";
229233

230234
const Page = ({ serverSideData }) => (
@@ -235,7 +239,7 @@ const Page = ({ serverSideData }) => (
235239

236240
Page.getInitialProps = async () => {
237241
return {
238-
serverSideData: await readServerSideData()
242+
serverSideData: await readServerSide()
239243
}
240244
}
241245

demo/.eslintrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"globals": {
3+
"document": true,
4+
"window": true
5+
}
6+
}

demo/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/node_modules
66
/.pnp
77
.pnp.js
8+
/src/react-mercury
89

910
# testing
1011
/coverage

demo/config-overrides.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module.exports = function override(config) {
2+
// Remove eslint execution for running app
3+
let eslintRuleIndex;
4+
config.module.rules.forEach((rule, ruleIndex) => {
5+
if (rule.use && Array.isArray(rule.use)) {
6+
rule.use.forEach(loaderDetails => {
7+
if (loaderDetails.loader.indexOf("eslint-loader") > -1) {
8+
eslintRuleIndex = ruleIndex;
9+
}
10+
});
11+
}
12+
});
13+
if (eslintRuleIndex) {
14+
config.module.rules.splice(eslintRuleIndex, 1);
15+
}
16+
17+
// Add babel alias for react-mercury
18+
config.module.rules.unshift({
19+
test: /\.(js|jsx|mjs)$/,
20+
include: /src/,
21+
loader: require.resolve("babel-loader"),
22+
options: {
23+
plugins: [
24+
[
25+
"module-resolver",
26+
{
27+
root: ["."],
28+
alias: {
29+
"@xbyorange/react-mercury": "./src/react-mercury/react-mercury.esm.js"
30+
}
31+
}
32+
]
33+
],
34+
cacheDirectory: true
35+
}
36+
});
37+
38+
return config;
39+
};

0 commit comments

Comments
 (0)