@modern-js/plugin-state 1.1.2 → 1.1.4
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 +24 -0
- package/dist/js/modern/runtime/plugin.js +14 -10
- package/dist/js/modern/types.js +0 -1
- package/dist/js/node/runtime/plugin.js +17 -10
- package/dist/js/treeshaking/runtime/plugin.js +16 -11
- package/dist/js/treeshaking/types.js +0 -1
- package/dist/types/cli/index.d.ts +3 -0
- package/dist/types/runtime/plugin.d.ts +3 -9
- package/package.json +13 -10
- package/src/runtime/plugin.tsx +14 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @modern-js/plugin-state
|
|
2
2
|
|
|
3
|
+
## 1.1.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4a281912: fix: app init function not work
|
|
8
|
+
- Updated dependencies [4a281912]
|
|
9
|
+
- Updated dependencies [4a281912]
|
|
10
|
+
- Updated dependencies [eb026119]
|
|
11
|
+
- @modern-js/runtime-core@1.1.3
|
|
12
|
+
|
|
13
|
+
## 1.1.3
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 4406c2db: fix: avoid fetching data again when ssr succeeds
|
|
18
|
+
- Updated dependencies [90eeb72c]
|
|
19
|
+
- Updated dependencies [e04914ce]
|
|
20
|
+
- Updated dependencies [4406c2db]
|
|
21
|
+
- Updated dependencies [5a4c557e]
|
|
22
|
+
- Updated dependencies [e04914ce]
|
|
23
|
+
- Updated dependencies [ecb344dc]
|
|
24
|
+
- @modern-js/core@1.2.0
|
|
25
|
+
- @modern-js/runtime-core@1.1.2
|
|
26
|
+
|
|
3
27
|
## 1.1.2
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
1
|
+
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; }
|
|
2
2
|
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
3
|
+
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; }
|
|
4
4
|
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
|
|
@@ -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
|
|
package/dist/js/modern/types.js
CHANGED
|
@@ -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,9 +32,11 @@ Object.keys(_plugins).forEach(function (key) {
|
|
|
30
32
|
});
|
|
31
33
|
});
|
|
32
34
|
|
|
33
|
-
function
|
|
35
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
36
|
+
|
|
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
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
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; }
|
|
36
40
|
|
|
37
41
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
38
42
|
|
|
@@ -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,6 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
1
|
+
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; }
|
|
2
2
|
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
3
|
+
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; }
|
|
4
4
|
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
|
|
@@ -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) {
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
declare const index: import("@modern-js/core").AsyncPlugin<Partial<import("@modern-js/core").Progresses2Threads<{
|
|
2
2
|
config: import("@modern-js/core").ParallelWorkflow<void, unknown>;
|
|
3
|
+
resolvedConfig: import("@modern-js/core").AsyncWaterfall<{
|
|
4
|
+
resolved: import("@modern-js/core").NormalizedConfig;
|
|
5
|
+
}>;
|
|
3
6
|
validateSchema: import("@modern-js/core").ParallelWorkflow<void, unknown>;
|
|
4
7
|
prepare: import("@modern-js/core").AsyncWorkflow<void, void>;
|
|
5
8
|
commands: import("@modern-js/core").AsyncWorkflow<{
|
|
@@ -7,14 +7,8 @@ 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];
|
|
@@ -36,7 +30,7 @@ declare const state: (config: PluginProps) => import("@modern-js/plugin").Plugin
|
|
|
36
30
|
App: import("react").ComponentType<any>;
|
|
37
31
|
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/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.1.
|
|
14
|
+
"version": "1.1.4",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/runtime/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/runtime/index.js",
|
|
@@ -53,26 +53,28 @@
|
|
|
53
53
|
"@modern-js-reduck/react": "^1.0.0",
|
|
54
54
|
"@modern-js-reduck/store": "^1.0.0",
|
|
55
55
|
"@types/redux-logger": "^3.0.9",
|
|
56
|
-
"redux-logger": "^3.0.6"
|
|
56
|
+
"redux-logger": "^3.0.6",
|
|
57
|
+
"hoist-non-react-statics": "^3.3.2"
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
59
|
-
"@modern-js/core": "^1.
|
|
60
|
+
"@modern-js/core": "^1.2.0",
|
|
60
61
|
"@modern-js/plugin": "^1.1.2",
|
|
61
|
-
"@modern-js/runtime-core": "^1.1.
|
|
62
|
-
"@modern-js/utils": "^1.1.
|
|
62
|
+
"@modern-js/runtime-core": "^1.1.3",
|
|
63
|
+
"@modern-js/utils": "^1.1.6",
|
|
64
|
+
"@types/hoist-non-react-statics": "^3.3.1",
|
|
63
65
|
"@types/jest": "^26",
|
|
64
66
|
"@types/node": "^14",
|
|
65
67
|
"@types/react": "^17",
|
|
66
68
|
"@types/react-dom": "^17",
|
|
67
69
|
"react": "^17.0.2",
|
|
68
70
|
"typescript": "^4",
|
|
69
|
-
"@modern-js/plugin-testing": "^1.
|
|
70
|
-
"@modern-js/module-tools": "^1.1.
|
|
71
|
+
"@modern-js/plugin-testing": "^1.2.2",
|
|
72
|
+
"@modern-js/module-tools": "^1.1.4"
|
|
71
73
|
},
|
|
72
74
|
"sideEffects": false,
|
|
73
75
|
"peerDependencies": {
|
|
74
|
-
"@modern-js/core": "^1.
|
|
75
|
-
"@modern-js/runtime-core": "^1.1.
|
|
76
|
+
"@modern-js/core": "^1.2.0",
|
|
77
|
+
"@modern-js/runtime-core": "^1.1.3",
|
|
76
78
|
"react": "^17.0.2"
|
|
77
79
|
},
|
|
78
80
|
"modernConfig": {},
|
|
@@ -84,5 +86,6 @@
|
|
|
84
86
|
"new": "modern new",
|
|
85
87
|
"build": "modern build",
|
|
86
88
|
"test": "modern test --passWithNoTests"
|
|
87
|
-
}
|
|
89
|
+
},
|
|
90
|
+
"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"
|
|
88
91
|
}
|
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) {
|