Skip to content
This repository was archived by the owner on Mar 11, 2021. It is now read-only.

Commit f5f1c96

Browse files
author
nghiepit
committed
Polyfill
1 parent a154d3c commit f5f1c96

File tree

6 files changed

+921
-947
lines changed

6 files changed

+921
-947
lines changed

.babelrc

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
{
2-
"presets": ["next/babel"],
2+
"presets": [
3+
[
4+
"next/babel",
5+
{
6+
"preset-env": {
7+
"useBuiltIns": "usage"
8+
},
9+
"transform-runtime": {
10+
"corejs": false,
11+
"helpers": false
12+
}
13+
}
14+
]
15+
],
316
"plugins": [
417
["@babel/plugin-proposal-decorators", {"legacy": true}],
518
["@babel/plugin-proposal-class-properties", {"loose": true}]

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
"build": "npm run clean && npm run babel",
1515
"prepublishOnly": "npm run build"
1616
},
17+
"dependencies": {},
1718
"devDependencies": {
1819
"@babel/cli": "^7.2.3",
1920
"@babel/core": "^7.2.2",
2021
"@babel/plugin-proposal-class-properties": "^7.3.0",
2122
"@babel/plugin-proposal-decorators": "^7.3.0",
22-
"next": "^7.0.2",
23-
"react": "^16.7.0",
23+
"next": "^8.0.1",
24+
"react": "^16.8.1",
2425
"rimraf": "^2.6.3"
2526
},
2627
"peerDependencies": {

src/index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const __NEXT_MOBX_STORE__ = new Map();
66
export class BaseStore {
77
constructor(props = {}) {
88
for (const prop in props) {
9-
// Convert JSON string to Map string for client
9+
// Convert JSON to Map
1010
this[prop] = jsonToMap(props[prop]);
1111
}
1212
}
@@ -19,24 +19,25 @@ export class BaseStore {
1919
}
2020

2121
export const getOrCreateStore = (storeKeyName, Store) => initialState => {
22-
// Convert Map to JSON string for client
22+
// Convert Map to JSON
2323
if (initialState) {
2424
for (const itemState in initialState) {
2525
try {
2626
const dataMap = initialState[itemState];
27+
2728
if (dataMap.toJS() instanceof Map) {
2829
initialState[itemState] = mapToJson(dataMap);
2930
}
3031
} catch (e) {}
3132
}
3233
}
3334

34-
// Always make a new store if server, otherwise state is shared between requests
35+
// Always make a new store if server
3536
if (isServer) {
3637
return new Store(initialState);
3738
}
3839

39-
// Create store if unavailable on the client and set it on the window object
40+
// Create store if unavailable on the client
4041
if (!__NEXT_MOBX_STORE__.has(storeKeyName)) {
4142
__NEXT_MOBX_STORE__.set(storeKeyName, new Store(initialState));
4243
}

src/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const isServer = !process.browser;
22

3-
// getCounterStore=> counterStore
3+
// getCounterStore => counterStore
44
export const getKeyNameStore = fnName =>
55
fnName.replace(/^get(.)/, (match, p1) => p1.toLowerCase());
66

src/with-mobx.js

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default (getStores = {}) => App => {
3838

3939
render() {
4040
const {initialMobxState, ...props} = this.props;
41+
4142
return <App {...props} store={{...this.store}} />;
4243
}
4344
};

0 commit comments

Comments
 (0)