piral-core 0.15.0-alpha.4311 → 0.15.0-alpha.4345
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/app.codegen +191 -0
- package/{debug.codegen.d.ts → app.codegen.d.ts} +10 -1
- package/esm/actions/app.d.ts +1 -0
- package/esm/actions/app.js +3 -0
- package/esm/actions/app.js.map +1 -1
- package/esm/actions/state.js +6 -7
- package/esm/actions/state.js.map +1 -1
- package/esm/components/PiralRoutes.js +2 -6
- package/esm/components/PiralRoutes.js.map +1 -1
- package/esm/components/wrapComponent.js +2 -2
- package/esm/components/wrapComponent.js.map +1 -1
- package/esm/createInstance.js +1 -1
- package/esm/createInstance.js.map +1 -1
- package/esm/debugger.js +4 -2
- package/esm/debugger.js.map +1 -1
- package/esm/defaults/{DefaultRouteSwitch.d.ts → DefaultRouteSwitch_v5.d.ts} +0 -0
- package/esm/defaults/{DefaultRouteSwitch.js → DefaultRouteSwitch_v5.js} +2 -1
- package/esm/defaults/DefaultRouteSwitch_v5.js.map +1 -0
- package/{lib/defaults/DefaultRouteSwitch.d.ts → esm/defaults/DefaultRouteSwitch_v6.d.ts} +0 -0
- package/esm/defaults/DefaultRouteSwitch_v6.js +15 -0
- package/esm/defaults/DefaultRouteSwitch_v6.js.map +1 -0
- package/esm/defaults/{DefaultRouter.d.ts → DefaultRouter_v5.d.ts} +0 -0
- package/esm/defaults/{DefaultRouter.js → DefaultRouter_v5.js} +2 -1
- package/esm/defaults/DefaultRouter_v5.js.map +1 -0
- package/{lib/defaults/DefaultRouter.d.ts → esm/defaults/DefaultRouter_v6.d.ts} +0 -0
- package/esm/defaults/DefaultRouter_v6.js +9 -0
- package/esm/defaults/DefaultRouter_v6.js.map +1 -0
- package/esm/emulator.js +2 -3
- package/esm/emulator.js.map +1 -1
- package/esm/helpers.js +1 -1
- package/esm/helpers.js.map +1 -1
- package/esm/hooks/globalState.js +2 -9
- package/esm/hooks/globalState.js.map +1 -1
- package/esm/hooks/index.d.ts +1 -0
- package/esm/hooks/index.js +1 -0
- package/esm/hooks/index.js.map +1 -1
- package/esm/hooks/routes.d.ts +2 -0
- package/esm/hooks/routes.js +11 -0
- package/esm/hooks/routes.js.map +1 -0
- package/esm/modules/dependencies.js +1 -1
- package/esm/modules/dependencies.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 +4 -27
- package/esm/state/createGlobalState.js.map +1 -1
- package/esm/types/components.d.ts +14 -10
- package/esm/types/state.d.ts +8 -3
- package/lib/actions/app.d.ts +1 -0
- package/lib/actions/app.js +5 -1
- package/lib/actions/app.js.map +1 -1
- package/lib/actions/state.js +6 -7
- package/lib/actions/state.js.map +1 -1
- package/lib/components/PiralRoutes.js +1 -5
- package/lib/components/PiralRoutes.js.map +1 -1
- package/lib/components/wrapComponent.js +2 -2
- package/lib/components/wrapComponent.js.map +1 -1
- package/lib/createInstance.js +1 -1
- package/lib/createInstance.js.map +1 -1
- package/lib/debugger.js +4 -2
- package/lib/debugger.js.map +1 -1
- package/lib/defaults/DefaultRouteSwitch_v5.d.ts +3 -0
- package/lib/defaults/{DefaultRouteSwitch.js → DefaultRouteSwitch_v5.js} +2 -1
- package/lib/defaults/DefaultRouteSwitch_v5.js.map +1 -0
- package/lib/defaults/DefaultRouteSwitch_v6.d.ts +3 -0
- package/lib/defaults/DefaultRouteSwitch_v6.js +19 -0
- package/lib/defaults/DefaultRouteSwitch_v6.js.map +1 -0
- package/lib/defaults/DefaultRouter_v5.d.ts +3 -0
- package/lib/defaults/{DefaultRouter.js → DefaultRouter_v5.js} +2 -1
- package/lib/defaults/DefaultRouter_v5.js.map +1 -0
- package/lib/defaults/DefaultRouter_v6.d.ts +3 -0
- package/lib/defaults/DefaultRouter_v6.js +13 -0
- package/lib/defaults/DefaultRouter_v6.js.map +1 -0
- package/lib/emulator.js +2 -3
- package/lib/emulator.js.map +1 -1
- package/lib/helpers.js +3 -3
- package/lib/helpers.js.map +1 -1
- package/lib/hooks/globalState.js +2 -9
- package/lib/hooks/globalState.js.map +1 -1
- package/lib/hooks/index.d.ts +1 -0
- package/lib/hooks/index.js +1 -0
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/routes.d.ts +2 -0
- package/lib/hooks/routes.js +15 -0
- package/lib/hooks/routes.js.map +1 -0
- package/lib/modules/dependencies.js +3 -3
- package/lib/modules/dependencies.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 +4 -27
- package/lib/state/createGlobalState.js.map +1 -1
- package/lib/types/components.d.ts +14 -10
- package/lib/types/state.d.ts +8 -3
- package/package.json +13 -17
- package/src/Piral.test.tsx +7 -5
- package/src/RootListener.test.tsx +8 -4
- package/src/actions/app.test.ts +32 -32
- package/src/actions/app.ts +4 -0
- 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 +9 -5
- package/src/components/Mediator.test.tsx +11 -10
- package/src/components/PiralRoutes.test.tsx +23 -16
- package/src/components/PiralRoutes.tsx +2 -8
- package/src/components/wrapComponent.tsx +2 -2
- package/src/createInstance.tsx +1 -1
- package/src/debugger.ts +4 -2
- package/src/defaults/{DefaultRouteSwitch.tsx → DefaultRouteSwitch_v5.tsx} +1 -0
- package/src/defaults/DefaultRouteSwitch_v6.tsx +20 -0
- package/src/defaults/{DefaultRouter.tsx → DefaultRouter_v5.tsx} +1 -0
- package/src/defaults/DefaultRouter_v6.tsx +10 -0
- package/src/emulator.ts +2 -10
- package/src/helpers.test.tsx +9 -8
- package/src/helpers.tsx +1 -1
- package/src/hooks/globalState.ts +2 -11
- package/src/hooks/index.ts +1 -0
- package/src/hooks/routes.ts +14 -0
- package/src/hooks/setter.test.ts +1 -1
- package/src/modules/dependencies.ts +1 -1
- 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 +53 -58
- package/src/state/createGlobalState.ts +4 -34
- package/src/state/withApi.test.tsx +5 -5
- package/src/types/components.ts +15 -10
- package/src/types/state.ts +8 -3
- package/src/utils/foreign.test.ts +1 -1
- package/debug.codegen +0 -24
- package/dependencies.codegen +0 -37
- package/dependencies.codegen.d.ts +0 -1
- package/dependencies.codegen.native.js +0 -2
- package/esm/defaults/DefaultRouteSwitch.js.map +0 -1
- package/esm/defaults/DefaultRouter.js.map +0 -1
- package/esm/defaults/index.d.ts +0 -5
- package/esm/defaults/index.js +0 -6
- package/esm/defaults/index.js.map +0 -1
- package/lib/defaults/DefaultRouteSwitch.js.map +0 -1
- package/lib/defaults/DefaultRouter.js.map +0 -1
- package/lib/defaults/index.d.ts +0 -5
- package/lib/defaults/index.js +0 -9
- package/lib/defaults/index.js.map +0 -1
- package/src/defaults/index.ts +0 -5
- package/src/hooks/globalState-server.test.ts +0 -41
- package/src/hooks/globalState.test.ts +0 -47
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
//@ts-ignore
|
|
3
|
+
import { Routes, Route } from 'react-router-dom';
|
|
4
|
+
import { RouteSwitchProps } from '../types';
|
|
5
|
+
|
|
6
|
+
export const DefaultRouteSwitch: React.FC<RouteSwitchProps> = ({ paths, NotFound, ...props }) => {
|
|
7
|
+
return (
|
|
8
|
+
<Routes {...props}>
|
|
9
|
+
{paths.map(({ path, Component }) => (
|
|
10
|
+
//@ts-ignore
|
|
11
|
+
<Route key={path} path={path} element={<Component />} />
|
|
12
|
+
))}
|
|
13
|
+
{
|
|
14
|
+
//@ts-ignore
|
|
15
|
+
<Route element={<NotFound />} />
|
|
16
|
+
}
|
|
17
|
+
</Routes>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
DefaultRouteSwitch.displayName = 'DefaultRouteSwitch';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { BrowserRouter } from 'react-router-dom';
|
|
3
|
+
import { useGlobalState } from '../hooks';
|
|
4
|
+
import { RouterProps } from '../types';
|
|
5
|
+
|
|
6
|
+
export const DefaultRouter: React.FC<RouterProps> = ({ children }) => {
|
|
7
|
+
const publicPath = useGlobalState((s) => s.app.publicPath);
|
|
8
|
+
return <BrowserRouter basename={publicPath}>{children}</BrowserRouter>;
|
|
9
|
+
};
|
|
10
|
+
DefaultRouter.displayName = 'DefaultRouter';
|
package/src/emulator.ts
CHANGED
|
@@ -6,16 +6,8 @@ export function integrateEmulator(context: GlobalStateContext, options: LoadPile
|
|
|
6
6
|
installPiletEmulator(options.fetchPilets, {
|
|
7
7
|
addPilet: context.addPilet,
|
|
8
8
|
removePilet: context.removePilet,
|
|
9
|
-
integrate(
|
|
10
|
-
|
|
11
|
-
...s,
|
|
12
|
-
components: {
|
|
13
|
-
...s.components,
|
|
14
|
-
...emulator.components,
|
|
15
|
-
},
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
options.fetchPilets = emulator.requester;
|
|
9
|
+
integrate(requester) {
|
|
10
|
+
options.fetchPilets = requester;
|
|
19
11
|
},
|
|
20
12
|
});
|
|
21
13
|
}
|
package/src/helpers.test.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import create from 'zustand';
|
|
1
2
|
import { createPiletOptions, PiletOptionsConfig } from './helpers';
|
|
2
3
|
import { globalDependencies } from './modules';
|
|
3
4
|
import { PiletMetadata } from 'piral-base';
|
|
4
|
-
import { Atom, swap, deref } from '@dbeining/react-atom';
|
|
5
5
|
|
|
6
6
|
function createMockApi(meta: PiletMetadata) {
|
|
7
7
|
return {
|
|
@@ -13,7 +13,7 @@ function createMockApi(meta: PiletMetadata) {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
function createMockContainer() {
|
|
16
|
-
const state =
|
|
16
|
+
const state = create(() => ({
|
|
17
17
|
registry: {
|
|
18
18
|
pages: {},
|
|
19
19
|
extensions: {},
|
|
@@ -22,7 +22,7 @@ function createMockContainer() {
|
|
|
22
22
|
routes: {},
|
|
23
23
|
components: {},
|
|
24
24
|
modules: [],
|
|
25
|
-
});
|
|
25
|
+
}));
|
|
26
26
|
return {
|
|
27
27
|
context: {
|
|
28
28
|
on: jest.fn(),
|
|
@@ -30,19 +30,20 @@ function createMockContainer() {
|
|
|
30
30
|
emit: jest.fn(),
|
|
31
31
|
state,
|
|
32
32
|
dispatch(cb) {
|
|
33
|
-
|
|
33
|
+
state.setState(cb(state.getState()));
|
|
34
34
|
},
|
|
35
35
|
readState(cb) {
|
|
36
|
-
return cb(
|
|
36
|
+
return cb(state.getState());
|
|
37
37
|
},
|
|
38
38
|
setComponent(name, comp) {
|
|
39
|
-
|
|
39
|
+
const s = state.getState();
|
|
40
|
+
state.setState({
|
|
40
41
|
...s,
|
|
41
42
|
components: {
|
|
42
43
|
...s.components,
|
|
43
44
|
[name]: comp,
|
|
44
45
|
},
|
|
45
|
-
})
|
|
46
|
+
});
|
|
46
47
|
},
|
|
47
48
|
} as any,
|
|
48
49
|
};
|
|
@@ -85,7 +86,7 @@ describe('Piral-Core helpers module', () => {
|
|
|
85
86
|
const options = createPiletOptions(optionsConfig);
|
|
86
87
|
|
|
87
88
|
// Assert
|
|
88
|
-
expect(options.pilets
|
|
89
|
+
expect(options.pilets?.length).toEqual(providedPilets.length);
|
|
89
90
|
|
|
90
91
|
if (wasUndefined) {
|
|
91
92
|
process.env.DEBUG_PIRAL = undefined;
|
package/src/helpers.tsx
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import type { DebuggerExtensionOptions } from 'piral-debug-utils';
|
|
12
12
|
import { globalDependencies } from './modules';
|
|
13
13
|
import type { Pilet, PiletRequester, GlobalStateContext, PiletLoadingStrategy, DependencySelector } from './types';
|
|
14
|
-
import { integrateDebugger, integrateEmulator } from '../
|
|
14
|
+
import { integrateDebugger, integrateEmulator } from '../app.codegen';
|
|
15
15
|
|
|
16
16
|
export interface PiletOptionsConfig {
|
|
17
17
|
context: GlobalStateContext;
|
package/src/hooks/globalState.ts
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
|
-
import { useAtom, deref } from '@dbeining/react-atom';
|
|
3
2
|
import { StateContext } from '../state/stateContext';
|
|
4
3
|
import { GlobalState } from '../types';
|
|
5
4
|
|
|
6
|
-
const useGlobalAtom = typeof window !== 'undefined' ? useAtom : useDirectAtom;
|
|
7
|
-
|
|
8
|
-
function useDirectAtom(atom: any, opts: any) {
|
|
9
|
-
const state = deref(atom);
|
|
10
|
-
const select = opts && opts.select;
|
|
11
|
-
return typeof select === 'function' ? select(state) : state;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
5
|
/**
|
|
15
6
|
* Hook to obtain the global state context, which gives you directly
|
|
16
7
|
* all actions, state, and more of the Piral instance.
|
|
@@ -35,6 +26,6 @@ export function useGlobalState(): GlobalState;
|
|
|
35
26
|
export function useGlobalState<R>(select: (state: GlobalState) => R): R;
|
|
36
27
|
|
|
37
28
|
export function useGlobalState<R>(select?: (state: GlobalState) => R) {
|
|
38
|
-
const { state } = useGlobalStateContext();
|
|
39
|
-
return
|
|
29
|
+
const { state: useState } = useGlobalStateContext();
|
|
30
|
+
return useState(select);
|
|
40
31
|
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useGlobalState } from './globalState';
|
|
2
|
+
import { useRouteFilter } from '../../app.codegen';
|
|
3
|
+
import { AppPath } from '../types';
|
|
4
|
+
|
|
5
|
+
export function useRoutes() {
|
|
6
|
+
const routes = useGlobalState((s) => s.routes);
|
|
7
|
+
const pages = useGlobalState((s) => s.registry.pages);
|
|
8
|
+
const paths: Array<AppPath> = [];
|
|
9
|
+
|
|
10
|
+
Object.keys(routes).map((path) => paths.push({ path, Component: routes[path] }));
|
|
11
|
+
Object.keys(pages).map((path) => paths.push({ path, Component: pages[path].component }));
|
|
12
|
+
|
|
13
|
+
return useRouteFilter(paths);
|
|
14
|
+
}
|
package/src/hooks/setter.test.ts
CHANGED
|
@@ -14,7 +14,7 @@ describe('UseSetter Hook Module', () => {
|
|
|
14
14
|
|
|
15
15
|
const root = createRoot(document.body.appendChild(document.createElement('div')));
|
|
16
16
|
root.render(React.createElement(MyComponent));
|
|
17
|
-
await act(() => Promise
|
|
17
|
+
await act(() => new Promise(resolve => setTimeout(resolve, 5)));
|
|
18
18
|
expect(cb).toHaveBeenCalled();
|
|
19
19
|
});
|
|
20
20
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isfunc } from 'piral-base';
|
|
2
2
|
import type { AvailableDependencies, PiletEntries } from '../types';
|
|
3
|
-
import fillDependencies from '../../
|
|
3
|
+
import { fillDependencies } from '../../app.codegen';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The global dependencies, which represent the dependencies
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
* @jest-environment node
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import create from 'zustand';
|
|
6
6
|
import { createListener } from 'piral-base';
|
|
7
7
|
import { createActions } from '../state';
|
|
8
8
|
import { renderElement } from './element';
|
|
9
9
|
|
|
10
10
|
function createMockContext(): [any, any] {
|
|
11
|
-
const state =
|
|
11
|
+
const state: any = create(() => ({
|
|
12
12
|
portals: {
|
|
13
13
|
root: [],
|
|
14
14
|
},
|
|
15
|
-
});
|
|
15
|
+
}));
|
|
16
16
|
const context = createActions(state, createListener({}));
|
|
17
17
|
return [context, state];
|
|
18
18
|
}
|
|
@@ -24,6 +24,6 @@ describe('Elements Module from SSR', () => {
|
|
|
24
24
|
addEventListener() {},
|
|
25
25
|
};
|
|
26
26
|
renderElement(context, element, {});
|
|
27
|
-
expect(
|
|
27
|
+
expect(state.getState().portals.root.length).toBe(0);
|
|
28
28
|
});
|
|
29
29
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import create from 'zustand';
|
|
2
2
|
import { createListener } from 'piral-base';
|
|
3
3
|
import { createActions } from '../state';
|
|
4
4
|
import { renderElement } from './element';
|
|
@@ -14,9 +14,9 @@ declare global {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
function createMockContext(): [any, any] {
|
|
17
|
-
const state =
|
|
17
|
+
const state: any = create(() => ({
|
|
18
18
|
portals: {},
|
|
19
|
-
});
|
|
19
|
+
}));
|
|
20
20
|
const context = createActions(state, createListener({}));
|
|
21
21
|
return [context, state];
|
|
22
22
|
}
|
|
@@ -31,7 +31,7 @@ describe('Elements Module', () => {
|
|
|
31
31
|
element.dispatchEvent(event);
|
|
32
32
|
document.body.removeChild(element);
|
|
33
33
|
(element as any).connectedCallback();
|
|
34
|
-
expect(
|
|
34
|
+
expect(state.getState().portals.root.length).toBe(1);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
it('disposing piral-extension web component', () => {
|
|
@@ -39,9 +39,9 @@ describe('Elements Module', () => {
|
|
|
39
39
|
const element = document.createElement('piral-extension');
|
|
40
40
|
document.body.appendChild(element);
|
|
41
41
|
const [dispose] = renderElement(context, element, {});
|
|
42
|
-
expect(
|
|
42
|
+
expect(state.getState().portals.root.length).toBe(1);
|
|
43
43
|
dispose();
|
|
44
|
-
expect(
|
|
44
|
+
expect(state.getState().portals.root.length).toBe(0);
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
it('testing setters and getters in piral-extension web component', () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import create from 'zustand';
|
|
2
3
|
import { mount } from 'enzyme';
|
|
3
|
-
import { Atom, swap, deref } from '@dbeining/react-atom';
|
|
4
4
|
import { SetComponent } from './SetComponent';
|
|
5
5
|
import { StateContext } from '../state';
|
|
6
6
|
|
|
@@ -8,9 +8,9 @@ const FakeLoading = () => null;
|
|
|
8
8
|
FakeLoading.displayName = 'FakeLoading';
|
|
9
9
|
|
|
10
10
|
function createMockContainer() {
|
|
11
|
-
const state =
|
|
11
|
+
const state = create(() => ({
|
|
12
12
|
components: {},
|
|
13
|
-
});
|
|
13
|
+
}));
|
|
14
14
|
return {
|
|
15
15
|
context: {
|
|
16
16
|
on: jest.fn(),
|
|
@@ -18,13 +18,14 @@ function createMockContainer() {
|
|
|
18
18
|
emit: jest.fn(),
|
|
19
19
|
state,
|
|
20
20
|
setComponent(name, comp) {
|
|
21
|
-
|
|
21
|
+
const s = state.getState();
|
|
22
|
+
state.setState({
|
|
22
23
|
...s,
|
|
23
24
|
components: {
|
|
24
25
|
...s.components,
|
|
25
26
|
[name]: comp,
|
|
26
27
|
},
|
|
27
|
-
})
|
|
28
|
+
});
|
|
28
29
|
},
|
|
29
30
|
} as any,
|
|
30
31
|
};
|
|
@@ -38,7 +39,7 @@ describe('Piral-Core SetComponent component', () => {
|
|
|
38
39
|
<SetComponent name="LoadingIndicator" component={FakeLoading} />
|
|
39
40
|
</StateContext.Provider>,
|
|
40
41
|
);
|
|
41
|
-
expect(
|
|
42
|
+
expect(context.state.getState().components).toEqual({
|
|
42
43
|
LoadingIndicator: FakeLoading,
|
|
43
44
|
});
|
|
44
45
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import create from 'zustand';
|
|
2
3
|
import { mount } from 'enzyme';
|
|
3
|
-
import { Atom, swap, deref } from '@dbeining/react-atom';
|
|
4
4
|
import { SetError } from './SetError';
|
|
5
5
|
import { StateContext } from '../state';
|
|
6
6
|
|
|
@@ -8,9 +8,9 @@ const FakeError = () => null;
|
|
|
8
8
|
FakeError.displayName = 'FakeError';
|
|
9
9
|
|
|
10
10
|
function createMockContainer() {
|
|
11
|
-
const state =
|
|
11
|
+
const state = create(() => ({
|
|
12
12
|
errorComponents: {},
|
|
13
|
-
});
|
|
13
|
+
}));
|
|
14
14
|
return {
|
|
15
15
|
context: {
|
|
16
16
|
on: jest.fn(),
|
|
@@ -18,13 +18,14 @@ function createMockContainer() {
|
|
|
18
18
|
emit: jest.fn(),
|
|
19
19
|
state,
|
|
20
20
|
setErrorComponent(name, comp) {
|
|
21
|
-
|
|
21
|
+
const s = state.getState();
|
|
22
|
+
state.setState({
|
|
22
23
|
...s,
|
|
23
24
|
errorComponents: {
|
|
24
25
|
...s.errorComponents,
|
|
25
26
|
[name]: comp,
|
|
26
27
|
},
|
|
27
|
-
})
|
|
28
|
+
});
|
|
28
29
|
},
|
|
29
30
|
} as any,
|
|
30
31
|
};
|
|
@@ -38,7 +39,7 @@ describe('Piral-Core SetError component', () => {
|
|
|
38
39
|
<SetError type="loading" component={FakeError} />
|
|
39
40
|
</StateContext.Provider>,
|
|
40
41
|
);
|
|
41
|
-
expect(
|
|
42
|
+
expect((context.state.getState()).errorComponents).toEqual({
|
|
42
43
|
loading: FakeError,
|
|
43
44
|
});
|
|
44
45
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import create from 'zustand';
|
|
2
3
|
import { mount } from 'enzyme';
|
|
3
|
-
import { Atom, swap, deref } from '@dbeining/react-atom';
|
|
4
4
|
import { SetErrors } from './SetErrors';
|
|
5
5
|
import { StateContext } from '../state/stateContext';
|
|
6
6
|
|
|
@@ -8,9 +8,9 @@ const FakeError = () => null;
|
|
|
8
8
|
FakeError.displayName = 'FakeError';
|
|
9
9
|
|
|
10
10
|
function createMockContainer() {
|
|
11
|
-
const state =
|
|
11
|
+
const state = create(() => ({
|
|
12
12
|
errorComponents: {},
|
|
13
|
-
});
|
|
13
|
+
}));
|
|
14
14
|
return {
|
|
15
15
|
context: {
|
|
16
16
|
on: jest.fn(),
|
|
@@ -18,13 +18,14 @@ function createMockContainer() {
|
|
|
18
18
|
emit: jest.fn(),
|
|
19
19
|
state,
|
|
20
20
|
setErrorComponent(name, comp) {
|
|
21
|
-
|
|
21
|
+
const s = state.getState();
|
|
22
|
+
state.setState({
|
|
22
23
|
...s,
|
|
23
24
|
errorComponents: {
|
|
24
25
|
...s.errorComponents,
|
|
25
26
|
[name]: comp,
|
|
26
27
|
},
|
|
27
|
-
})
|
|
28
|
+
});
|
|
28
29
|
},
|
|
29
30
|
} as any,
|
|
30
31
|
};
|
|
@@ -44,7 +45,7 @@ describe('Piral SetErrors component', () => {
|
|
|
44
45
|
/>
|
|
45
46
|
</StateContext.Provider>,
|
|
46
47
|
);
|
|
47
|
-
expect(
|
|
48
|
+
expect(context.state.getState().errorComponents).toEqual({
|
|
48
49
|
menu: FakeError,
|
|
49
50
|
});
|
|
50
51
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import create from 'zustand';
|
|
2
3
|
import { mount } from 'enzyme';
|
|
3
|
-
import { Atom, swap, deref } from '@dbeining/react-atom';
|
|
4
4
|
import { SetLayout } from './SetLayout';
|
|
5
5
|
import { StateContext } from '../state/stateContext';
|
|
6
6
|
|
|
@@ -8,9 +8,9 @@ const FakeContainer = () => null;
|
|
|
8
8
|
FakeContainer.displayName = 'FakeContainer';
|
|
9
9
|
|
|
10
10
|
function createMockContainer() {
|
|
11
|
-
const state =
|
|
11
|
+
const state = create(() => ({
|
|
12
12
|
components: {},
|
|
13
|
-
});
|
|
13
|
+
}));
|
|
14
14
|
return {
|
|
15
15
|
context: {
|
|
16
16
|
on: jest.fn(),
|
|
@@ -18,13 +18,14 @@ function createMockContainer() {
|
|
|
18
18
|
emit: jest.fn(),
|
|
19
19
|
state,
|
|
20
20
|
setComponent(name, comp) {
|
|
21
|
-
|
|
21
|
+
const s = state.getState();
|
|
22
|
+
state.setState({
|
|
22
23
|
...s,
|
|
23
24
|
components: {
|
|
24
25
|
...s.components,
|
|
25
26
|
[name]: comp,
|
|
26
27
|
},
|
|
27
|
-
})
|
|
28
|
+
});
|
|
28
29
|
},
|
|
29
30
|
} as any,
|
|
30
31
|
};
|
|
@@ -44,7 +45,7 @@ describe('Piral SetLayout component', () => {
|
|
|
44
45
|
/>
|
|
45
46
|
</StateContext.Provider>,
|
|
46
47
|
);
|
|
47
|
-
expect(
|
|
48
|
+
expect(context.state.getState().components).toEqual({
|
|
48
49
|
DashboardContainer: FakeContainer,
|
|
49
50
|
});
|
|
50
51
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import create from 'zustand';
|
|
2
3
|
import { mount } from 'enzyme';
|
|
3
|
-
import { Atom, swap, deref } from '@dbeining/react-atom';
|
|
4
4
|
import { SetProvider } from './SetProvider';
|
|
5
5
|
import { StateContext } from '../state';
|
|
6
6
|
|
|
@@ -8,9 +8,9 @@ const FakeProvider = () => null;
|
|
|
8
8
|
FakeProvider.displayName = 'FakeProvider';
|
|
9
9
|
|
|
10
10
|
function createMockContainer() {
|
|
11
|
-
const state =
|
|
11
|
+
const state = create(() => ({
|
|
12
12
|
providers: [],
|
|
13
|
-
});
|
|
13
|
+
}));
|
|
14
14
|
return {
|
|
15
15
|
context: {
|
|
16
16
|
on: jest.fn(),
|
|
@@ -18,10 +18,11 @@ function createMockContainer() {
|
|
|
18
18
|
emit: jest.fn(),
|
|
19
19
|
state,
|
|
20
20
|
includeProvider(provider) {
|
|
21
|
-
|
|
21
|
+
const update = (s) => ({
|
|
22
22
|
...s,
|
|
23
23
|
providers: [...s.providers, provider],
|
|
24
|
-
})
|
|
24
|
+
});
|
|
25
|
+
state.setState(update(state.getState()));
|
|
25
26
|
},
|
|
26
27
|
} as any,
|
|
27
28
|
};
|
|
@@ -36,6 +37,6 @@ describe('Piral-Core SetProvider component', () => {
|
|
|
36
37
|
<SetProvider provider={provider} />
|
|
37
38
|
</StateContext.Provider>,
|
|
38
39
|
);
|
|
39
|
-
expect(
|
|
40
|
+
expect(context.state.getState().providers).toEqual([provider]);
|
|
40
41
|
});
|
|
41
42
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import create from 'zustand';
|
|
2
3
|
import { mount } from 'enzyme';
|
|
3
|
-
import { Atom, swap, deref } from '@dbeining/react-atom';
|
|
4
4
|
import { SetRedirect } from './SetRedirect';
|
|
5
5
|
import { StateContext } from '../state';
|
|
6
6
|
|
|
7
7
|
function createMockContainer() {
|
|
8
|
-
const state =
|
|
8
|
+
const state = create(() => ({
|
|
9
9
|
routes: {},
|
|
10
|
-
});
|
|
10
|
+
}));
|
|
11
11
|
return {
|
|
12
12
|
context: {
|
|
13
13
|
on: jest.fn(),
|
|
@@ -15,13 +15,14 @@ function createMockContainer() {
|
|
|
15
15
|
emit: jest.fn(),
|
|
16
16
|
state,
|
|
17
17
|
setRoute(name, comp) {
|
|
18
|
-
|
|
18
|
+
const update = (s) => ({
|
|
19
19
|
...s,
|
|
20
20
|
routes: {
|
|
21
21
|
...s.routes,
|
|
22
22
|
[name]: comp,
|
|
23
23
|
},
|
|
24
|
-
})
|
|
24
|
+
});
|
|
25
|
+
state.setState(update(state.getState()));
|
|
25
26
|
},
|
|
26
27
|
} as any,
|
|
27
28
|
};
|
|
@@ -35,7 +36,7 @@ describe('Piral-Core SetRedirect component', () => {
|
|
|
35
36
|
<SetRedirect from="/foo" to="/bar" />
|
|
36
37
|
</StateContext.Provider>,
|
|
37
38
|
);
|
|
38
|
-
expect(
|
|
39
|
+
expect(context.state.getState().routes).toEqual({
|
|
39
40
|
'/foo': expect.anything(),
|
|
40
41
|
});
|
|
41
42
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import create from 'zustand';
|
|
2
3
|
import { mount } from 'enzyme';
|
|
3
|
-
import { Atom, swap, deref } from '@dbeining/react-atom';
|
|
4
4
|
import { SetRoute } from './SetRoute';
|
|
5
5
|
import { StateContext } from '../state';
|
|
6
6
|
|
|
@@ -8,9 +8,9 @@ const FakeRoute = () => null;
|
|
|
8
8
|
FakeRoute.displayName = 'FakeRoute';
|
|
9
9
|
|
|
10
10
|
function createMockContainer() {
|
|
11
|
-
const state =
|
|
11
|
+
const state = create(() => ({
|
|
12
12
|
routes: {},
|
|
13
|
-
});
|
|
13
|
+
}));
|
|
14
14
|
return {
|
|
15
15
|
context: {
|
|
16
16
|
on: jest.fn(),
|
|
@@ -18,13 +18,14 @@ function createMockContainer() {
|
|
|
18
18
|
emit: jest.fn(),
|
|
19
19
|
state,
|
|
20
20
|
setRoute(name, comp) {
|
|
21
|
-
|
|
21
|
+
const update = (s) => ({
|
|
22
22
|
...s,
|
|
23
23
|
routes: {
|
|
24
24
|
...s.routes,
|
|
25
25
|
[name]: comp,
|
|
26
26
|
},
|
|
27
|
-
})
|
|
27
|
+
});
|
|
28
|
+
state.setState(update(state.getState()));
|
|
28
29
|
},
|
|
29
30
|
} as any,
|
|
30
31
|
};
|
|
@@ -38,7 +39,7 @@ describe('Piral-Core SetRoute component', () => {
|
|
|
38
39
|
<SetRoute path="/foo" component={FakeRoute} />
|
|
39
40
|
</StateContext.Provider>,
|
|
40
41
|
);
|
|
41
|
-
expect(
|
|
42
|
+
expect(context.state.getState().routes).toEqual({
|
|
42
43
|
'/foo': FakeRoute,
|
|
43
44
|
});
|
|
44
45
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as actions from '../actions';
|
|
2
|
-
import {
|
|
2
|
+
import { UseBoundStore } from 'zustand';
|
|
3
3
|
import { EventEmitter, GlobalState, GlobalStateContext, PiralDefineActions } from '../types';
|
|
4
4
|
|
|
5
|
-
function createContext(state:
|
|
5
|
+
function createContext(state: UseBoundStore<GlobalState>, events: EventEmitter) {
|
|
6
6
|
const ctx = {
|
|
7
7
|
...events,
|
|
8
8
|
apis: {},
|
|
@@ -23,7 +23,7 @@ export function includeActions(ctx: GlobalStateContext, actions: PiralDefineActi
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export function createActions(state:
|
|
26
|
+
export function createActions(state: UseBoundStore<GlobalState>, events: EventEmitter): GlobalStateContext {
|
|
27
27
|
const context = createContext(state, events);
|
|
28
28
|
includeActions(context, actions);
|
|
29
29
|
return context;
|