piral-core 1.11.1-beta.efeabd1 → 1.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/actions/portal.js +1 -9
- package/lib/actions/portal.js.map +1 -1
- package/lib/actions/state.js +1 -1
- package/lib/actions/state.js.map +1 -1
- package/package.json +4 -4
- package/src/actions/portal.test.ts +0 -42
- package/src/actions/portal.ts +1 -16
- package/src/actions/state.test.ts +29 -0
- package/src/actions/state.ts +1 -1
package/lib/actions/portal.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { withoutKey, withKey, includeItem, excludeItem, replaceOrAddItem } from '../utils';
|
|
2
|
-
function getPortalContainer(portal) {
|
|
3
|
-
return portal.containerInfo;
|
|
4
|
-
}
|
|
5
2
|
export function destroyPortal(ctx, id) {
|
|
6
3
|
ctx.dispatch((state) => ({
|
|
7
4
|
...state,
|
|
@@ -14,15 +11,10 @@ export function hidePortal(ctx, id, entry) {
|
|
|
14
11
|
portals: withKey(state.portals, id, excludeItem(state.portals[id], entry)),
|
|
15
12
|
}));
|
|
16
13
|
}
|
|
17
|
-
function isSamePortal(current, candidate) {
|
|
18
|
-
const currentContainer = getPortalContainer(current);
|
|
19
|
-
const candidateContainer = getPortalContainer(candidate);
|
|
20
|
-
return candidate === current || (!!currentContainer && currentContainer === candidateContainer);
|
|
21
|
-
}
|
|
22
14
|
export function updatePortal(ctx, id, current, next) {
|
|
23
15
|
ctx.dispatch((state) => ({
|
|
24
16
|
...state,
|
|
25
|
-
portals: withKey(state.portals, id, replaceOrAddItem(state.portals[id], next, (m) =>
|
|
17
|
+
portals: withKey(state.portals, id, replaceOrAddItem(state.portals[id], next, (m) => m === current)),
|
|
26
18
|
}));
|
|
27
19
|
}
|
|
28
20
|
export function showPortal(ctx, id, entry) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portal.js","sourceRoot":"","sources":["../../src/actions/portal.ts"],"names":[],"mapp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,UAAU,CAAC,GAAuB,EAAE,EAAU,EAAE,KAAkB;IAChF,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACvB,GAAG,KAAK;QACR,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;KAC3E,CAAC,CAAC,CAAC;AACN,CAAC"}
|
package/lib/actions/state.js
CHANGED
|
@@ -2,7 +2,7 @@ import { isSame } from '../utils';
|
|
|
2
2
|
export function dispatch(ctx, update) {
|
|
3
3
|
const oldState = ctx.state.getState();
|
|
4
4
|
const newState = update(oldState);
|
|
5
|
-
if (!isSame(oldState, newState)) {
|
|
5
|
+
if (oldState.portals !== newState.portals || !isSame(oldState, newState)) {
|
|
6
6
|
ctx.state.setState(newState);
|
|
7
7
|
}
|
|
8
8
|
}
|
package/lib/actions/state.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,CAAC;
|
|
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,QAAQ,CAAC,OAAO,KAAK,QAAQ,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,CAAC;QACzE,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-core",
|
|
3
|
-
"version": "1.11.1
|
|
3
|
+
"version": "1.11.1",
|
|
4
4
|
"description": "The core library for creating a Piral instance.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"portal",
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"piral-base": "1.11.1
|
|
67
|
-
"piral-debug-utils": "1.11.1
|
|
66
|
+
"piral-base": "^1.11.1",
|
|
67
|
+
"piral-debug-utils": "^1.11.1",
|
|
68
68
|
"zustand": "^3.0.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"react-router-dom",
|
|
85
85
|
"tslib"
|
|
86
86
|
],
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "5a57b813ac5cae4e60fbb7c6cd0f5120135371dd"
|
|
88
88
|
}
|
|
@@ -70,48 +70,6 @@ describe('Piral-Core portal actions', () => {
|
|
|
70
70
|
expect(portals.test).not.toBeNull();
|
|
71
71
|
});
|
|
72
72
|
|
|
73
|
-
it('updatePortal replaces a portal with the same container', () => {
|
|
74
|
-
const children = React.createElement('div');
|
|
75
|
-
const container = {};
|
|
76
|
-
const stored = {
|
|
77
|
-
key: 'stored',
|
|
78
|
-
children: { children },
|
|
79
|
-
type: 'div',
|
|
80
|
-
props: null,
|
|
81
|
-
containerInfo: container,
|
|
82
|
-
} as unknown as React.ReactPortal & { containerInfo: unknown };
|
|
83
|
-
const current = {
|
|
84
|
-
key: 'current',
|
|
85
|
-
children: { children },
|
|
86
|
-
type: 'div',
|
|
87
|
-
props: null,
|
|
88
|
-
containerInfo: container,
|
|
89
|
-
} as unknown as React.ReactPortal & { containerInfo: unknown };
|
|
90
|
-
const next = {
|
|
91
|
-
key: 'next',
|
|
92
|
-
children: { children },
|
|
93
|
-
type: 'div',
|
|
94
|
-
props: null,
|
|
95
|
-
containerInfo: container,
|
|
96
|
-
} as unknown as React.ReactPortal & { containerInfo: unknown };
|
|
97
|
-
|
|
98
|
-
const state = create(() => ({
|
|
99
|
-
portals: { test: [stored] },
|
|
100
|
-
}));
|
|
101
|
-
|
|
102
|
-
const ctx: any = {
|
|
103
|
-
state,
|
|
104
|
-
dispatch(update) {
|
|
105
|
-
state.setState(update(state.getState()));
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
updatePortal(ctx, 'test', current, next);
|
|
110
|
-
const { portals } = ctx.state.getState();
|
|
111
|
-
expect(portals.test).toHaveLength(1);
|
|
112
|
-
expect(portals.test[0]).toBe(next);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
73
|
it('showPortal adds a portal', () => {
|
|
116
74
|
const children = React.createElement('div');
|
|
117
75
|
const newPortal: React.ReactPortal = { key: 'test', children: { children }, type: 'div', props: null };
|
package/src/actions/portal.ts
CHANGED
|
@@ -2,14 +2,6 @@ import { ReactPortal } from 'react';
|
|
|
2
2
|
import { withoutKey, withKey, includeItem, excludeItem, replaceOrAddItem } from '../utils';
|
|
3
3
|
import { GlobalStateContext } from '../types';
|
|
4
4
|
|
|
5
|
-
type PortalWithContainer = ReactPortal & {
|
|
6
|
-
containerInfo?: unknown;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
function getPortalContainer(portal: ReactPortal) {
|
|
10
|
-
return (portal as PortalWithContainer).containerInfo;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
5
|
export function destroyPortal(ctx: GlobalStateContext, id: string) {
|
|
14
6
|
ctx.dispatch((state) => ({
|
|
15
7
|
...state,
|
|
@@ -24,20 +16,13 @@ export function hidePortal(ctx: GlobalStateContext, id: string, entry: ReactPort
|
|
|
24
16
|
}));
|
|
25
17
|
}
|
|
26
18
|
|
|
27
|
-
function isSamePortal(current: ReactPortal, candidate: ReactPortal) {
|
|
28
|
-
const currentContainer = getPortalContainer(current);
|
|
29
|
-
const candidateContainer = getPortalContainer(candidate);
|
|
30
|
-
|
|
31
|
-
return candidate === current || (!!currentContainer && currentContainer === candidateContainer);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
19
|
export function updatePortal(ctx: GlobalStateContext, id: string, current: ReactPortal, next: ReactPortal) {
|
|
35
20
|
ctx.dispatch((state) => ({
|
|
36
21
|
...state,
|
|
37
22
|
portals: withKey(
|
|
38
23
|
state.portals,
|
|
39
24
|
id,
|
|
40
|
-
replaceOrAddItem(state.portals[id], next, (m) =>
|
|
25
|
+
replaceOrAddItem(state.portals[id], next, (m) => m === current),
|
|
41
26
|
),
|
|
42
27
|
}));
|
|
43
28
|
}
|
|
@@ -37,4 +37,33 @@ describe('Piral-Core state actions', () => {
|
|
|
37
37
|
}));
|
|
38
38
|
expect(context.read().test).toBe(11);
|
|
39
39
|
});
|
|
40
|
+
|
|
41
|
+
it('dispatch updates the portal state for new portal instances', () => {
|
|
42
|
+
const oldPortal = {
|
|
43
|
+
key: null,
|
|
44
|
+
children: 'content',
|
|
45
|
+
containerInfo: {},
|
|
46
|
+
implementation: null,
|
|
47
|
+
};
|
|
48
|
+
const newPortal = {
|
|
49
|
+
key: null,
|
|
50
|
+
children: 'content',
|
|
51
|
+
containerInfo: {},
|
|
52
|
+
implementation: null,
|
|
53
|
+
};
|
|
54
|
+
const { context } = createMockContainer({
|
|
55
|
+
portals: {
|
|
56
|
+
root: [oldPortal],
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
dispatch(context, (state: any) => ({
|
|
61
|
+
...state,
|
|
62
|
+
portals: {
|
|
63
|
+
root: [newPortal],
|
|
64
|
+
},
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
expect(context.read().portals.root[0]).toBe(newPortal);
|
|
68
|
+
});
|
|
40
69
|
});
|
package/src/actions/state.ts
CHANGED
|
@@ -5,7 +5,7 @@ export function dispatch(ctx: GlobalStateContext, update: (state: GlobalState) =
|
|
|
5
5
|
const oldState = ctx.state.getState();
|
|
6
6
|
const newState = update(oldState);
|
|
7
7
|
|
|
8
|
-
if (!isSame(oldState, newState)) {
|
|
8
|
+
if (oldState.portals !== newState.portals || !isSame(oldState, newState)) {
|
|
9
9
|
ctx.state.setState(newState);
|
|
10
10
|
}
|
|
11
11
|
}
|