@modern-js/plugin-state 1.1.3-rc.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -8
- package/dist/js/modern/runtime/index.js +2 -4
- package/dist/js/modern/runtime/plugin.js +12 -8
- package/dist/js/node/runtime/index.js +17 -16
- package/dist/js/node/runtime/plugin.js +15 -8
- package/dist/js/treeshaking/runtime/index.js +2 -4
- package/dist/js/treeshaking/runtime/plugin.js +14 -9
- package/dist/types/runtime/index.d.ts +2 -3
- package/dist/types/runtime/plugin.d.ts +8 -14
- package/jest.config.js +8 -0
- package/package.json +23 -14
- package/src/runtime/index.tsx +1 -6
- package/src/runtime/plugin.tsx +14 -17
- package/tests/index.test.ts +9 -0
- package/tsconfig.json +1 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,16 +1,42 @@
|
|
|
1
1
|
# @modern-js/plugin-state
|
|
2
2
|
|
|
3
|
-
## 1.
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- cfe11628: Make Modern.js self bootstraping
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [fc71e36f]
|
|
12
|
+
- Updated dependencies [a2cb9abc]
|
|
13
|
+
- Updated dependencies [cfe11628]
|
|
14
|
+
- @modern-js/core@1.3.0
|
|
15
|
+
- @modern-js/runtime-core@1.2.0
|
|
16
|
+
|
|
17
|
+
## 1.1.4
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 4a281912: fix: app init function not work
|
|
22
|
+
- Updated dependencies [4a281912]
|
|
23
|
+
- Updated dependencies [4a281912]
|
|
24
|
+
- Updated dependencies [eb026119]
|
|
25
|
+
- @modern-js/runtime-core@1.1.3
|
|
26
|
+
|
|
27
|
+
## 1.1.3
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
|
6
30
|
|
|
7
|
-
-
|
|
8
|
-
- Updated dependencies [
|
|
9
|
-
- Updated dependencies [
|
|
10
|
-
- Updated dependencies [
|
|
11
|
-
- Updated dependencies [
|
|
12
|
-
|
|
13
|
-
|
|
31
|
+
- 4406c2db: fix: avoid fetching data again when ssr succeeds
|
|
32
|
+
- Updated dependencies [90eeb72c]
|
|
33
|
+
- Updated dependencies [e04914ce]
|
|
34
|
+
- Updated dependencies [4406c2db]
|
|
35
|
+
- Updated dependencies [5a4c557e]
|
|
36
|
+
- Updated dependencies [e04914ce]
|
|
37
|
+
- Updated dependencies [ecb344dc]
|
|
38
|
+
- @modern-js/core@1.2.0
|
|
39
|
+
- @modern-js/runtime-core@1.1.2
|
|
14
40
|
|
|
15
41
|
## 1.1.2
|
|
16
42
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
// eslint-disable-next-line filenames/match-exported
|
|
2
|
-
import statePlugin from "./plugin";
|
|
3
1
|
export * from '@modern-js-reduck/react';
|
|
4
2
|
export { model, createStore } from '@modern-js-reduck/store';
|
|
5
|
-
export
|
|
6
|
-
export
|
|
3
|
+
export { default } from "./plugin";
|
|
4
|
+
export * from "./plugin";
|
|
@@ -9,21 +9,25 @@ import { useContext } from 'react';
|
|
|
9
9
|
import { createPlugin, RuntimeReactContext } from '@modern-js/runtime-core';
|
|
10
10
|
import { createStore } from '@modern-js-reduck/store';
|
|
11
11
|
import { Provider } from '@modern-js-reduck/react';
|
|
12
|
+
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
12
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
14
|
|
|
14
15
|
const state = config => createPlugin(() => ({
|
|
15
16
|
hoc({
|
|
16
17
|
App
|
|
17
18
|
}, next) {
|
|
19
|
+
const getStateApp = props => {
|
|
20
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
21
|
+
const context = useContext(RuntimeReactContext);
|
|
22
|
+
return /*#__PURE__*/_jsx(Provider, {
|
|
23
|
+
store: context.store,
|
|
24
|
+
config: config,
|
|
25
|
+
children: /*#__PURE__*/_jsx(App, _objectSpread({}, props))
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
18
29
|
return next({
|
|
19
|
-
App:
|
|
20
|
-
const context = useContext(RuntimeReactContext);
|
|
21
|
-
return /*#__PURE__*/_jsx(Provider, {
|
|
22
|
-
store: context.store,
|
|
23
|
-
config: config,
|
|
24
|
-
children: /*#__PURE__*/_jsx(App, _objectSpread({}, props))
|
|
25
|
-
});
|
|
26
|
-
}
|
|
30
|
+
App: hoistNonReactStatics(getStateApp, App)
|
|
27
31
|
});
|
|
28
32
|
},
|
|
29
33
|
|
|
@@ -13,7 +13,12 @@ Object.defineProperty(exports, "createStore", {
|
|
|
13
13
|
return _store.createStore;
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
exports
|
|
16
|
+
Object.defineProperty(exports, "default", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () {
|
|
19
|
+
return _plugin.default;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
17
22
|
Object.defineProperty(exports, "model", {
|
|
18
23
|
enumerable: true,
|
|
19
24
|
get: function () {
|
|
@@ -21,40 +26,36 @@ Object.defineProperty(exports, "model", {
|
|
|
21
26
|
}
|
|
22
27
|
});
|
|
23
28
|
|
|
24
|
-
var
|
|
29
|
+
var _react = require("@modern-js-reduck/react");
|
|
25
30
|
|
|
26
|
-
Object.keys(
|
|
31
|
+
Object.keys(_react).forEach(function (key) {
|
|
27
32
|
if (key === "default" || key === "__esModule") return;
|
|
28
33
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
29
|
-
if (key in exports && exports[key] ===
|
|
34
|
+
if (key in exports && exports[key] === _react[key]) return;
|
|
30
35
|
Object.defineProperty(exports, key, {
|
|
31
36
|
enumerable: true,
|
|
32
37
|
get: function () {
|
|
33
|
-
return
|
|
38
|
+
return _react[key];
|
|
34
39
|
}
|
|
35
40
|
});
|
|
36
41
|
});
|
|
37
42
|
|
|
38
|
-
var
|
|
43
|
+
var _store = require("@modern-js-reduck/store");
|
|
39
44
|
|
|
40
|
-
|
|
45
|
+
var _plugin = _interopRequireWildcard(require("./plugin"));
|
|
46
|
+
|
|
47
|
+
Object.keys(_plugin).forEach(function (key) {
|
|
41
48
|
if (key === "default" || key === "__esModule") return;
|
|
42
49
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
43
|
-
if (key in exports && exports[key] ===
|
|
50
|
+
if (key in exports && exports[key] === _plugin[key]) return;
|
|
44
51
|
Object.defineProperty(exports, key, {
|
|
45
52
|
enumerable: true,
|
|
46
53
|
get: function () {
|
|
47
|
-
return
|
|
54
|
+
return _plugin[key];
|
|
48
55
|
}
|
|
49
56
|
});
|
|
50
57
|
});
|
|
51
58
|
|
|
52
|
-
var _store = require("@modern-js-reduck/store");
|
|
53
|
-
|
|
54
59
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
55
60
|
|
|
56
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
57
|
-
|
|
58
|
-
// eslint-disable-next-line filenames/match-exported
|
|
59
|
-
var _default = _plugin.default;
|
|
60
|
-
exports.default = _default;
|
|
61
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -14,6 +14,8 @@ var _store = require("@modern-js-reduck/store");
|
|
|
14
14
|
|
|
15
15
|
var _react2 = require("@modern-js-reduck/react");
|
|
16
16
|
|
|
17
|
+
var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
|
|
18
|
+
|
|
17
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
20
|
|
|
19
21
|
var _plugins = require("../plugins");
|
|
@@ -30,6 +32,8 @@ Object.keys(_plugins).forEach(function (key) {
|
|
|
30
32
|
});
|
|
31
33
|
});
|
|
32
34
|
|
|
35
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
36
|
+
|
|
33
37
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
34
38
|
|
|
35
39
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -40,15 +44,18 @@ const state = config => (0, _runtimeCore.createPlugin)(() => ({
|
|
|
40
44
|
hoc({
|
|
41
45
|
App
|
|
42
46
|
}, next) {
|
|
47
|
+
const getStateApp = props => {
|
|
48
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
49
|
+
const context = (0, _react.useContext)(_runtimeCore.RuntimeReactContext);
|
|
50
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Provider, {
|
|
51
|
+
store: context.store,
|
|
52
|
+
config: config,
|
|
53
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(App, _objectSpread({}, props))
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
43
57
|
return next({
|
|
44
|
-
App:
|
|
45
|
-
const context = (0, _react.useContext)(_runtimeCore.RuntimeReactContext);
|
|
46
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Provider, {
|
|
47
|
-
store: context.store,
|
|
48
|
-
config: config,
|
|
49
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(App, _objectSpread({}, props))
|
|
50
|
-
});
|
|
51
|
-
}
|
|
58
|
+
App: (0, _hoistNonReactStatics.default)(getStateApp, App)
|
|
52
59
|
});
|
|
53
60
|
},
|
|
54
61
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
// eslint-disable-next-line filenames/match-exported
|
|
2
|
-
import statePlugin from "./plugin";
|
|
3
1
|
export * from '@modern-js-reduck/react';
|
|
4
2
|
export { model, createStore } from '@modern-js-reduck/store';
|
|
5
|
-
export
|
|
6
|
-
export
|
|
3
|
+
export { default } from "./plugin";
|
|
4
|
+
export * from "./plugin";
|
|
@@ -9,22 +9,27 @@ import { useContext } from 'react';
|
|
|
9
9
|
import { createPlugin, RuntimeReactContext } from '@modern-js/runtime-core';
|
|
10
10
|
import { createStore } from '@modern-js-reduck/store';
|
|
11
11
|
import { Provider } from '@modern-js-reduck/react';
|
|
12
|
+
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
12
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
14
|
|
|
14
15
|
var state = function state(config) {
|
|
15
16
|
return createPlugin(function () {
|
|
16
17
|
return {
|
|
17
18
|
hoc: function hoc(_ref, next) {
|
|
18
|
-
var
|
|
19
|
+
var App = _ref.App;
|
|
20
|
+
|
|
21
|
+
var getStateApp = function getStateApp(props) {
|
|
22
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
23
|
+
var context = useContext(RuntimeReactContext);
|
|
24
|
+
return /*#__PURE__*/_jsx(Provider, {
|
|
25
|
+
store: context.store,
|
|
26
|
+
config: config,
|
|
27
|
+
children: /*#__PURE__*/_jsx(App, _objectSpread({}, props))
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
19
31
|
return next({
|
|
20
|
-
App:
|
|
21
|
-
var context = useContext(RuntimeReactContext);
|
|
22
|
-
return /*#__PURE__*/_jsx(Provider, {
|
|
23
|
-
store: context.store,
|
|
24
|
-
config: config,
|
|
25
|
-
children: /*#__PURE__*/_jsx(_App, _objectSpread({}, props))
|
|
26
|
-
});
|
|
27
|
-
}
|
|
32
|
+
App: hoistNonReactStatics(getStateApp, App)
|
|
28
33
|
});
|
|
29
34
|
},
|
|
30
35
|
init: function init(_ref2, next) {
|
|
@@ -7,36 +7,30 @@ declare module '@modern-js/runtime-core' {
|
|
|
7
7
|
interface TRuntimeContext {
|
|
8
8
|
store: Store;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
interface Window {
|
|
13
|
-
_SSR_DATA?: {
|
|
14
|
-
data: {
|
|
15
|
-
storeState: any;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
10
|
+
interface SSRData {
|
|
11
|
+
storeState: any;
|
|
18
12
|
}
|
|
19
13
|
}
|
|
20
14
|
declare type PluginProps = Parameters<typeof createStore>[0];
|
|
21
|
-
declare const state: (config: PluginProps) => import("@modern-js/
|
|
15
|
+
declare const state: (config: PluginProps) => import("@modern-js/core").Plugin<Partial<import("@modern-js/runtime-core").Progresses2Threads<{
|
|
22
16
|
hoc: import("@modern-js/runtime-core").Pipeline<{
|
|
23
17
|
App: import("react").ComponentType<any>;
|
|
24
18
|
}, import("react").ComponentType<any>>;
|
|
25
19
|
provide: import("@modern-js/runtime-core").Pipeline<{
|
|
26
20
|
element: JSX.Element;
|
|
27
|
-
props: import("@modern-js/runtime-core/
|
|
28
|
-
context: import("@modern-js/runtime-core").RuntimeContext;
|
|
21
|
+
readonly props: import("@modern-js/runtime-core/src/plugin").AppProps;
|
|
22
|
+
readonly context: import("@modern-js/runtime-core").RuntimeContext;
|
|
29
23
|
}, JSX.Element>;
|
|
30
24
|
client: import("@modern-js/runtime-core").AsyncPipeline<{
|
|
31
25
|
App: import("react").ComponentType<any>;
|
|
32
|
-
context?: import("@modern-js/runtime-core").RuntimeContext | undefined;
|
|
26
|
+
readonly context?: import("@modern-js/runtime-core").RuntimeContext | undefined;
|
|
33
27
|
rootElement: HTMLElement;
|
|
34
28
|
}, void>;
|
|
35
29
|
server: import("@modern-js/runtime-core").AsyncPipeline<{
|
|
36
30
|
App: import("react").ComponentType<any>;
|
|
37
|
-
context?: import("@modern-js/runtime-core").RuntimeContext | undefined;
|
|
31
|
+
readonly context?: import("@modern-js/runtime-core").RuntimeContext | undefined;
|
|
38
32
|
}, string>;
|
|
39
|
-
init: import("@modern-js/runtime-core").
|
|
33
|
+
init: import("@modern-js/runtime-core").AsyncPipeline<{
|
|
40
34
|
context: import("@modern-js/runtime-core").RuntimeContext;
|
|
41
35
|
}, unknown>;
|
|
42
36
|
pickContext: import("@modern-js/runtime-core").Pipeline<{
|
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
15
|
-
"jsnext:source": "./src/index.
|
|
14
|
+
"version": "1.2.0",
|
|
15
|
+
"jsnext:source": "./src/runtime/index.tsx",
|
|
16
16
|
"types": "./dist/types/runtime/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/runtime/index.js",
|
|
18
18
|
"module": "./dist/js/treeshaking/runtime/index.js",
|
|
@@ -20,13 +20,18 @@
|
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
22
22
|
"node": {
|
|
23
|
+
"jsnext:source": "./src/runtime/index.tsx",
|
|
23
24
|
"import": "./dist/js/modern/runtime/index.js",
|
|
24
25
|
"require": "./dist/js/node/runtime/index.js"
|
|
25
26
|
},
|
|
26
27
|
"default": "./dist/js/treeshaking/runtime/index.js"
|
|
27
28
|
},
|
|
28
|
-
"./cli":
|
|
29
|
+
"./cli": {
|
|
30
|
+
"jsnext:source": "./src/cli/index.ts",
|
|
31
|
+
"default": "./dist/js/node/cli/index.js"
|
|
32
|
+
},
|
|
29
33
|
"./plugins": {
|
|
34
|
+
"jsnext:source": "./src/plugins.ts",
|
|
30
35
|
"node": {
|
|
31
36
|
"import": "./dist/js/node/plugins.js",
|
|
32
37
|
"require": "./dist/js/node/plugins.js"
|
|
@@ -53,37 +58,41 @@
|
|
|
53
58
|
"@modern-js-reduck/react": "^1.0.0",
|
|
54
59
|
"@modern-js-reduck/store": "^1.0.0",
|
|
55
60
|
"@types/redux-logger": "^3.0.9",
|
|
56
|
-
"redux-logger": "^3.0.6"
|
|
61
|
+
"redux-logger": "^3.0.6",
|
|
62
|
+
"hoist-non-react-statics": "^3.3.2"
|
|
57
63
|
},
|
|
58
64
|
"devDependencies": {
|
|
59
|
-
"@modern-js/core": "^1.
|
|
60
|
-
"@modern-js/plugin": "^1.
|
|
61
|
-
"@modern-js/runtime-core": "^1.
|
|
62
|
-
"@modern-js/utils": "^1.
|
|
65
|
+
"@modern-js/core": "^1.3.0",
|
|
66
|
+
"@modern-js/plugin": "^1.2.0",
|
|
67
|
+
"@modern-js/runtime-core": "^1.2.0",
|
|
68
|
+
"@modern-js/utils": "^1.2.0",
|
|
69
|
+
"@types/hoist-non-react-statics": "^3.3.1",
|
|
63
70
|
"@types/jest": "^26",
|
|
64
71
|
"@types/node": "^14",
|
|
65
72
|
"@types/react": "^17",
|
|
66
73
|
"@types/react-dom": "^17",
|
|
67
74
|
"react": "^17.0.2",
|
|
68
75
|
"typescript": "^4",
|
|
69
|
-
"@
|
|
70
|
-
"
|
|
76
|
+
"@scripts/build": "0.0.0",
|
|
77
|
+
"jest": "^27",
|
|
78
|
+
"@scripts/jest-config": "0.0.0"
|
|
71
79
|
},
|
|
72
80
|
"sideEffects": false,
|
|
73
81
|
"peerDependencies": {
|
|
74
|
-
"@modern-js/core": "^1.
|
|
75
|
-
"@modern-js/runtime-core": "^1.
|
|
82
|
+
"@modern-js/core": "^1.3.0",
|
|
83
|
+
"@modern-js/runtime-core": "^1.2.0",
|
|
76
84
|
"react": "^17.0.2"
|
|
77
85
|
},
|
|
78
86
|
"modernConfig": {},
|
|
79
87
|
"publishConfig": {
|
|
80
88
|
"registry": "https://registry.npmjs.org/",
|
|
81
|
-
"access": "public"
|
|
89
|
+
"access": "public",
|
|
90
|
+
"types": "./dist/types/runtime/index.d.ts"
|
|
82
91
|
},
|
|
83
92
|
"scripts": {
|
|
84
93
|
"new": "modern new",
|
|
85
94
|
"build": "modern build",
|
|
86
|
-
"test": "
|
|
95
|
+
"test": "jest --passWithNoTests"
|
|
87
96
|
},
|
|
88
97
|
"readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
|
|
89
98
|
}
|
package/src/runtime/index.tsx
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
// eslint-disable-next-line filenames/match-exported
|
|
2
|
-
import statePlugin from './plugin';
|
|
3
|
-
|
|
4
1
|
export * from '@modern-js-reduck/react';
|
|
5
2
|
export { model, createStore } from '@modern-js-reduck/store';
|
|
6
|
-
|
|
3
|
+
export { default } from './plugin';
|
|
7
4
|
export * from './plugin';
|
|
8
|
-
|
|
9
|
-
export default statePlugin;
|
package/src/runtime/plugin.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import { useContext } from 'react';
|
|
|
3
3
|
import { createPlugin, RuntimeReactContext } from '@modern-js/runtime-core';
|
|
4
4
|
import { createStore, Store } from '@modern-js-reduck/store';
|
|
5
5
|
import { Provider } from '@modern-js-reduck/react';
|
|
6
|
+
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
6
7
|
|
|
7
8
|
declare module '@modern-js/runtime-core' {
|
|
8
9
|
interface RuntimeContext {
|
|
@@ -12,15 +13,9 @@ declare module '@modern-js/runtime-core' {
|
|
|
12
13
|
interface TRuntimeContext {
|
|
13
14
|
store: Store;
|
|
14
15
|
}
|
|
15
|
-
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
_SSR_DATA?: {
|
|
20
|
-
data: {
|
|
21
|
-
storeState: any;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
17
|
+
interface SSRData {
|
|
18
|
+
storeState: any;
|
|
24
19
|
}
|
|
25
20
|
}
|
|
26
21
|
|
|
@@ -30,16 +25,18 @@ const state = (config: PluginProps) =>
|
|
|
30
25
|
createPlugin(
|
|
31
26
|
() => ({
|
|
32
27
|
hoc({ App }, next) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
const getStateApp = (props: any) => {
|
|
29
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
30
|
+
const context = useContext(RuntimeReactContext);
|
|
36
31
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
return (
|
|
33
|
+
<Provider store={context.store} config={config}>
|
|
34
|
+
<App {...props} />
|
|
35
|
+
</Provider>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
return next({
|
|
39
|
+
App: hoistNonReactStatics(getStateApp, App),
|
|
43
40
|
});
|
|
44
41
|
},
|
|
45
42
|
init({ context }, next) {
|