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.
Files changed (55) hide show
  1. package/esm/actions/state.js +6 -7
  2. package/esm/actions/state.js.map +1 -1
  3. package/esm/debugger.js +1 -2
  4. package/esm/debugger.js.map +1 -1
  5. package/esm/hooks/globalState.js +2 -9
  6. package/esm/hooks/globalState.js.map +1 -1
  7. package/esm/state/createActions.d.ts +2 -2
  8. package/esm/state/createActions.js.map +1 -1
  9. package/esm/state/createGlobalState.d.ts +1 -2
  10. package/esm/state/createGlobalState.js +2 -2
  11. package/esm/state/createGlobalState.js.map +1 -1
  12. package/esm/types/state.d.ts +2 -3
  13. package/lib/actions/state.js +6 -7
  14. package/lib/actions/state.js.map +1 -1
  15. package/lib/debugger.js +1 -2
  16. package/lib/debugger.js.map +1 -1
  17. package/lib/hooks/globalState.js +2 -9
  18. package/lib/hooks/globalState.js.map +1 -1
  19. package/lib/state/createActions.d.ts +2 -2
  20. package/lib/state/createActions.js.map +1 -1
  21. package/lib/state/createGlobalState.d.ts +1 -2
  22. package/lib/state/createGlobalState.js +2 -2
  23. package/lib/state/createGlobalState.js.map +1 -1
  24. package/lib/types/state.d.ts +2 -3
  25. package/package.json +7 -13
  26. package/src/RootListener.test.tsx +5 -7
  27. package/src/actions/app.test.ts +32 -32
  28. package/src/actions/components.test.ts +10 -10
  29. package/src/actions/data.test.ts +49 -49
  30. package/src/actions/define.test.ts +2 -2
  31. package/src/actions/portal.test.ts +17 -17
  32. package/src/actions/state.test.ts +3 -3
  33. package/src/actions/state.ts +7 -8
  34. package/src/components/ForeignComponentContainer.test.tsx +14 -13
  35. package/src/components/Mediator.test.tsx +11 -10
  36. package/src/debugger.ts +1 -2
  37. package/src/helpers.test.tsx +9 -8
  38. package/src/hooks/globalState.ts +2 -11
  39. package/src/hooks/setter.test.ts +3 -4
  40. package/src/modules/element-server.test.ts +4 -4
  41. package/src/modules/element.test.ts +6 -6
  42. package/src/setters/SetComponent.test.tsx +7 -6
  43. package/src/setters/SetError.test.tsx +7 -6
  44. package/src/setters/SetErrors.test.tsx +7 -6
  45. package/src/setters/SetLayout.test.tsx +7 -6
  46. package/src/setters/SetProvider.test.tsx +7 -6
  47. package/src/setters/SetRedirect.test.tsx +7 -6
  48. package/src/setters/SetRoute.test.tsx +7 -6
  49. package/src/state/createActions.ts +3 -3
  50. package/src/state/createGlobalState.test.ts +9 -11
  51. package/src/state/createGlobalState.ts +2 -2
  52. package/src/state/withApi.test.tsx +5 -5
  53. package/src/types/state.ts +2 -3
  54. package/src/hooks/globalState-server.test.ts +0 -41
  55. package/src/hooks/globalState.test.ts +0 -47
@@ -1,20 +1,20 @@
1
- import { Atom, deref } from '@dbeining/react-atom';
1
+ import create from 'zustand';
2
2
  import { createListener } from 'piral-base';
3
3
  import { registerExtension, registerPage, unregisterExtension, unregisterPage } from './components';
4
4
  import { createActions } from '../state';
5
5
 
