@expressive/react 0.20.0 → 0.21.0
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/index.esm.js +11 -30
- package/lib/index.js +11 -30
- package/package.json +2 -2
package/lib/index.esm.js
CHANGED
|
@@ -48,7 +48,7 @@ const useModel = (adapter) => {
|
|
|
48
48
|
return hook.render;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
const Oops
|
|
51
|
+
const Oops = issues({
|
|
52
52
|
BadProps: () => `Provider expects either a render function, 'get' or 'has' props.`
|
|
53
53
|
});
|
|
54
54
|
function Consumer(props) {
|
|
@@ -59,44 +59,25 @@ function Consumer(props) {
|
|
|
59
59
|
if (typeof callback == "function")
|
|
60
60
|
callback(Type.get(!!has));
|
|
61
61
|
else
|
|
62
|
-
throw Oops
|
|
62
|
+
throw Oops.BadProps();
|
|
63
63
|
return null;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
const Oops = issues({
|
|
67
|
-
NoType: () => "Provider 'for' prop must be Model, typeof Model or a collection of them."
|
|
68
|
-
});
|
|
69
66
|
function Provider(props) {
|
|
70
|
-
let { for:
|
|
71
|
-
const init = new Set();
|
|
67
|
+
let { for: included, use: assign } = props;
|
|
72
68
|
const ambient = useLookup();
|
|
73
|
-
const context = useMemo(() =>
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (typeof include == "function" || include instanceof Model)
|
|
79
|
-
include = { [0]: include };
|
|
80
|
-
for (const key in include) {
|
|
81
|
-
const instance = context.add(include[key], key);
|
|
82
|
-
init.add(instance);
|
|
83
|
-
if (assign)
|
|
69
|
+
const context = useMemo(() => ambient.push(), []);
|
|
70
|
+
if (typeof included == "function" || included instanceof Model)
|
|
71
|
+
included = { [0]: included };
|
|
72
|
+
context.include(included).forEach((explicit, model) => {
|
|
73
|
+
if (assign && explicit)
|
|
84
74
|
for (const K in assign)
|
|
85
|
-
if (K in
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
for (const model of init) {
|
|
89
|
-
const control = Control.for(model, true);
|
|
75
|
+
if (K in model)
|
|
76
|
+
model[K] = assign[K];
|
|
90
77
|
const pending = Pending.get(model);
|
|
91
78
|
if (pending)
|
|
92
79
|
pending.forEach(cb => cb(context));
|
|
93
|
-
|
|
94
|
-
if (value instanceof Model && Control.for(value).parent === model) {
|
|
95
|
-
context.add(value);
|
|
96
|
-
init.add(value);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
80
|
+
});
|
|
100
81
|
useLayoutEffect(() => () => context.pop(), []);
|
|
101
82
|
return (React.createElement(LookupContext.Provider, { value: context }, props.fallback === false
|
|
102
83
|
? props.children
|
package/lib/index.js
CHANGED
|
@@ -56,7 +56,7 @@ const useModel = (adapter) => {
|
|
|
56
56
|
return hook.render;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
const Oops
|
|
59
|
+
const Oops = mvc.issues({
|
|
60
60
|
BadProps: () => `Provider expects either a render function, 'get' or 'has' props.`
|
|
61
61
|
});
|
|
62
62
|
function Consumer(props) {
|
|
@@ -67,44 +67,25 @@ function Consumer(props) {
|
|
|
67
67
|
if (typeof callback == "function")
|
|
68
68
|
callback(Type.get(!!has));
|
|
69
69
|
else
|
|
70
|
-
throw Oops
|
|
70
|
+
throw Oops.BadProps();
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
const Oops = mvc.issues({
|
|
75
|
-
NoType: () => "Provider 'for' prop must be Model, typeof Model or a collection of them."
|
|
76
|
-
});
|
|
77
74
|
function Provider(props) {
|
|
78
|
-
let { for:
|
|
79
|
-
const init = new Set();
|
|
75
|
+
let { for: included, use: assign } = props;
|
|
80
76
|
const ambient = useLookup();
|
|
81
|
-
const context = React.useMemo(() =>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (typeof include == "function" || include instanceof mvc.Model)
|
|
87
|
-
include = { [0]: include };
|
|
88
|
-
for (const key in include) {
|
|
89
|
-
const instance = context.add(include[key], key);
|
|
90
|
-
init.add(instance);
|
|
91
|
-
if (assign)
|
|
77
|
+
const context = React.useMemo(() => ambient.push(), []);
|
|
78
|
+
if (typeof included == "function" || included instanceof mvc.Model)
|
|
79
|
+
included = { [0]: included };
|
|
80
|
+
context.include(included).forEach((explicit, model) => {
|
|
81
|
+
if (assign && explicit)
|
|
92
82
|
for (const K in assign)
|
|
93
|
-
if (K in
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
for (const model of init) {
|
|
97
|
-
const control = mvc.Control.for(model, true);
|
|
83
|
+
if (K in model)
|
|
84
|
+
model[K] = assign[K];
|
|
98
85
|
const pending = Pending.get(model);
|
|
99
86
|
if (pending)
|
|
100
87
|
pending.forEach(cb => cb(context));
|
|
101
|
-
|
|
102
|
-
if (value instanceof mvc.Model && mvc.Control.for(value).parent === model) {
|
|
103
|
-
context.add(value);
|
|
104
|
-
init.add(value);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
88
|
+
});
|
|
108
89
|
React.useLayoutEffect(() => () => context.pop(), []);
|
|
109
90
|
return (React__default["default"].createElement(LookupContext.Provider, { value: context }, props.fallback === false
|
|
110
91
|
? props.children
|
package/package.json
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"postversion": "git push & npm publish"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@expressive/mvc": "^0.
|
|
33
|
+
"@expressive/mvc": "^0.21.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": ">=16.8.0 <19.0.0"
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"react": ">=17.0.2",
|
|
43
43
|
"react-test-renderer": "^17.0.2"
|
|
44
44
|
},
|
|
45
|
-
"version": "0.
|
|
45
|
+
"version": "0.21.0"
|
|
46
46
|
}
|