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
package/src/actions/data.test.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import create from 'zustand';
|
|
2
2
|
import { createListener } from 'piral-base';
|
|
3
3
|
import { readDataItem, readDataValue, resetData, tryWriteDataItem, writeDataItem } from './data';
|
|
4
4
|
|
|
5
5
|
describe('Data Actions Module', () => {
|
|
6
6
|
it('readDataItem reads the current item', () => {
|
|
7
|
-
const state =
|
|
7
|
+
const state = create(() => ({
|
|
8
8
|
foo: 5,
|
|
9
9
|
data: {
|
|
10
10
|
foo: 10,
|
|
11
11
|
},
|
|
12
|
-
});
|
|
12
|
+
}));
|
|
13
13
|
const ctx: any = {
|
|
14
14
|
state,
|
|
15
15
|
dispatch(update) {
|
|
16
|
-
|
|
16
|
+
state.setState(update(state.getState()));
|
|
17
17
|
},
|
|
18
18
|
readState(select) {
|
|
19
|
-
return select(
|
|
19
|
+
return select(state.getState());
|
|
20
20
|
},
|
|
21
21
|
};
|
|
22
22
|
const value = readDataItem(ctx, 'foo');
|
|
@@ -24,21 +24,21 @@ describe('Data Actions Module', () => {
|
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
it('readDataValue reads the current value', () => {
|
|
27
|
-
const state =
|
|
27
|
+
const state = create(() => ({
|
|
28
28
|
foo: 5,
|
|
29
29
|
data: {
|
|
30
30
|
foo: {
|
|
31
31
|
value: 15,
|
|
32
32
|
},
|
|
33
33
|
},
|
|
34
|
-
});
|
|
34
|
+
}));
|
|
35
35
|
const ctx: any = {
|
|
36
36
|
state,
|
|
37
37
|
dispatch(update) {
|
|
38
|
-
|
|
38
|
+
state.setState(update(state.getState()));
|
|
39
39
|
},
|
|
40
40
|
readState(select) {
|
|
41
|
-
return select(
|
|
41
|
+
return select(state.getState());
|
|
42
42
|
},
|
|
43
43
|
};
|
|
44
44
|
const value = readDataValue(ctx, 'foo');
|
|
@@ -46,48 +46,48 @@ describe('Data Actions Module', () => {
|
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
it('resetData clears all items', () => {
|
|
49
|
-
const state =
|
|
49
|
+
const state = create(() => ({
|
|
50
50
|
foo: 5,
|
|
51
51
|
data: {
|
|
52
52
|
foo: 10,
|
|
53
53
|
bar: [5],
|
|
54
54
|
},
|
|
55
|
-
});
|
|
55
|
+
}));
|
|
56
56
|
const ctx: any = {
|
|
57
57
|
state,
|
|
58
58
|
dispatch(update) {
|
|
59
|
-
|
|
59
|
+
state.setState(update(state.getState()));
|
|
60
60
|
},
|
|
61
61
|
readState(select) {
|
|
62
|
-
return select(
|
|
62
|
+
return select(state.getState());
|
|
63
63
|
},
|
|
64
64
|
};
|
|
65
65
|
resetData(ctx);
|
|
66
|
-
expect(
|
|
66
|
+
expect(state.getState()).toEqual({
|
|
67
67
|
foo: 5,
|
|
68
68
|
data: {},
|
|
69
69
|
});
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
it('writeDataItem adds a new data item', () => {
|
|
73
|
-
const state =
|
|
73
|
+
const state = create(() => ({
|
|
74
74
|
foo: 5,
|
|
75
75
|
data: {
|
|
76
76
|
foo: 10,
|
|
77
77
|
bar: [5],
|
|
78
78
|
},
|
|
79
|
-
});
|
|
79
|
+
}));
|
|
80
80
|
const ctx: any = Object.assign(createListener(undefined), {
|
|
81
81
|
state,
|
|
82
82
|
dispatch(update) {
|
|
83
|
-
|
|
83
|
+
state.setState(update(state.getState()));
|
|
84
84
|
},
|
|
85
85
|
readState(select) {
|
|
86
|
-
return select(
|
|
86
|
+
return select(state.getState());
|
|
87
87
|
},
|
|
88
88
|
});
|
|
89
|
-
writeDataItem(ctx, 'fi', 0);
|
|
90
|
-
expect(
|
|
89
|
+
writeDataItem(ctx, 'fi', 0, undefined, undefined, undefined);
|
|
90
|
+
expect(state.getState()).toEqual({
|
|
91
91
|
foo: 5,
|
|
92
92
|
data: {
|
|
93
93
|
foo: 10,
|
|
@@ -103,24 +103,24 @@ describe('Data Actions Module', () => {
|
|
|
103
103
|
});
|
|
104
104
|
|
|
105
105
|
it('writeDataItem overwrites an existing data item', () => {
|
|
106
|
-
const state =
|
|
106
|
+
const state = create(() => ({
|
|
107
107
|
foo: 5,
|
|
108
108
|
data: {
|
|
109
109
|
foo: 10,
|
|
110
110
|
bar: [5],
|
|
111
111
|
},
|
|
112
|
-
});
|
|
112
|
+
}));
|
|
113
113
|
const ctx: any = Object.assign(createListener(undefined), {
|
|
114
114
|
state,
|
|
115
115
|
dispatch(update) {
|
|
116
|
-
|
|
116
|
+
state.setState(update(state.getState()));
|
|
117
117
|
},
|
|
118
118
|
readState(select) {
|
|
119
|
-
return select(
|
|
119
|
+
return select(state.getState());
|
|
120
120
|
},
|
|
121
121
|
});
|
|
122
|
-
writeDataItem(ctx, 'bar', 0);
|
|
123
|
-
expect(
|
|
122
|
+
writeDataItem(ctx, 'bar', 0, undefined, undefined, undefined);
|
|
123
|
+
expect(state.getState()).toEqual({
|
|
124
124
|
foo: 5,
|
|
125
125
|
data: {
|
|
126
126
|
foo: 10,
|
|
@@ -135,24 +135,24 @@ describe('Data Actions Module', () => {
|
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
it('writeDataItem removes an existing data item', () => {
|
|
138
|
-
const state =
|
|
138
|
+
const state = create(() => ({
|
|
139
139
|
foo: 5,
|
|
140
140
|
data: {
|
|
141
141
|
foo: 10,
|
|
142
142
|
bar: [5],
|
|
143
143
|
},
|
|
144
|
-
});
|
|
144
|
+
}));
|
|
145
145
|
const ctx: any = Object.assign(createListener(undefined), {
|
|
146
146
|
state,
|
|
147
147
|
dispatch(update) {
|
|
148
|
-
|
|
148
|
+
state.setState(update(state.getState()));
|
|
149
149
|
},
|
|
150
150
|
readState(select) {
|
|
151
|
-
return select(
|
|
151
|
+
return select(state.getState());
|
|
152
152
|
},
|
|
153
153
|
});
|
|
154
|
-
writeDataItem(ctx, 'bar', null);
|
|
155
|
-
expect(
|
|
154
|
+
writeDataItem(ctx, 'bar', null, undefined, undefined, undefined);
|
|
155
|
+
expect(state.getState()).toEqual({
|
|
156
156
|
foo: 5,
|
|
157
157
|
data: {
|
|
158
158
|
foo: 10,
|
|
@@ -161,27 +161,27 @@ describe('Data Actions Module', () => {
|
|
|
161
161
|
});
|
|
162
162
|
|
|
163
163
|
it('tryWriteDataItem can write new item', () => {
|
|
164
|
-
const state =
|
|
164
|
+
const state = create(() => ({
|
|
165
165
|
foo: 5,
|
|
166
166
|
data: {
|
|
167
167
|
foo: 10,
|
|
168
168
|
},
|
|
169
|
-
});
|
|
169
|
+
}));
|
|
170
170
|
const ctx: any = Object.assign(createListener(undefined), {
|
|
171
171
|
state,
|
|
172
172
|
dispatch(update) {
|
|
173
|
-
|
|
173
|
+
state.setState(update(state.getState()));
|
|
174
174
|
},
|
|
175
175
|
readState(select) {
|
|
176
|
-
return select(
|
|
176
|
+
return select(state.getState());
|
|
177
177
|
},
|
|
178
178
|
});
|
|
179
|
-
const success = tryWriteDataItem(ctx, 'bar', 10, 'me');
|
|
179
|
+
const success = tryWriteDataItem(ctx, 'bar', 10, 'me', undefined, undefined);
|
|
180
180
|
expect(success).toBe(true);
|
|
181
181
|
});
|
|
182
182
|
|
|
183
183
|
it('tryWriteDataItem can overwrite item if owner', () => {
|
|
184
|
-
const state =
|
|
184
|
+
const state = create(() => ({
|
|
185
185
|
foo: 5,
|
|
186
186
|
data: {
|
|
187
187
|
foo: 10,
|
|
@@ -190,23 +190,23 @@ describe('Data Actions Module', () => {
|
|
|
190
190
|
value: 5,
|
|
191
191
|
},
|
|
192
192
|
},
|
|
193
|
-
});
|
|
193
|
+
}));
|
|
194
194
|
const ctx: any = Object.assign(createListener(undefined), {
|
|
195
195
|
state,
|
|
196
196
|
dispatch(update) {
|
|
197
|
-
|
|
197
|
+
state.setState(update(state.getState()));
|
|
198
198
|
},
|
|
199
199
|
readState(select) {
|
|
200
|
-
return select(
|
|
200
|
+
return select(state.getState());
|
|
201
201
|
},
|
|
202
202
|
});
|
|
203
|
-
const success = tryWriteDataItem(ctx, 'bar', 10, 'me');
|
|
203
|
+
const success = tryWriteDataItem(ctx, 'bar', 10, 'me', undefined, undefined);
|
|
204
204
|
expect(success).toBe(true);
|
|
205
|
-
expect(
|
|
205
|
+
expect(state.getState().data.bar.value).toBe(10);
|
|
206
206
|
});
|
|
207
207
|
|
|
208
208
|
it('tryWriteDataItem can not overwrite item if not owner', () => {
|
|
209
|
-
const state =
|
|
209
|
+
const state = create(() => ({
|
|
210
210
|
foo: 5,
|
|
211
211
|
data: {
|
|
212
212
|
foo: 10,
|
|
@@ -215,18 +215,18 @@ describe('Data Actions Module', () => {
|
|
|
215
215
|
value: 5,
|
|
216
216
|
},
|
|
217
217
|
},
|
|
218
|
-
});
|
|
218
|
+
}));
|
|
219
219
|
const ctx: any = Object.assign(createListener(undefined), {
|
|
220
220
|
state,
|
|
221
221
|
dispatch(update) {
|
|
222
|
-
|
|
222
|
+
state.setState(update(state.getState()));
|
|
223
223
|
},
|
|
224
224
|
readState(select) {
|
|
225
|
-
return select(
|
|
225
|
+
return select(state.getState());
|
|
226
226
|
},
|
|
227
227
|
});
|
|
228
|
-
const success = tryWriteDataItem(ctx, 'bar', 10, 'me');
|
|
228
|
+
const success = tryWriteDataItem(ctx, 'bar', 10, 'me', undefined, undefined);
|
|
229
229
|
expect(success).toBe(false);
|
|
230
|
-
expect(
|
|
230
|
+
expect(state.getState().data.bar.value).toBe(5);
|
|
231
231
|
});
|
|
232
232
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import create from 'zustand';
|
|
2
2
|
import { defineAction, defineActions } from './define';
|
|
3
3
|
|
|
4
4
|
function createMockContainer(initialState = {}) {
|
|
5
|
-
const state =
|
|
5
|
+
const state = create(() => initialState);
|
|
6
6
|
return {
|
|
7
7
|
context: {
|
|
8
8
|
on: jest.fn(),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import create from 'zustand';
|
|
3
3
|
import { showPortal, destroyPortal, hidePortal, updatePortal } from './portal';
|
|
4
4
|
|
|
5
5
|
describe('Piral-Core portal actions', () => {
|
|
@@ -7,19 +7,19 @@ describe('Piral-Core portal actions', () => {
|
|
|
7
7
|
const children = React.createElement('div');
|
|
8
8
|
const portal: React.ReactPortal = { key: 'test', children: { children }, type: 'div', props: null };
|
|
9
9
|
|
|
10
|
-
const state =
|
|
10
|
+
const state = create(() => ({
|
|
11
11
|
portals: { test: { portal } },
|
|
12
|
-
});
|
|
12
|
+
}));
|
|
13
13
|
|
|
14
14
|
const ctx: any = {
|
|
15
15
|
state,
|
|
16
16
|
dispatch(update) {
|
|
17
|
-
|
|
17
|
+
state.setState(update(state.getState()));
|
|
18
18
|
},
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
destroyPortal(ctx, 'test');
|
|
22
|
-
const { portals } =
|
|
22
|
+
const { portals } = ctx.state.getState();
|
|
23
23
|
expect(portals).not.toBeNull();
|
|
24
24
|
expect(portals.test).toBeUndefined();
|
|
25
25
|
});
|
|
@@ -29,19 +29,19 @@ describe('Piral-Core portal actions', () => {
|
|
|
29
29
|
const newPortal: React.ReactPortal = { key: 'test', children: { children }, type: 'div', props: null };
|
|
30
30
|
const portal: React.ReactPortal = { key: 'toast', children: { children }, type: 'div', props: null };
|
|
31
31
|
|
|
32
|
-
const state =
|
|
32
|
+
const state = create(() => ({
|
|
33
33
|
portals: { p1: { portal } },
|
|
34
|
-
});
|
|
34
|
+
}));
|
|
35
35
|
|
|
36
36
|
const ctx: any = {
|
|
37
37
|
state,
|
|
38
38
|
dispatch(update) {
|
|
39
|
-
|
|
39
|
+
state.setState(update(state.getState()));
|
|
40
40
|
},
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
hidePortal(ctx, 'test', newPortal);
|
|
44
|
-
const { portals } =
|
|
44
|
+
const { portals } = ctx.state.getState();
|
|
45
45
|
expect(portals).not.toBeNull();
|
|
46
46
|
expect(portals.test).not.toBeNull();
|
|
47
47
|
});
|
|
@@ -52,19 +52,19 @@ describe('Piral-Core portal actions', () => {
|
|
|
52
52
|
const next: React.ReactPortal = { key: 'next', children: { children }, type: 'div', props: null };
|
|
53
53
|
const portal: React.ReactPortal = { key: 'toast', children: { children }, type: 'div', props: null };
|
|
54
54
|
|
|
55
|
-
const state =
|
|
55
|
+
const state = create(() => ({
|
|
56
56
|
portals: { p1: { portal } },
|
|
57
|
-
});
|
|
57
|
+
}));
|
|
58
58
|
|
|
59
59
|
const ctx: any = {
|
|
60
60
|
state,
|
|
61
61
|
dispatch(update) {
|
|
62
|
-
|
|
62
|
+
state.setState(update(state.getState()));
|
|
63
63
|
},
|
|
64
64
|
};
|
|
65
65
|
|
|
66
66
|
updatePortal(ctx, 'test', current, next);
|
|
67
|
-
const { portals } =
|
|
67
|
+
const { portals } = ctx.state.getState();
|
|
68
68
|
expect(portals).not.toBeNull();
|
|
69
69
|
expect(portals.test).not.toBeNull();
|
|
70
70
|
});
|
|
@@ -74,19 +74,19 @@ describe('Piral-Core portal actions', () => {
|
|
|
74
74
|
const newPortal: React.ReactPortal = { key: 'test', children: { children }, type: 'div', props: null };
|
|
75
75
|
const portal: React.ReactPortal = { key: 'toast', children: { children }, type: 'div', props: null };
|
|
76
76
|
|
|
77
|
-
const state =
|
|
77
|
+
const state = create(() => ({
|
|
78
78
|
portals: { p1: { portal } },
|
|
79
|
-
});
|
|
79
|
+
}));
|
|
80
80
|
|
|
81
81
|
const ctx: any = {
|
|
82
82
|
state,
|
|
83
83
|
dispatch(update) {
|
|
84
|
-
|
|
84
|
+
state.setState(update(state.getState()));
|
|
85
85
|
},
|
|
86
86
|
};
|
|
87
87
|
|
|
88
88
|
showPortal(ctx, 'test', newPortal);
|
|
89
|
-
const { portals } =
|
|
89
|
+
const { portals } = ctx.state.getState();
|
|
90
90
|
expect(portals).not.toBeNull();
|
|
91
91
|
expect(portals.test).not.toBeNull();
|
|
92
92
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import create from 'zustand';
|
|
2
2
|
import { readState, dispatch } from './state';
|
|
3
3
|
|
|
4
4
|
function createMockContainer(initialState = {}) {
|
|
5
|
-
const state =
|
|
5
|
+
const state = create(() => initialState);
|
|
6
6
|
return {
|
|
7
7
|
context: {
|
|
8
8
|
on: jest.fn(),
|
|
@@ -11,7 +11,7 @@ function createMockContainer(initialState = {}) {
|
|
|
11
11
|
defineActions() {},
|
|
12
12
|
state,
|
|
13
13
|
read() {
|
|
14
|
-
return
|
|
14
|
+
return state.getState();
|
|
15
15
|
},
|
|
16
16
|
} as any,
|
|
17
17
|
};
|
package/src/actions/state.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { swap, deref } from '@dbeining/react-atom';
|
|
2
1
|
import { isSame } from '../utils';
|
|
3
2
|
import { GlobalState, GlobalStateContext } from '../types';
|
|
4
3
|
|
|
5
|
-
function onlyChangedState(oldState: GlobalState, newState: GlobalState) {
|
|
6
|
-
return isSame(oldState, newState) ? oldState : newState;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
4
|
export function dispatch(ctx: GlobalStateContext, update: (state: GlobalState) => GlobalState) {
|
|
10
|
-
|
|
5
|
+
const oldState = ctx.state.getState();
|
|
6
|
+
const newState = update(oldState);
|
|
7
|
+
|
|
8
|
+
if (!isSame(oldState, newState)) {
|
|
9
|
+
ctx.state.setState(newState);
|
|
10
|
+
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function readState<S>(ctx: GlobalStateContext, read: (state: GlobalState) => S) {
|
|
14
|
-
|
|
15
|
-
return read(state);
|
|
14
|
+
return read(ctx.state.getState());
|
|
16
15
|
}
|
|
@@ -3,10 +3,14 @@ import { createRoot } from 'react-dom/client';
|
|
|
3
3
|
import { act } from 'react-dom/test-utils';
|
|
4
4
|
import { ForeignComponentContainer } from './ForeignComponentContainer';
|
|
5
5
|
|
|
6
|
+
function resolveAfter(time = 5) {
|
|
7
|
+
return new Promise<void>(resolve => setTimeout(resolve, time));
|
|
8
|
+
}
|
|
9
|
+
|
|
6
10
|
async function render(element: any, container: Element) {
|
|
7
11
|
const root = createRoot(container);
|
|
8
12
|
root.render(element);
|
|
9
|
-
await act(
|
|
13
|
+
await act(resolveAfter);
|
|
10
14
|
return root;
|
|
11
15
|
}
|
|
12
16
|
|
|
@@ -63,7 +67,7 @@ describe('ForeignComponentContainer component', () => {
|
|
|
63
67
|
innerProps={{ a: 'foo' }}
|
|
64
68
|
/>,
|
|
65
69
|
);
|
|
66
|
-
await act(
|
|
70
|
+
await act(resolveAfter);
|
|
67
71
|
expect(update).toHaveBeenCalled();
|
|
68
72
|
container.remove();
|
|
69
73
|
});
|
|
@@ -74,7 +78,7 @@ describe('ForeignComponentContainer component', () => {
|
|
|
74
78
|
ForeignComponentContainer.prototype.componentDidMount = function () {
|
|
75
79
|
componentDidMount.call(this);
|
|
76
80
|
this.previous = {
|
|
77
|
-
removeEventListener() {},
|
|
81
|
+
removeEventListener() { },
|
|
78
82
|
};
|
|
79
83
|
};
|
|
80
84
|
const mount = jest.fn();
|
|
@@ -101,7 +105,7 @@ describe('ForeignComponentContainer component', () => {
|
|
|
101
105
|
innerProps={{ a: 'foo' }}
|
|
102
106
|
/>,
|
|
103
107
|
);
|
|
104
|
-
await act(
|
|
108
|
+
await act(resolveAfter);
|
|
105
109
|
expect(update).not.toHaveBeenCalled();
|
|
106
110
|
expect(unmount).toHaveBeenCalled();
|
|
107
111
|
container.remove();
|
|
@@ -121,7 +125,7 @@ describe('ForeignComponentContainer component', () => {
|
|
|
121
125
|
const node = document.querySelector('[data-portal-id=foo]');
|
|
122
126
|
expect(renderHtmlExtension).not.toHaveBeenCalled();
|
|
123
127
|
node.dispatchEvent(new CustomEvent('render-html', { detail: {} }));
|
|
124
|
-
await act(
|
|
128
|
+
await act(resolveAfter);
|
|
125
129
|
expect(renderHtmlExtension).toHaveBeenCalled();
|
|
126
130
|
container.remove();
|
|
127
131
|
});
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import create from 'zustand';
|
|
2
3
|
import { Mediator } from './Mediator';
|
|
3
|
-
import { Atom, swap, deref } from '@dbeining/react-atom';
|
|
4
4
|
import { mount } from 'enzyme';
|
|
5
5
|
import { StateContext } from '../state';
|
|
6
6
|
import { PiletMetadata } from '../types';
|
|
7
7
|
|
|
8
8
|
function createMockContainer() {
|
|
9
|
-
const state =
|
|
9
|
+
const state = create(() => ({
|
|
10
10
|
app: {
|
|
11
11
|
layout: 'tablet',
|
|
12
12
|
loading: false,
|
|
13
13
|
error: undefined,
|
|
14
14
|
},
|
|
15
|
-
});
|
|
15
|
+
}));
|
|
16
16
|
return {
|
|
17
17
|
context: {
|
|
18
18
|
on: jest.fn(),
|
|
@@ -20,21 +20,22 @@ function createMockContainer() {
|
|
|
20
20
|
emit: jest.fn(),
|
|
21
21
|
state,
|
|
22
22
|
dispatch(update) {
|
|
23
|
-
|
|
23
|
+
state.setState(update(state.getState()));
|
|
24
24
|
},
|
|
25
25
|
readState(select) {
|
|
26
|
-
return select(
|
|
26
|
+
return select(state.getState());
|
|
27
27
|
},
|
|
28
28
|
initialize(loading, error, modules) {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const s = state.getState();
|
|
30
|
+
state.setState({
|
|
31
|
+
...s,
|
|
31
32
|
app: {
|
|
32
|
-
...
|
|
33
|
+
...s.app,
|
|
33
34
|
error,
|
|
34
35
|
loading,
|
|
35
36
|
},
|
|
36
37
|
modules,
|
|
37
|
-
})
|
|
38
|
+
} as any);
|
|
38
39
|
},
|
|
39
40
|
} as any,
|
|
40
41
|
};
|
|
@@ -54,6 +55,6 @@ describe('Component Mediator', () => {
|
|
|
54
55
|
<Mediator options={options} />
|
|
55
56
|
</StateContext.Provider>,
|
|
56
57
|
);
|
|
57
|
-
expect(
|
|
58
|
+
expect(context.state.getState().app.layout).toEqual('tablet');
|
|
58
59
|
});
|
|
59
60
|
});
|
|
@@ -3,7 +3,7 @@ import * as hooks from '../hooks';
|
|
|
3
3
|
import { MemoryRouter } from 'react-router';
|
|
4
4
|
import { mount } from 'enzyme';
|
|
5
5
|
import { PiralRoutes } from './PiralRoutes';
|
|
6
|
-
import { DefaultRouteSwitch } from '../defaults';
|
|
6
|
+
import { DefaultRouteSwitch } from '../defaults/DefaultRouteSwitch_v5';
|
|
7
7
|
|
|
8
8
|
const mountWithRouter = (node, url = '/') =>
|
|
9
9
|
mount(
|
|
@@ -14,21 +14,28 @@ const mountWithRouter = (node, url = '/') =>
|
|
|
14
14
|
|
|
15
15
|
jest.mock('../hooks');
|
|
16
16
|
|
|
17
|
-
(hooks as any).
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
(hooks as any).useRoutes = () => [
|
|
18
|
+
{
|
|
19
|
+
path: '/',
|
|
20
|
+
Component: StubHome,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
path: '/custom',
|
|
24
|
+
Component: StubCustomPage,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
path: '/foo',
|
|
28
|
+
Component: StubFooPage,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
path: '/foo/bar',
|
|
32
|
+
Component: StubFooBarPage,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
path: '/bar',
|
|
36
|
+
Component: StubBarPage,
|
|
37
|
+
},
|
|
38
|
+
];
|
|
32
39
|
|
|
33
40
|
const StubHome: React.FC = (props) => <div />;
|
|
34
41
|
StubHome.displayName = 'StubHome';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { RouteComponentProps, SwitchProps } from 'react-router';
|
|
3
|
-
import {
|
|
3
|
+
import { useRoutes } from '../hooks';
|
|
4
4
|
import { RouteSwitchProps } from '../types';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -21,13 +21,7 @@ export interface RoutesProps extends SwitchProps {
|
|
|
21
21
|
* The component for defining the exclusive routes to be used.
|
|
22
22
|
*/
|
|
23
23
|
export const PiralRoutes: React.FC<RoutesProps> = ({ NotFound, RouteSwitch, ...props }) => {
|
|
24
|
-
const
|
|
25
|
-
const pages = useGlobalState((s) => s.registry.pages);
|
|
26
|
-
const paths = [];
|
|
27
|
-
|
|
28
|
-
Object.keys(routes).map((path) => paths.push({ path, Component: routes[path] }));
|
|
29
|
-
Object.keys(pages).map((path) => paths.push({ path, Component: pages[path].component }));
|
|
30
|
-
|
|
24
|
+
const paths = useRoutes();
|
|
31
25
|
return <RouteSwitch NotFound={NotFound} paths={paths} {...props} />;
|
|
32
26
|
};
|
|
33
27
|
PiralRoutes.displayName = 'Routes';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { __RouterContext } from 'react-router';
|
|
3
2
|
import { PortalRenderer } from './PortalRenderer';
|
|
4
3
|
import { ForeignComponentContainer } from './ForeignComponentContainer';
|
|
5
4
|
import { useGlobalStateContext } from '../hooks';
|
|
6
5
|
import { convertComponent, none } from '../utils';
|
|
6
|
+
import { useRouterContext } from '../../app.codegen';
|
|
7
7
|
import type { AnyComponent, ComponentConverters, ForeignComponent, PiletApi, BaseComponentProps } from '../types';
|
|
8
8
|
|
|
9
9
|
// this is an arbitrary start number to have 6 digits
|
|
@@ -32,7 +32,7 @@ function wrapForeignComponent<T>(
|
|
|
32
32
|
) {
|
|
33
33
|
return React.memo((props: T) => {
|
|
34
34
|
const { state, readState, destroyPortal } = useGlobalStateContext();
|
|
35
|
-
const router =
|
|
35
|
+
const router = useRouterContext();
|
|
36
36
|
const id = React.useMemo(() => (portalIdBase++).toString(26), none);
|
|
37
37
|
const context = React.useMemo(() => ({ router, state, readState }), [router, state]);
|
|
38
38
|
const innerProps = React.useMemo(() => ({ ...props, ...captured }), [props]);
|
package/src/createInstance.tsx
CHANGED
|
@@ -50,7 +50,7 @@ export function createInstance(config: PiralInstanceOptions = {}): PiralInstance
|
|
|
50
50
|
const createApi = apiFactory(context, usedPlugins);
|
|
51
51
|
const root = createApi({
|
|
52
52
|
name: '_',
|
|
53
|
-
version:
|
|
53
|
+
version: '0',
|
|
54
54
|
spec: 'v0',
|
|
55
55
|
basePath: '',
|
|
56
56
|
link: '',
|
package/src/debugger.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { addChangeHandler } from '@dbeining/react-atom';
|
|
2
1
|
import { LoadPiletsOptions } from 'piral-base';
|
|
3
2
|
import { installPiralDebug, DebuggerExtensionOptions } from 'piral-debug-utils';
|
|
4
3
|
import { GlobalStateContext } from './types';
|
|
@@ -42,6 +41,9 @@ export function integrateDebugger(
|
|
|
42
41
|
getGlobalState() {
|
|
43
42
|
return context.readState((s) => s);
|
|
44
43
|
},
|
|
44
|
+
navigate(path, state) {
|
|
45
|
+
return context.navigate(path, state);
|
|
46
|
+
},
|
|
45
47
|
getPilets() {
|
|
46
48
|
return context.readState((s) => s.modules);
|
|
47
49
|
},
|
|
@@ -65,7 +67,7 @@ export function integrateDebugger(
|
|
|
65
67
|
},
|
|
66
68
|
}));
|
|
67
69
|
|
|
68
|
-
|
|
70
|
+
context.state.subscribe((current, previous) => {
|
|
69
71
|
const pilets = current.modules !== previous.modules;
|
|
70
72
|
const pages = current.registry.pages !== previous.registry.pages || current.routes !== previous.routes;
|
|
71
73
|
const extensions = current.registry.extensions !== previous.registry.extensions;
|