@modern-js/plugin-state 1.1.3 → 1.2.1
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 +36 -0
- 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 +6 -6
- package/jest.config.js +8 -0
- package/package.json +23 -14
- package/tests/index.test.ts +9 -0
- package/tsconfig.json +1 -4
- package/src/.eslintrc.json +0 -3
- package/src/cli/index.ts +0 -144
- package/src/plugins.ts +0 -9
- package/src/runtime/index.tsx +0 -9
- package/src/runtime/plugin.tsx +0 -70
- package/src/types.ts +0 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# @modern-js/plugin-state
|
|
2
2
|
|
|
3
|
+
## 1.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 83166714: change .npmignore
|
|
8
|
+
- Updated dependencies [83166714]
|
|
9
|
+
- Updated dependencies [c3de9882]
|
|
10
|
+
- Updated dependencies [33ff48af]
|
|
11
|
+
- Updated dependencies [c74597bd]
|
|
12
|
+
- @modern-js/core@1.3.2
|
|
13
|
+
- @modern-js/runtime-core@1.2.1
|
|
14
|
+
|
|
15
|
+
## 1.2.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- cfe11628: Make Modern.js self bootstraping
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [fc71e36f]
|
|
24
|
+
- Updated dependencies [a2cb9abc]
|
|
25
|
+
- Updated dependencies [cfe11628]
|
|
26
|
+
- @modern-js/core@1.3.0
|
|
27
|
+
- @modern-js/runtime-core@1.2.0
|
|
28
|
+
|
|
29
|
+
## 1.1.4
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- 4a281912: fix: app init function not work
|
|
34
|
+
- Updated dependencies [4a281912]
|
|
35
|
+
- Updated dependencies [4a281912]
|
|
36
|
+
- Updated dependencies [eb026119]
|
|
37
|
+
- @modern-js/runtime-core@1.1.3
|
|
38
|
+
|
|
3
39
|
## 1.1.3
|
|
4
40
|
|
|
5
41
|
### Patch Changes
|
|
@@ -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) {
|
|
@@ -12,25 +12,25 @@ declare module '@modern-js/runtime-core' {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
declare type PluginProps = Parameters<typeof createStore>[0];
|
|
15
|
-
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<{
|
|
16
16
|
hoc: import("@modern-js/runtime-core").Pipeline<{
|
|
17
17
|
App: import("react").ComponentType<any>;
|
|
18
18
|
}, import("react").ComponentType<any>>;
|
|
19
19
|
provide: import("@modern-js/runtime-core").Pipeline<{
|
|
20
20
|
element: JSX.Element;
|
|
21
|
-
props: import("@modern-js/runtime-core/
|
|
22
|
-
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;
|
|
23
23
|
}, JSX.Element>;
|
|
24
24
|
client: import("@modern-js/runtime-core").AsyncPipeline<{
|
|
25
25
|
App: import("react").ComponentType<any>;
|
|
26
|
-
context?: import("@modern-js/runtime-core").RuntimeContext | undefined;
|
|
26
|
+
readonly context?: import("@modern-js/runtime-core").RuntimeContext | undefined;
|
|
27
27
|
rootElement: HTMLElement;
|
|
28
28
|
}, void>;
|
|
29
29
|
server: import("@modern-js/runtime-core").AsyncPipeline<{
|
|
30
30
|
App: import("react").ComponentType<any>;
|
|
31
|
-
context?: import("@modern-js/runtime-core").RuntimeContext | undefined;
|
|
31
|
+
readonly context?: import("@modern-js/runtime-core").RuntimeContext | undefined;
|
|
32
32
|
}, string>;
|
|
33
|
-
init: import("@modern-js/runtime-core").
|
|
33
|
+
init: import("@modern-js/runtime-core").AsyncPipeline<{
|
|
34
34
|
context: import("@modern-js/runtime-core").RuntimeContext;
|
|
35
35
|
}, unknown>;
|
|
36
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.1
|
|
15
|
-
"jsnext:source": "./src/index.
|
|
14
|
+
"version": "1.2.1",
|
|
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.2
|
|
60
|
-
"@modern-js/plugin": "^1.1
|
|
61
|
-
"@modern-js/runtime-core": "^1.1
|
|
62
|
-
"@modern-js/utils": "^1.
|
|
65
|
+
"@modern-js/core": "^1.3.2",
|
|
66
|
+
"@modern-js/plugin": "^1.2.1",
|
|
67
|
+
"@modern-js/runtime-core": "^1.2.1",
|
|
68
|
+
"@modern-js/utils": "^1.2.2",
|
|
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.2
|
|
75
|
-
"@modern-js/runtime-core": "^1.1
|
|
82
|
+
"@modern-js/core": "^1.3.2",
|
|
83
|
+
"@modern-js/runtime-core": "^1.2.1",
|
|
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/tsconfig.json
CHANGED
package/src/.eslintrc.json
DELETED
package/src/cli/index.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import {
|
|
3
|
-
getEntryOptions,
|
|
4
|
-
createRuntimeExportsUtils,
|
|
5
|
-
PLUGIN_SCHEMAS,
|
|
6
|
-
} from '@modern-js/utils';
|
|
7
|
-
import {
|
|
8
|
-
createPlugin,
|
|
9
|
-
useAppContext,
|
|
10
|
-
useResolvedConfigContext,
|
|
11
|
-
} from '@modern-js/core';
|
|
12
|
-
import {} from '../types';
|
|
13
|
-
|
|
14
|
-
const PLUGIN_IDENTIFIER = 'state';
|
|
15
|
-
|
|
16
|
-
const index = createPlugin(
|
|
17
|
-
(() => {
|
|
18
|
-
const stateConfigMap = new Map<string, any>();
|
|
19
|
-
|
|
20
|
-
let pluginsExportsUtils: any;
|
|
21
|
-
const stateModulePath = path.resolve(__dirname, '../../../../');
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
config() {
|
|
25
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
26
|
-
const appContext = useAppContext();
|
|
27
|
-
|
|
28
|
-
pluginsExportsUtils = createRuntimeExportsUtils(
|
|
29
|
-
appContext.internalDirectory,
|
|
30
|
-
'plugins',
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
source: {
|
|
35
|
-
alias: {
|
|
36
|
-
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath(),
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
modifyEntryImports({ entrypoint, imports }: any) {
|
|
42
|
-
const { entryName } = entrypoint;
|
|
43
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
44
|
-
const userConfig = useResolvedConfigContext();
|
|
45
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
46
|
-
const { packageName } = useAppContext();
|
|
47
|
-
|
|
48
|
-
const stateConfig = getEntryOptions(
|
|
49
|
-
entryName,
|
|
50
|
-
userConfig.runtime,
|
|
51
|
-
userConfig.runtimeByEntries,
|
|
52
|
-
packageName,
|
|
53
|
-
)?.state;
|
|
54
|
-
|
|
55
|
-
stateConfigMap.set(entryName, stateConfig);
|
|
56
|
-
|
|
57
|
-
const getEnabledPlugins = () => {
|
|
58
|
-
const internalPlugins = [
|
|
59
|
-
'immer',
|
|
60
|
-
'effects',
|
|
61
|
-
'autoActions',
|
|
62
|
-
'devtools',
|
|
63
|
-
];
|
|
64
|
-
|
|
65
|
-
return internalPlugins.filter(name => stateConfig[name] !== false);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
if (stateConfig) {
|
|
69
|
-
imports.push({
|
|
70
|
-
value: '@modern-js/runtime/plugins',
|
|
71
|
-
specifiers: [
|
|
72
|
-
{
|
|
73
|
-
imported: PLUGIN_IDENTIFIER,
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
});
|
|
77
|
-
imports.push({
|
|
78
|
-
value: '@modern-js/runtime/model',
|
|
79
|
-
specifiers: getEnabledPlugins().map(imported => ({ imported })),
|
|
80
|
-
initialize: `
|
|
81
|
-
const createStatePlugins = (config) => {
|
|
82
|
-
const plugins = [];
|
|
83
|
-
|
|
84
|
-
${getEnabledPlugins()
|
|
85
|
-
.map(
|
|
86
|
-
name => `
|
|
87
|
-
plugins.push(${name}(config['${name}']));
|
|
88
|
-
`,
|
|
89
|
-
)
|
|
90
|
-
.join('\n')}
|
|
91
|
-
|
|
92
|
-
return plugins;
|
|
93
|
-
}
|
|
94
|
-
`,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
entrypoint,
|
|
100
|
-
imports,
|
|
101
|
-
};
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
modifyEntryRuntimePlugins({ entrypoint, plugins }: any) {
|
|
105
|
-
const stateOptions = stateConfigMap.get(entrypoint.entryName);
|
|
106
|
-
|
|
107
|
-
if (stateOptions) {
|
|
108
|
-
const isBoolean = typeof stateOptions === 'boolean';
|
|
109
|
-
|
|
110
|
-
let options = isBoolean ? '{}' : JSON.stringify(stateOptions);
|
|
111
|
-
|
|
112
|
-
options = `${options.substr(0, options.length - 1)}${
|
|
113
|
-
isBoolean ? '' : ','
|
|
114
|
-
}plugins: createStatePlugins(${JSON.stringify(
|
|
115
|
-
stateConfigMap.get(entrypoint.entryName),
|
|
116
|
-
)})}`;
|
|
117
|
-
|
|
118
|
-
plugins.push({
|
|
119
|
-
name: PLUGIN_IDENTIFIER,
|
|
120
|
-
options,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
return {
|
|
124
|
-
entrypoint,
|
|
125
|
-
plugins,
|
|
126
|
-
};
|
|
127
|
-
},
|
|
128
|
-
validateSchema() {
|
|
129
|
-
return PLUGIN_SCHEMAS['@modern-js/plugin-state'];
|
|
130
|
-
},
|
|
131
|
-
addRuntimeExports() {
|
|
132
|
-
pluginsExportsUtils.addExport(
|
|
133
|
-
`export { default as state } from '${stateModulePath}'`,
|
|
134
|
-
);
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
}) as any,
|
|
138
|
-
{
|
|
139
|
-
name: '@modern-js/plugin-state',
|
|
140
|
-
required: ['@modern-js/runtime'],
|
|
141
|
-
},
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
export default index;
|
package/src/plugins.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { plugin as effectsPlugin } from '@modern-js-reduck/plugin-effects';
|
|
2
|
-
import autoActionsPlugin from '@modern-js-reduck/plugin-auto-actions';
|
|
3
|
-
import immerPlugin from '@modern-js-reduck/plugin-immutable';
|
|
4
|
-
|
|
5
|
-
export { default as devtools } from '@modern-js-reduck/plugin-devtools';
|
|
6
|
-
|
|
7
|
-
export const effects = () => effectsPlugin;
|
|
8
|
-
export const immer = () => immerPlugin;
|
|
9
|
-
export const autoActions = () => autoActionsPlugin;
|
package/src/runtime/index.tsx
DELETED
package/src/runtime/plugin.tsx
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line filenames/match-exported
|
|
2
|
-
import { useContext } from 'react';
|
|
3
|
-
import { createPlugin, RuntimeReactContext } from '@modern-js/runtime-core';
|
|
4
|
-
import { createStore, Store } from '@modern-js-reduck/store';
|
|
5
|
-
import { Provider } from '@modern-js-reduck/react';
|
|
6
|
-
|
|
7
|
-
declare module '@modern-js/runtime-core' {
|
|
8
|
-
interface RuntimeContext {
|
|
9
|
-
store: Store;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface TRuntimeContext {
|
|
13
|
-
store: Store;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface SSRData {
|
|
17
|
-
storeState: any;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type PluginProps = Parameters<typeof createStore>[0];
|
|
22
|
-
|
|
23
|
-
const state = (config: PluginProps) =>
|
|
24
|
-
createPlugin(
|
|
25
|
-
() => ({
|
|
26
|
-
hoc({ App }, next) {
|
|
27
|
-
return next({
|
|
28
|
-
App: (props: any) => {
|
|
29
|
-
const context = useContext(RuntimeReactContext);
|
|
30
|
-
|
|
31
|
-
return (
|
|
32
|
-
<Provider store={context.store} config={config}>
|
|
33
|
-
<App {...props} />
|
|
34
|
-
</Provider>
|
|
35
|
-
);
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
},
|
|
39
|
-
init({ context }, next) {
|
|
40
|
-
const storeConfig = config || {};
|
|
41
|
-
|
|
42
|
-
if (typeof window !== 'undefined') {
|
|
43
|
-
storeConfig.initialState =
|
|
44
|
-
storeConfig.initialState ||
|
|
45
|
-
window?._SSR_DATA?.data?.storeState ||
|
|
46
|
-
{};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
context.store = createStore(storeConfig);
|
|
50
|
-
|
|
51
|
-
next({ context });
|
|
52
|
-
},
|
|
53
|
-
pickContext({ context, pickedContext }, next) {
|
|
54
|
-
return next({
|
|
55
|
-
context,
|
|
56
|
-
pickedContext: {
|
|
57
|
-
...pickedContext,
|
|
58
|
-
store: context.store,
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
}),
|
|
63
|
-
{
|
|
64
|
-
name: '@modern-js/plugin-state',
|
|
65
|
-
},
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
export default state;
|
|
69
|
-
|
|
70
|
-
export * from '../plugins';
|
package/src/types.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { createStore } from '@modern-js-reduck/store';
|
|
2
|
-
import { ReduxLoggerOptions } from 'redux-logger';
|
|
3
|
-
|
|
4
|
-
export type PluginOptions = Parameters<typeof createStore>[0] & {
|
|
5
|
-
/**
|
|
6
|
-
* If it's false, the logger will be disabled.
|
|
7
|
-
* If it's a object, it means options will pass to createLogger function
|
|
8
|
-
*/
|
|
9
|
-
logger?: false | ReduxLoggerOptions;
|
|
10
|
-
// todo: achive effects params
|
|
11
|
-
effects?: any;
|
|
12
|
-
/**
|
|
13
|
-
* Default: false
|
|
14
|
-
* When it's true, will remove immer plugin
|
|
15
|
-
*/
|
|
16
|
-
disableImmer?: boolean;
|
|
17
|
-
// todo: achive devtools params
|
|
18
|
-
devtools?: any;
|
|
19
|
-
};
|