6
6
  describe('Components Actions Module', () => {
7
7
  it('registerExtension and unregisterExtension', () => {
8
- const state = Atom.of({
8
+ const state: any = create(() => ({
9
9
  foo: 5,
10
10
  registry: {
11
11
  foo: 5,
12
12
  extensions: {},
13
13
  },
14
- });
14
+ }));
15
15
  const ctx = createActions(state, createListener({}));
16
16
  registerExtension(ctx, 'foo', 10 as any);
17
- expect(deref(state)).toEqual({
17
+ expect(state.getState()).toEqual({
18
18
  foo: 5,
19
19
  registry: {
20
20
  foo: 5,
@@ -23,8 +23,8 @@ describe('Components Actions Module', () => {
23
23
  },
24
24
  },
25
25
  });
26
- unregisterExtension(ctx, 'foo');
27
- expect(deref(state)).toEqual({
26
+ unregisterExtension(ctx, 'foo', undefined);
27
+ expect(state.getState()).toEqual({
28
28
  foo: 5,
29
29
  registry: {
30
30
  foo: 5,
@@ -36,16 +36,16 @@ describe('Components Actions Module', () => {
36
36
  });
37
37
 
38
38
  it('registerPage and unregisterPage', () => {
39
- const state = Atom.of({
39
+ const state: any = create(() => ({
40
40
  foo: 5,
41
41
  registry: {
42
42
  foo: 5,
43
43
  pages: {},
44
44
  },
45
- });
45
+ }));
46
46
  const ctx = createActions(state, createListener({}));
47
47
  registerPage(ctx, 'foo', 10 as any);
48
- expect(deref(state)).toEqual({
48
+ expect(state.getState()).toEqual({
49
49
  foo: 5,
50
50
  registry: {
51
51
  foo: 5,
@@ -55,7 +55,7 @@ describe('Components Actions Module', () => {
55
55
  },
56
56
  });
57
57
  unregisterPage(ctx, 'foo');
58
- expect(deref(state)).toEqual({
58
+ expect(state.getState()).toEqual({
59
59
  foo: 5,
60
60
  registry: {
61
61
  foo: 5,
@@ -1,22 +1,22 @@
1
- import { Atom, deref, swap } from '@dbeining/react-atom';
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 = Atom.of({
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
- swap(state, update);
16
+ state.setState(update(state.getState()));
17
17
  },
18
18
  readState(select) {
19
- return select(deref(state));
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 = Atom.of({
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
- swap(state, update);
38
+ state.setState(update(state.getState()));
39
39
  },
40
40
  readState(select) {
41
- return select(deref(state));
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 = Atom.of({
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
- swap(state, update);
59
+ state.setState(update(state.getState()));
60
60
  },
61
61
  readState(select) {
62
- return select(deref(state));
62
+ return select(state.getState());
63
63
  },
64
64
  };
65
65
  resetData(ctx);
66
- expect(deref(state)).toEqual({
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 = Atom.of({
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
- swap(state, update);
83
+ state.setState(update(state.getState()));
84
84
  },
85
85
  readState(select) {
86
- return select(deref(state));
86
+ return select(state.getState());
87
87
  },
88
88
  });
89
- writeDataItem(ctx, 'fi', 0);
90
- expect(deref(state)).toEqual({
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 = Atom.of({
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
- swap(state, update);
116
+ state.setState(update(state.getState()));
117
117
  },
118
118
  readState(select) {
119
- return select(deref(state));
119
+ return select(state.getState());
120
120
  },
121
121
  });
122
- writeDataItem(ctx, 'bar', 0);
123
- expect(deref(state)).toEqual({
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 = Atom.of({
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
- swap(state, update);
148
+ state.setState(update(state.getState()));
149
149
  },
150
150
  readState(select) {
151
- return select(deref(state));
151
+ return select(state.getState());
152
152
  },
153
153
  });
154
- writeDataItem(ctx, 'bar', null);
155
- expect(deref(state)).toEqual({
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 = Atom.of({
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
- swap(state, update);
173
+ state.setState(update(state.getState()));
174
174
  },
175
175
  readState(select) {
176
- return select(deref(state));
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 = Atom.of({
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
- swap(state, update);
197
+ state.setState(update(state.getState()));
198
198
  },
199
199
  readState(select) {
200
- return select(deref(state));
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(deref(state).data.bar.value).toBe(10);
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 = Atom.of({
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
- swap(state, update);
222
+ state.setState(update(state.getState()));
223
223
  },
224
224
  readState(select) {
225
- return select(deref(state));
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(deref(state).data.bar.value).toBe(5);
230
+ expect(state.getState().data.bar.value).toBe(5);
231
231
  });
232
232
  });
@@ -1,8 +1,8 @@
1
- import { Atom } from '@dbeining/react-atom';
1
+ import create from 'zustand';
2
2
  import { defineAction, defineActions } from './define';
3
3
 
4
4
  function createMockContainer(initialState = {}) {
5
- const state = Atom.of(initialState);
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 { Atom, swap, deref } from '@dbeining/react-atom';
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 = Atom.of({
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
- swap(state, update);
17
+ state.setState(update(state.getState()));
18
18
  },
19
19
  };
20
20
 
21
21
  destroyPortal(ctx, 'test');
22
- const { portals } = deref(ctx.state);
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 = Atom.of({
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
- swap(state, update);
39
+ state.setState(update(state.getState()));
40
40
  },
41
41
  };
42
42
 
43
43
  hidePortal(ctx, 'test', newPortal);
44
- const { portals } = deref(ctx.state);
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 = Atom.of({
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
- swap(state, update);
62
+ state.setState(update(state.getState()));
63
63
  },
64
64
  };
65
65
 
66
66
  updatePortal(ctx, 'test', current, next);
67
- const { portals } = deref(ctx.state);
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 = Atom.of({
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
- swap(state, update);
84
+ state.setState(update(state.getState()));
85
85
  },
86
86
  };
87
87
 
88
88
  showPortal(ctx, 'test', newPortal);
89
- const { portals } = deref(ctx.state);
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 { Atom, deref } from '@dbeining/react-atom';
1
+ import create from 'zustand';
2
2
  import { readState, dispatch } from './state';
3
3
 
4
4
  function createMockContainer(initialState = {}) {
5
- const state = Atom.of(initialState);
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 deref(state);
14
+ return state.getState();
15
15
  },
16
16
  } as any,
17
17
  };
@@ -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
- swap(ctx.state, oldState => onlyChangedState(oldState, update(oldState)));
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
- const state = deref(ctx.state);
15
- return read(state);
14
+ return read(ctx.state.getState());
16
15
  }
@@ -1,17 +1,16 @@
1
1
  import * as React from 'react';
2
- import { createRoot } from 'react-dom/client';
2
+ import { render as renderDom } from 'react-dom';
3
3
  import { act } from 'react-dom/test-utils';
4
4
  import { ForeignComponentContainer } from './ForeignComponentContainer';
5
5
 
6
6
  function resolveAfter(time = 5) {
7
- return new Promise<void>(resolve => setTimeout(resolve, time));
7
+ return new Promise<void>((resolve) => setTimeout(resolve, time));
8
8
  }
9
9
 
10
10
  async function render(element: any, container: Element) {
11
- const root = createRoot(container);
12
- root.render(element);
11
+ renderDom(element, container);
13
12
  await act(resolveAfter);
14
- return root;
13
+ return () => renderDom(<div />, container);
15
14
  }
16
15
 
17
16
  describe('ForeignComponentContainer component', () => {
@@ -32,13 +31,13 @@ describe('ForeignComponentContainer component', () => {
32
31
  const mount = jest.fn();
33
32
  const unmount = jest.fn();
34
33
  const component = { mount, unmount };
35
- const root = await render(
34
+ const doUnmount = await render(
36
35
  <ForeignComponentContainer $component={component} $context={undefined} $portalId="foo" innerProps={{}} />,
37
36
  container,
38
37
  );
39
38
  expect(mount).toHaveBeenCalled();
40
39
  expect(unmount).not.toHaveBeenCalled();
41
- root.unmount();
40
+ doUnmount();
42
41
  expect(unmount).toHaveBeenCalled();
43
42
  container.remove();
44
43
  });
@@ -48,7 +47,7 @@ describe('ForeignComponentContainer component', () => {
48
47
  const mount = jest.fn();
49
48
  const update = jest.fn();
50
49
  const component = { mount, update };
51
- const root = await render(
50
+ await render(
52
51
  <ForeignComponentContainer
53
52
  $component={component}
54
53
  $context={undefined}
@@ -59,13 +58,14 @@ describe('ForeignComponentContainer component', () => {
59
58
  );
60
59
  expect(mount).toHaveBeenCalled();
61
60
  expect(update).not.toHaveBeenCalled();
62
- root.render(
61
+ await render(
63
62
  <ForeignComponentContainer
64
63
  $component={component}
65
64
  $context={undefined}
66
65
  $portalId="foo"
67
66
  innerProps={{ a: 'foo' }}
68
67
  />,
68
+ container,
69
69
  );
70
70
  await act(resolveAfter);
71
71
  expect(update).toHaveBeenCalled();
@@ -78,14 +78,14 @@ describe('ForeignComponentContainer component', () => {
78
78
  ForeignComponentContainer.prototype.componentDidMount = function () {
79
79
  componentDidMount.call(this);
80
80
  this.previous = {
81
- removeEventListener() { },
81
+ removeEventListener() {},
82
82
  };
83
83
  };
84
84
  const mount = jest.fn();
85
85
  const update = jest.fn();
86
86
  const unmount = jest.fn();
87
87
  const component = { mount, update, unmount };
88
- const root = await render(
88
+ await render(
89
89
  <ForeignComponentContainer
90
90
  $component={component}
91
91
  $context={undefined}
@@ -97,13 +97,14 @@ describe('ForeignComponentContainer component', () => {
97
97
  expect(mount).toHaveBeenCalled();
98
98
  expect(unmount).not.toHaveBeenCalled();
99
99
  expect(update).not.toHaveBeenCalled();
100
- root.render(
100
+ await render(
101
101
  <ForeignComponentContainer
102
102
  $component={component}
103
103
  $context={undefined}
104
104
  $portalId="foo"
105
105
  innerProps={{ a: 'foo' }}
106
106
  />,
107
+ container,
107
108
  );
108
109
  await act(resolveAfter);
109
110
  expect(update).not.toHaveBeenCalled();
@@ -124,7 +125,7 @@ describe('ForeignComponentContainer component', () => {
124
125
  expect(mount).toHaveBeenCalled();
125
126
  const node = document.querySelector('[data-portal-id=foo]');
126
127
  expect(renderHtmlExtension).not.toHaveBeenCalled();
127
- node.dispatchEvent(new CustomEvent('render-html', { detail: {} }));
128
+ node?.dispatchEvent(new CustomEvent('render-html', { detail: {} }));
128
129
  await act(resolveAfter);
129
130
  expect(renderHtmlExtension).toHaveBeenCalled();
130
131
  container.remove();
@@ -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 = Atom.of({
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
- swap(state, update);
23
+ state.setState(update(state.getState()));
24
24
  },
25
25
  readState(select) {
26
- return select(deref(state));
26
+ return select(state.getState());
27
27
  },
28
28
  initialize(loading, error, modules) {
29
- swap(state, (state) => ({
30
- ...state,
29
+ const s = state.getState();
30
+ state.setState({
31
+ ...s,
31
32
  app: {
32
- ...state.app,
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(deref<any>(context.state).app.layout).toEqual('tablet');
58
+ expect(context.state.getState().app.layout).toEqual('tablet');
58
59
  });
59
60
  });
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';
@@ -68,7 +67,7 @@ export function integrateDebugger(
68
67
  },
69
68
  }));
70
69
 
71
- addChangeHandler(context.state, 'debugging', ({ previous, current }) => {
70
+ context.state.subscribe((current, previous) => {
72
71
  const pilets = current.modules !== previous.modules;
73
72
  const pages = current.registry.pages !== previous.registry.pages || current.routes !== previous.routes;
74
73
  const extensions = current.registry.extensions !== previous.registry.extensions;