piral-core 0.15.0-alpha.4332 → 0.15.0-alpha.4396
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/esm/actions/state.js +6 -7
- package/esm/actions/state.js.map +1 -1
- package/esm/debugger.js +1 -2
- package/esm/debugger.js.map +1 -1
- package/esm/hooks/globalState.js +2 -9
- package/esm/hooks/globalState.js.map +1 -1
- package/esm/state/createActions.d.ts +2 -2
- package/esm/state/createActions.js.map +1 -1
- package/esm/state/createGlobalState.d.ts +1 -2
- package/esm/state/createGlobalState.js +2 -2
- package/esm/state/createGlobalState.js.map +1 -1
- package/esm/types/state.d.ts +2 -3
- package/lib/actions/state.js +6 -7
- package/lib/actions/state.js.map +1 -1
- package/lib/debugger.js +1 -2
- package/lib/debugger.js.map +1 -1
- package/lib/hooks/globalState.js +2 -9
- package/lib/hooks/globalState.js.map +1 -1
- package/lib/state/createActions.d.ts +2 -2
- package/lib/state/createActions.js.map +1 -1
- package/lib/state/createGlobalState.d.ts +1 -2
- package/lib/state/createGlobalState.js +2 -2
- package/lib/state/createGlobalState.js.map +1 -1
- package/lib/types/state.d.ts +2 -3
- package/package.json +7 -13
- package/src/RootListener.test.tsx +5 -7
- package/src/actions/app.test.ts +32 -32
- package/src/actions/components.test.ts +10 -10
- package/src/actions/data.test.ts +49 -49
- package/src/actions/define.test.ts +2 -2
- package/src/actions/portal.test.ts +17 -17
- package/src/actions/state.test.ts +3 -3
- package/src/actions/state.ts +7 -8
- package/src/components/ForeignComponentContainer.test.tsx +14 -13
- package/src/components/Mediator.test.tsx +11 -10
- package/src/debugger.ts +1 -2
- package/src/helpers.test.tsx +9 -8
- package/src/hooks/globalState.ts +2 -11
- package/src/hooks/setter.test.ts +3 -4
- package/src/modules/element-server.test.ts +4 -4
- package/src/modules/element.test.ts +6 -6
- package/src/setters/SetComponent.test.tsx +7 -6
- package/src/setters/SetError.test.tsx +7 -6
- package/src/setters/SetErrors.test.tsx +7 -6
- package/src/setters/SetLayout.test.tsx +7 -6
- package/src/setters/SetProvider.test.tsx +7 -6
- package/src/setters/SetRedirect.test.tsx +7 -6
- package/src/setters/SetRoute.test.tsx +7 -6
- package/src/state/createActions.ts +3 -3
- package/src/state/createGlobalState.test.ts +9 -11
- package/src/state/createGlobalState.ts +2 -2
- package/src/state/withApi.test.tsx +5 -5
- package/src/types/state.ts +2 -3
- package/src/hooks/globalState-server.test.ts +0 -41
- package/src/hooks/globalState.test.ts +0 -47
package/esm/actions/state.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { swap, deref } from '@dbeining/react-atom';
|
|
2
1
|
import { isSame } from '../utils';
|
|
3
|
-
function onlyChangedState(oldState, newState) {
|
|
4
|
-
return isSame(oldState, newState) ? oldState : newState;
|
|
5
|
-
}
|
|
6
2
|
export function dispatch(ctx, update) {
|
|
7
|
-
|
|
3
|
+
const oldState = ctx.state.getState();
|
|
4
|
+
const newState = update(oldState);
|
|
5
|
+
if (!isSame(oldState, newState)) {
|
|
6
|
+
ctx.state.setState(newState);
|
|
7
|
+
}
|
|
8
8
|
}
|
|
9
9
|
export function readState(ctx, read) {
|
|
10
|
-
|
|
11
|
-
return read(state);
|
|
10
|
+
return read(ctx.state.getState());
|
|
12
11
|
}
|
|
13
12
|
//# sourceMappingURL=state.js.map
|
package/esm/actions/state.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/actions/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/actions/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,MAAM,UAAU,QAAQ,CAAC,GAAuB,EAAE,MAA2C;IAC3F,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IACtC,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAElC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE;QAC/B,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;KAC9B;AACH,CAAC;AAED,MAAM,UAAU,SAAS,CAAI,GAAuB,EAAE,IAA+B;IACnF,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;AACpC,CAAC"}
|
package/esm/debugger.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { addChangeHandler } from '@dbeining/react-atom';
|
|
2
1
|
import { installPiralDebug } from 'piral-debug-utils';
|
|
3
2
|
export function integrateDebugger(context, options, debug = {}) {
|
|
4
3
|
installPiralDebug(Object.assign(Object.assign({}, debug), { addPilet: context.addPilet, removePilet: context.removePilet, updatePilet(pilet) {
|
|
@@ -38,7 +37,7 @@ export function integrateDebugger(context, options, debug = {}) {
|
|
|
38
37
|
},
|
|
39
38
|
integrate(dbg) {
|
|
40
39
|
context.dispatch((s) => (Object.assign(Object.assign({}, s), { components: Object.assign(Object.assign({}, s.components), dbg.components), routes: Object.assign(Object.assign({}, s.routes), dbg.routes), registry: Object.assign(Object.assign({}, s.registry), { wrappers: Object.assign(Object.assign({}, s.registry.wrappers), dbg.wrappers) }) })));
|
|
41
|
-
|
|
40
|
+
context.state.subscribe((current, previous) => {
|
|
42
41
|
const pilets = current.modules !== previous.modules;
|
|
43
42
|
const pages = current.registry.pages !== previous.registry.pages || current.routes !== previous.routes;
|
|
44
43
|
const extensions = current.registry.extensions !== previous.registry.extensions;
|
package/esm/debugger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debugger.js","sourceRoot":"","sources":["../src/debugger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"debugger.js","sourceRoot":"","sources":["../src/debugger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE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AAK,QAAQ,CAAC;gBACnC,GAAG,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE;oBAC9B,MAAM;oBACN,KAAK;oBACL,UAAU;oBACV,KAAK;iBACN,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,IACD,CAAC;AACL,CAAC"}
|
package/esm/hooks/globalState.js
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
|
-
import { useAtom, deref } from '@dbeining/react-atom';
|
|
3
2
|
import { StateContext } from '../state/stateContext';
|
|
4
|
-
const useGlobalAtom = typeof window !== 'undefined' ? useAtom : useDirectAtom;
|
|
5
|
-
function useDirectAtom(atom, opts) {
|
|
6
|
-
const state = deref(atom);
|
|
7
|
-
const select = opts && opts.select;
|
|
8
|
-
return typeof select === 'function' ? select(state) : state;
|
|
9
|
-
}
|
|
10
3
|
/**
|
|
11
4
|
* Hook to obtain the global state context, which gives you directly
|
|
12
5
|
* all actions, state, and more of the Piral instance.
|
|
@@ -17,7 +10,7 @@ export function useGlobalStateContext() {
|
|
|
17
10
|
return useContext(StateContext);
|
|
18
11
|
}
|
|
19
12
|
export function useGlobalState(select) {
|
|
20
|
-
const { state } = useGlobalStateContext();
|
|
21
|
-
return
|
|
13
|
+
const { state: useState } = useGlobalStateContext();
|
|
14
|
+
return useState(select);
|
|
22
15
|
}
|
|
23
16
|
//# sourceMappingURL=globalState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globalState.js","sourceRoot":"","sources":["../../src/hooks/globalState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"globalState.js","sourceRoot":"","sources":["../../src/hooks/globalState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAGrD;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO,UAAU,CAAC,YAAY,CAAC,CAAC;AAClC,CAAC;AAeD,MAAM,UAAU,cAAc,CAAI,MAAkC;IAClE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,qBAAqB,EAAE,CAAC;IACpD,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UseBoundStore } from 'zustand';
|
|
2
2
|
import { EventEmitter, GlobalState, GlobalStateContext, PiralDefineActions } from '../types';
|
|
3
3
|
export declare function includeActions(ctx: GlobalStateContext, actions: PiralDefineActions): void;
|
|
4
|
-
export declare function createActions(state:
|
|
4
|
+
export declare function createActions(state: UseBoundStore<GlobalState>, events: EventEmitter): GlobalStateContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createActions.js","sourceRoot":"","sources":["../../src/state/createActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,YAAY,CAAC;AAItC,SAAS,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"createActions.js","sourceRoot":"","sources":["../../src/state/createActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,YAAY,CAAC;AAItC,SAAS,aAAa,CAAC,KAAiC,EAAE,MAAoB;IAC5E,MAAM,GAAG,GAAG,gCACP,MAAM,KACT,IAAI,EAAE,EAAE,EACR,UAAU,EAAE;YACV,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,SAAS;SACnC,EACD,KAAK,GACgB,CAAC;IACxB,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAuB,EAAE,OAA2B;IACjF,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAEzC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;QACpC,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;QACnC,GAAG,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;KACzC;AACH,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAiC,EAAE,MAAoB;IACnF,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC7C,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACjC,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { Atom } from '@dbeining/react-atom';
|
|
2
1
|
import { GlobalState, NestedPartial } from '../types';
|
|
3
|
-
export declare function createGlobalState(customState?: NestedPartial<GlobalState>):
|
|
2
|
+
export declare function createGlobalState(customState?: NestedPartial<GlobalState>): import("zustand").UseBoundStore<GlobalState, import("zustand").StoreApi<GlobalState>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import create from 'zustand';
|
|
2
2
|
import { createDefaultState } from '../../app.codegen';
|
|
3
3
|
function extend(defaultState, customState) {
|
|
4
4
|
for (const key of Object.keys(customState)) {
|
|
@@ -14,6 +14,6 @@ function extend(defaultState, customState) {
|
|
|
14
14
|
}
|
|
15
15
|
export function createGlobalState(customState = {}) {
|
|
16
16
|
const defaultState = createDefaultState();
|
|
17
|
-
return
|
|
17
|
+
return create(() => extend(defaultState, customState));
|
|
18
18
|
}
|
|
19
19
|
//# sourceMappingURL=createGlobalState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createGlobalState.js","sourceRoot":"","sources":["../../src/state/createGlobalState.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"createGlobalState.js","sourceRoot":"","sources":["../../src/state/createGlobalState.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAGvD,SAAS,MAAM,CAAI,YAAe,EAAE,WAA6B;IAC/D,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE;QAC1C,IAAI,GAAG,KAAK,WAAW,IAAI,GAAG,KAAK,aAAa,EAAE;YAChD,SAAS;SACV;QAED,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QACnC,MAAM,MAAM,GAAG,OAAO,QAAQ,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;QACzE,YAAY,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;KAC9D;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,cAA0C,EAAE;IAC5E,MAAM,YAAY,GAAgB,kBAAkB,EAAE,CAAC;IACvD,OAAO,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC;AACzD,CAAC"}
|
package/esm/types/state.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ComponentType, ReactPortal, PropsWithChildren } from 'react';
|
|
2
2
|
import type { RouteComponentProps } from 'react-router';
|
|
3
|
-
import type { Atom } from '@dbeining/react-atom';
|
|
4
3
|
import type { LoadPiletsOptions } from 'piral-base';
|
|
4
|
+
import type { UseBoundStore } from 'zustand';
|
|
5
5
|
import type { Dict, Without } from './common';
|
|
6
6
|
import type { SharedDataItem, DataStoreTarget } from './data';
|
|
7
7
|
import type { PiralCustomActions, PiralCustomState, PiralCustomRegistryState, PiralCustomComponentsState } from './custom';
|
|
@@ -12,7 +12,6 @@ export interface StateDispatcher<TState> {
|
|
|
12
12
|
}
|
|
13
13
|
declare module './components' {
|
|
14
14
|
interface ComponentContext {
|
|
15
|
-
state: Atom<GlobalState>;
|
|
16
15
|
readState: PiralActions['readState'];
|
|
17
16
|
}
|
|
18
17
|
}
|
|
@@ -329,7 +328,7 @@ export interface GlobalStateContext extends PiralActions, EventEmitter {
|
|
|
329
328
|
* The global state context atom.
|
|
330
329
|
* Changes to the state should always be dispatched via the `dispatch` action.
|
|
331
330
|
*/
|
|
332
|
-
state:
|
|
331
|
+
state: UseBoundStore<GlobalState>;
|
|
333
332
|
/**
|
|
334
333
|
* The API objects created for the loaded pilets.
|
|
335
334
|
*/
|
package/lib/actions/state.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.readState = exports.dispatch = void 0;
|
|
4
|
-
const react_atom_1 = require("@dbeining/react-atom");
|
|
5
4
|
const utils_1 = require("../utils");
|
|
6
|
-
function onlyChangedState(oldState, newState) {
|
|
7
|
-
return (0, utils_1.isSame)(oldState, newState) ? oldState : newState;
|
|
8
|
-
}
|
|
9
5
|
function dispatch(ctx, update) {
|
|
10
|
-
|
|
6
|
+
const oldState = ctx.state.getState();
|
|
7
|
+
const newState = update(oldState);
|
|
8
|
+
if (!(0, utils_1.isSame)(oldState, newState)) {
|
|
9
|
+
ctx.state.setState(newState);
|
|
10
|
+
}
|
|
11
11
|
}
|
|
12
12
|
exports.dispatch = dispatch;
|
|
13
13
|
function readState(ctx, read) {
|
|
14
|
-
|
|
15
|
-
return read(state);
|
|
14
|
+
return read(ctx.state.getState());
|
|
16
15
|
}
|
|
17
16
|
exports.readState = readState;
|
|
18
17
|
//# sourceMappingURL=state.js.map
|
package/lib/actions/state.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/actions/state.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/actions/state.ts"],"names":[],"mappings":";;;AAAA,oCAAkC;AAGlC,SAAgB,QAAQ,CAAC,GAAuB,EAAE,MAA2C;IAC3F,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IACtC,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAElC,IAAI,CAAC,IAAA,cAAM,EAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE;QAC/B,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;KAC9B;AACH,CAAC;AAPD,4BAOC;AAED,SAAgB,SAAS,CAAI,GAAuB,EAAE,IAA+B;IACnF,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;AACpC,CAAC;AAFD,8BAEC"}
|
package/lib/debugger.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.integrateDebugger = void 0;
|
|
4
|
-
const react_atom_1 = require("@dbeining/react-atom");
|
|
5
4
|
const piral_debug_utils_1 = require("piral-debug-utils");
|
|
6
5
|
function integrateDebugger(context, options, debug = {}) {
|
|
7
6
|
(0, piral_debug_utils_1.installPiralDebug)(Object.assign(Object.assign({}, debug), { addPilet: context.addPilet, removePilet: context.removePilet, updatePilet(pilet) {
|
|
@@ -41,7 +40,7 @@ function integrateDebugger(context, options, debug = {}) {
|
|
|
41
40
|
},
|
|
42
41
|
integrate(dbg) {
|
|
43
42
|
context.dispatch((s) => (Object.assign(Object.assign({}, s), { components: Object.assign(Object.assign({}, s.components), dbg.components), routes: Object.assign(Object.assign({}, s.routes), dbg.routes), registry: Object.assign(Object.assign({}, s.registry), { wrappers: Object.assign(Object.assign({}, s.registry.wrappers), dbg.wrappers) }) })));
|
|
44
|
-
|
|
43
|
+
context.state.subscribe((current, previous) => {
|
|
45
44
|
const pilets = current.modules !== previous.modules;
|
|
46
45
|
const pages = current.registry.pages !== previous.registry.pages || current.routes !== previous.routes;
|
|
47
46
|
const extensions = current.registry.extensions !== previous.registry.extensions;
|
package/lib/debugger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debugger.js","sourceRoot":"","sources":["../src/debugger.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"debugger.js","sourceRoot":"","sources":["../src/debugger.ts"],"names":[],"mappings":";;;AACA,yDAAgF;AAGhF,SAAgB,iBAAiB,CAC/B,OAA2B,EAC3B,OAA0B,EAC1B,QAAkC,EAAE;IAEpC,IAAA,qCAAiB,kCACZ,KAAK,KACR,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAC1B,WAAW,EAAE,OAAO,CAAC,WAAW,EAChC,WAAW,CAAC,KAAK;YACf,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;gBACnB,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;gBAC9B,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;gBAEhC,IAAI;oBACF,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;oBAC3B,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;iBACrB;gBAAC,OAAO,KAAK,EAAE;oBACd,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;iBACtB;aACF;iBAAM;gBACL,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;aAC5B;QACH,CAAC,EACD,SAAS,EAAE,OAAO,CAAC,IAAI,EACvB,eAAe;YACb,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC3C,CAAC;QACD,aAAa;YACX,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAA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,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,KAAK,QAAQ,CAAC,OAAO,CAAC;gBACpD,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,KAAK,QAAQ,CAAC,QAAQ,CAAC,KAAK,IAAI,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,CAAC;gBACvG,MAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,UAAU,KAAK,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC;gBAChF,MAAM,KAAK,GAAG,OAAO,KAAK,QAAQ,CAAC;gBACnC,GAAG,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE;oBAC9B,MAAM;oBACN,KAAK;oBACL,UAAU;oBACV,KAAK;iBACN,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,IACD,CAAC;AACL,CAAC;AA/ED,8CA+EC"}
|
package/lib/hooks/globalState.js
CHANGED
|
@@ -2,14 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useGlobalState = exports.useGlobalStateContext = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
-
const react_atom_1 = require("@dbeining/react-atom");
|
|
6
5
|
const stateContext_1 = require("../state/stateContext");
|
|
7
|
-
const useGlobalAtom = typeof window !== 'undefined' ? react_atom_1.useAtom : useDirectAtom;
|
|
8
|
-
function useDirectAtom(atom, opts) {
|
|
9
|
-
const state = (0, react_atom_1.deref)(atom);
|
|
10
|
-
const select = opts && opts.select;
|
|
11
|
-
return typeof select === 'function' ? select(state) : state;
|
|
12
|
-
}
|
|
13
6
|
/**
|
|
14
7
|
* Hook to obtain the global state context, which gives you directly
|
|
15
8
|
* all actions, state, and more of the Piral instance.
|
|
@@ -21,8 +14,8 @@ function useGlobalStateContext() {
|
|
|
21
14
|
}
|
|
22
15
|
exports.useGlobalStateContext = useGlobalStateContext;
|
|
23
16
|
function useGlobalState(select) {
|
|
24
|
-
const { state } = useGlobalStateContext();
|
|
25
|
-
return
|
|
17
|
+
const { state: useState } = useGlobalStateContext();
|
|
18
|
+
return useState(select);
|
|
26
19
|
}
|
|
27
20
|
exports.useGlobalState = useGlobalState;
|
|
28
21
|
//# sourceMappingURL=globalState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globalState.js","sourceRoot":"","sources":["../../src/hooks/globalState.ts"],"names":[],"mappings":";;;AAAA,iCAAmC;AACnC,
|
|
1
|
+
{"version":3,"file":"globalState.js","sourceRoot":"","sources":["../../src/hooks/globalState.ts"],"names":[],"mappings":";;;AAAA,iCAAmC;AACnC,wDAAqD;AAGrD;;;;;GAKG;AACH,SAAgB,qBAAqB;IACnC,OAAO,IAAA,kBAAU,EAAC,2BAAY,CAAC,CAAC;AAClC,CAAC;AAFD,sDAEC;AAeD,SAAgB,cAAc,CAAI,MAAkC;IAClE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,qBAAqB,EAAE,CAAC;IACpD,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC1B,CAAC;AAHD,wCAGC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UseBoundStore } from 'zustand';
|
|
2
2
|
import { EventEmitter, GlobalState, GlobalStateContext, PiralDefineActions } from '../types';
|
|
3
3
|
export declare function includeActions(ctx: GlobalStateContext, actions: PiralDefineActions): void;
|
|
4
|
-
export declare function createActions(state:
|
|
4
|
+
export declare function createActions(state: UseBoundStore<GlobalState>, events: EventEmitter): GlobalStateContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createActions.js","sourceRoot":"","sources":["../../src/state/createActions.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AAItC,SAAS,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"createActions.js","sourceRoot":"","sources":["../../src/state/createActions.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AAItC,SAAS,aAAa,CAAC,KAAiC,EAAE,MAAoB;IAC5E,MAAM,GAAG,GAAG,gCACP,MAAM,KACT,IAAI,EAAE,EAAE,EACR,UAAU,EAAE;YACV,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,SAAS;SACnC,EACD,KAAK,GACgB,CAAC;IACxB,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAgB,cAAc,CAAC,GAAuB,EAAE,OAA2B;IACjF,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAEzC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;QACpC,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;QACnC,GAAG,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;KACzC;AACH,CAAC;AAPD,wCAOC;AAED,SAAgB,aAAa,CAAC,KAAiC,EAAE,MAAoB;IACnF,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC7C,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACjC,OAAO,OAAO,CAAC;AACjB,CAAC;AAJD,sCAIC"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { Atom } from '@dbeining/react-atom';
|
|
2
1
|
import { GlobalState, NestedPartial } from '../types';
|
|
3
|
-
export declare function createGlobalState(customState?: NestedPartial<GlobalState>):
|
|
2
|
+
export declare function createGlobalState(customState?: NestedPartial<GlobalState>): import("zustand").UseBoundStore<GlobalState, import("zustand").StoreApi<GlobalState>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createGlobalState = void 0;
|
|
4
|
-
const
|
|
4
|
+
const zustand_1 = require("zustand");
|
|
5
5
|
const app_codegen_1 = require("../../app.codegen");
|
|
6
6
|
function extend(defaultState, customState) {
|
|
7
7
|
for (const key of Object.keys(customState)) {
|
|
@@ -17,7 +17,7 @@ function extend(defaultState, customState) {
|
|
|
17
17
|
}
|
|
18
18
|
function createGlobalState(customState = {}) {
|
|
19
19
|
const defaultState = (0, app_codegen_1.createDefaultState)();
|
|
20
|
-
return
|
|
20
|
+
return (0, zustand_1.default)(() => extend(defaultState, customState));
|
|
21
21
|
}
|
|
22
22
|
exports.createGlobalState = createGlobalState;
|
|
23
23
|
//# sourceMappingURL=createGlobalState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createGlobalState.js","sourceRoot":"","sources":["../../src/state/createGlobalState.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"createGlobalState.js","sourceRoot":"","sources":["../../src/state/createGlobalState.ts"],"names":[],"mappings":";;;AAAA,qCAA6B;AAC7B,mDAAuD;AAGvD,SAAS,MAAM,CAAI,YAAe,EAAE,WAA6B;IAC/D,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE;QAC1C,IAAI,GAAG,KAAK,WAAW,IAAI,GAAG,KAAK,aAAa,EAAE;YAChD,SAAS;SACV;QAED,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QACnC,MAAM,MAAM,GAAG,OAAO,QAAQ,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;QACzE,YAAY,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;KAC9D;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAgB,iBAAiB,CAAC,cAA0C,EAAE;IAC5E,MAAM,YAAY,GAAgB,IAAA,gCAAkB,GAAE,CAAC;IACvD,OAAO,IAAA,iBAAM,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC;AACzD,CAAC;AAHD,8CAGC"}
|
package/lib/types/state.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ComponentType, ReactPortal, PropsWithChildren } from 'react';
|
|
2
2
|
import type { RouteComponentProps } from 'react-router';
|
|
3
|
-
import type { Atom } from '@dbeining/react-atom';
|
|
4
3
|
import type { LoadPiletsOptions } from 'piral-base';
|
|
4
|
+
import type { UseBoundStore } from 'zustand';
|
|
5
5
|
import type { Dict, Without } from './common';
|
|
6
6
|
import type { SharedDataItem, DataStoreTarget } from './data';
|
|
7
7
|
import type { PiralCustomActions, PiralCustomState, PiralCustomRegistryState, PiralCustomComponentsState } from './custom';
|
|
@@ -12,7 +12,6 @@ export interface StateDispatcher<TState> {
|
|
|
12
12
|
}
|
|
13
13
|
declare module './components' {
|
|
14
14
|
interface ComponentContext {
|
|
15
|
-
state: Atom<GlobalState>;
|
|
16
15
|
readState: PiralActions['readState'];
|
|
17
16
|
}
|
|
18
17
|
}
|
|
@@ -329,7 +328,7 @@ export interface GlobalStateContext extends PiralActions, EventEmitter {
|
|
|
329
328
|
* The global state context atom.
|
|
330
329
|
* Changes to the state should always be dispatched via the `dispatch` action.
|
|
331
330
|
*/
|
|
332
|
-
state:
|
|
331
|
+
state: UseBoundStore<GlobalState>;
|
|
333
332
|
/**
|
|
334
333
|
* The API objects created for the loaded pilets.
|
|
335
334
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-core",
|
|
3
|
-
"version": "0.15.0-alpha.
|
|
3
|
+
"version": "0.15.0-alpha.4396",
|
|
4
4
|
"description": "The core library for creating a Piral instance.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"portal",
|
|
@@ -17,10 +17,7 @@
|
|
|
17
17
|
"react-dom": "react-dom",
|
|
18
18
|
"react-router": "react-router",
|
|
19
19
|
"react-router-dom": "react-router-dom",
|
|
20
|
-
"history": "history"
|
|
21
|
-
"path-to-regexp": "path-to-regexp",
|
|
22
|
-
"@libre/atom": "@libre/atom",
|
|
23
|
-
"@dbeining/react-atom": "@dbeining/react-atom"
|
|
20
|
+
"history": "history"
|
|
24
21
|
}
|
|
25
22
|
},
|
|
26
23
|
"author": "smapiot",
|
|
@@ -74,9 +71,9 @@
|
|
|
74
71
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
75
72
|
},
|
|
76
73
|
"dependencies": {
|
|
77
|
-
"
|
|
78
|
-
"piral-
|
|
79
|
-
"
|
|
74
|
+
"piral-base": "0.15.0-alpha.4396",
|
|
75
|
+
"piral-debug-utils": "0.15.0-alpha.4396",
|
|
76
|
+
"zustand": "^3.0.0"
|
|
80
77
|
},
|
|
81
78
|
"peerDependencies": {
|
|
82
79
|
"react": ">=16.8.0",
|
|
@@ -101,10 +98,7 @@
|
|
|
101
98
|
"react-router",
|
|
102
99
|
"react-router-dom",
|
|
103
100
|
"history",
|
|
104
|
-
"tslib"
|
|
105
|
-
"path-to-regexp",
|
|
106
|
-
"@libre/atom",
|
|
107
|
-
"@dbeining/react-atom"
|
|
101
|
+
"tslib"
|
|
108
102
|
],
|
|
109
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "62abff4d61634b3ecffda2407f1c29f1de929b4c"
|
|
110
104
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { render } from 'react-dom';
|
|
3
3
|
import { act } from 'react-dom/test-utils';
|
|
4
4
|
import { RootListener } from './RootListener';
|
|
5
5
|
|
|
@@ -10,7 +10,7 @@ jest.mock('./hooks/globalState', () => ({
|
|
|
10
10
|
}));
|
|
11
11
|
|
|
12
12
|
function resolveAfter(time = 5) {
|
|
13
|
-
return new Promise<void>(resolve => setTimeout(resolve, time));
|
|
13
|
+
return new Promise<void>((resolve) => setTimeout(resolve, time));
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
describe('RootListener Component', () => {
|
|
@@ -19,8 +19,7 @@ describe('RootListener Component', () => {
|
|
|
19
19
|
const removed = jest.fn();
|
|
20
20
|
document.body.appendChild(element);
|
|
21
21
|
const container = document.body.appendChild(document.createElement('div'));
|
|
22
|
-
|
|
23
|
-
root.render(<RootListener />);
|
|
22
|
+
render(<RootListener />, container);
|
|
24
23
|
document.body.removeEventListener = removed;
|
|
25
24
|
await act(() => {
|
|
26
25
|
const event = new CustomEvent('render-html', {
|
|
@@ -40,11 +39,10 @@ describe('RootListener Component', () => {
|
|
|
40
39
|
it('removes the RootListener successfully', async () => {
|
|
41
40
|
const container = document.body.appendChild(document.createElement('div'));
|
|
42
41
|
const removed = jest.fn();
|
|
43
|
-
|
|
44
|
-
root.render(<RootListener />);
|
|
42
|
+
render(<RootListener />, container);
|
|
45
43
|
document.body.removeEventListener = removed;
|
|
46
44
|
await act(resolveAfter);
|
|
47
|
-
|
|
45
|
+
render(<div />, container);
|
|
48
46
|
await act(resolveAfter);
|
|
49
47
|
expect(removed).toHaveBeenCalled();
|
|
50
48
|
});
|
package/src/actions/app.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import create from 'zustand';
|
|
1
2
|
import { mount } from 'enzyme';
|
|
2
3
|
import { createElement } from 'react';
|
|
3
|
-
import { Atom, deref } from '@dbeining/react-atom';
|
|
4
4
|
import { createListener, Pilet } from 'piral-base';
|
|
5
5
|
import {
|
|
6
6
|
includeProvider,
|
|
@@ -23,27 +23,27 @@ const pilet: Pilet = {
|
|
|
23
23
|
|
|
24
24
|
describe('App Actions Module', () => {
|
|
25
25
|
it('initialize initializes state data', () => {
|
|
26
|
-
const state =
|
|
26
|
+
const state: any = create(() => ({
|
|
27
27
|
app: {},
|
|
28
|
-
});
|
|
28
|
+
}));
|
|
29
29
|
const ctx = createActions(state, createListener({}));
|
|
30
|
-
const modules = ['pilet 1', 'pilet 2', 'pilet 3'];
|
|
30
|
+
const modules: any = ['pilet 1', 'pilet 2', 'pilet 3'];
|
|
31
31
|
initialize(ctx, false, undefined, modules);
|
|
32
|
-
expect(
|
|
32
|
+
expect(state.getState()).toEqual({
|
|
33
33
|
app: { error: undefined, loading: false },
|
|
34
34
|
modules: ['pilet 1', 'pilet 2', 'pilet 3'],
|
|
35
35
|
});
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
it('removePilet removes pilet', () => {
|
|
39
|
-
const state =
|
|
39
|
+
const state: any = create(() => ({
|
|
40
40
|
app: {},
|
|
41
41
|
modules: [pilet],
|
|
42
42
|
registry: { 'my-pilet': pilet },
|
|
43
|
-
});
|
|
43
|
+
}));
|
|
44
44
|
const ctx = createActions(state, createListener({}));
|
|
45
45
|
removePilet(ctx, 'my-pilet');
|
|
46
|
-
expect(
|
|
46
|
+
expect(state.getState()).toEqual({ app: {}, modules: [], registry: { 'my-pilet': pilet } });
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
it('injectPilet injects pilet', () => {
|
|
@@ -53,55 +53,55 @@ describe('App Actions Module', () => {
|
|
|
53
53
|
link: undefined,
|
|
54
54
|
custom: undefined,
|
|
55
55
|
};
|
|
56
|
-
const state =
|
|
56
|
+
const state: any = create(() => ({
|
|
57
57
|
app: {},
|
|
58
58
|
modules: [pilet2],
|
|
59
59
|
registry: { pilet2 },
|
|
60
|
-
});
|
|
60
|
+
}));
|
|
61
61
|
const ctx = createActions(state, createListener({}));
|
|
62
62
|
injectPilet(ctx, pilet);
|
|
63
|
-
expect(
|
|
63
|
+
expect(state.getState()).toEqual({ app: {}, modules: [pilet2, pilet], registry: { pilet2 } });
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
it('setComponent set component', () => {
|
|
67
|
-
const state =
|
|
67
|
+
const state: any = create(() => ({
|
|
68
68
|
components: {},
|
|
69
|
-
});
|
|
69
|
+
}));
|
|
70
70
|
const ctx = createActions(state, createListener({}));
|
|
71
71
|
const node = RootListener;
|
|
72
72
|
setComponent(ctx, 'ComponentName', node);
|
|
73
|
-
expect(
|
|
73
|
+
expect(state.getState()).toEqual({ components: { ComponentName: RootListener } });
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
it('setErrorComponent set error component', () => {
|
|
77
|
-
const state =
|
|
77
|
+
const state: any = create(() => ({
|
|
78
78
|
errorComponents: {},
|
|
79
|
-
});
|
|
79
|
+
}));
|
|
80
80
|
const ctx = createActions(state, createListener({}));
|
|
81
81
|
const node = RootListener;
|
|
82
82
|
setErrorComponent(ctx, 'ComponentName', node);
|
|
83
|
-
expect(
|
|
83
|
+
expect(state.getState()).toEqual({ errorComponents: { ComponentName: RootListener } });
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
it('setRoute sets route', () => {
|
|
87
|
-
const state =
|
|
87
|
+
const state: any = create(() => ({
|
|
88
88
|
routes: {},
|
|
89
|
-
});
|
|
89
|
+
}));
|
|
90
90
|
const ctx = createActions(state, createListener({}));
|
|
91
91
|
const node = RootListener;
|
|
92
92
|
setRoute(ctx, './dist', RootListener);
|
|
93
|
-
expect(
|
|
93
|
+
expect(state.getState()).toEqual({ routes: { './dist': RootListener } });
|
|
94
94
|
});
|
|
95
95
|
|
|
96
96
|
it('allows using includeProvider once', () => {
|
|
97
|
-
const state =
|
|
97
|
+
const state: any = create(() => ({
|
|
98
98
|
provider: undefined,
|
|
99
|
-
});
|
|
99
|
+
}));
|
|
100
100
|
const Provider = (props) => createElement('div', props);
|
|
101
101
|
const ctx = createActions(state, createListener({}));
|
|
102
102
|
includeProvider(ctx, createElement(Provider));
|
|
103
103
|
|
|
104
|
-
const NewProvider =
|
|
104
|
+
const NewProvider = state.getState().provider;
|
|
105
105
|
expect(NewProvider).not.toBeUndefined();
|
|
106
106
|
|
|
107
107
|
const node = mount(createElement(NewProvider, undefined, 'Some text'));
|
|
@@ -110,16 +110,16 @@ describe('App Actions Module', () => {
|
|
|
110
110
|
});
|
|
111
111
|
|
|
112
112
|
it('allows using includeProvider twice', () => {
|
|
113
|
-
const state =
|
|
113
|
+
const state: any = create(() => ({
|
|
114
114
|
provider: undefined,
|
|
115
|
-
});
|
|
115
|
+
}));
|
|
116
116
|
const Provider1 = (props) => createElement('i', props);
|
|
117
117
|
const Provider2 = (props) => createElement('b', props);
|
|
118
118
|
const ctx = createActions(state, createListener({}));
|
|
119
119
|
includeProvider(ctx, createElement(Provider1));
|
|
120
120
|
includeProvider(ctx, createElement(Provider2));
|
|
121
121
|
|
|
122
|
-
const NewProvider =
|
|
122
|
+
const NewProvider = state.getState().provider;
|
|
123
123
|
expect(NewProvider).not.toBeUndefined();
|
|
124
124
|
|
|
125
125
|
const node = mount(createElement(NewProvider, undefined, 'Some text'));
|
|
@@ -129,14 +129,14 @@ describe('App Actions Module', () => {
|
|
|
129
129
|
});
|
|
130
130
|
|
|
131
131
|
it('allows using includeProvider with props', () => {
|
|
132
|
-
const state =
|
|
132
|
+
const state: any = create(() => ({
|
|
133
133
|
provider: undefined,
|
|
134
|
-
});
|
|
134
|
+
}));
|
|
135
135
|
const Provider = (props) => createElement('i', props, props.text, props.children);
|
|
136
136
|
const ctx = createActions(state, createListener({}));
|
|
137
137
|
includeProvider(ctx, createElement(Provider, { text: 'Icecream' }));
|
|
138
138
|
|
|
139
|
-
const NewProvider =
|
|
139
|
+
const NewProvider = state.getState().provider;
|
|
140
140
|
expect(NewProvider).not.toBeUndefined();
|
|
141
141
|
|
|
142
142
|
const node = mount(createElement(NewProvider, undefined, 'Some text'));
|
|
@@ -146,16 +146,16 @@ describe('App Actions Module', () => {
|
|
|
146
146
|
});
|
|
147
147
|
|
|
148
148
|
it('allows multiple includeProvider with props', () => {
|
|
149
|
-
const state =
|
|
149
|
+
const state: any = create(() => ({
|
|
150
150
|
provider: undefined,
|
|
151
|
-
});
|
|
151
|
+
}));
|
|
152
152
|
const Provider1 = (props) => createElement('i', props, props.text, props.children);
|
|
153
153
|
const Provider2 = (props) => createElement('b', props, props.text, props.children);
|
|
154
154
|
const ctx = createActions(state, createListener({}));
|
|
155
155
|
includeProvider(ctx, createElement(Provider1, { text: 'Icecream' }));
|
|
156
156
|
includeProvider(ctx, createElement(Provider2, { text: 'Chocolate' }));
|
|
157
157
|
|
|
158
|
-
const NewProvider =
|
|
158
|
+
const NewProvider = state.getState().provider;
|
|
159
159
|
expect(NewProvider).not.toBeUndefined();
|
|
160
160
|
|
|
161
161
|
const node = mount(createElement(NewProvider, undefined, 'Some text'));
|