@expressive/react 0.41.0 → 0.43.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/dist/index.d.ts +3 -3
- package/dist/index.js +22 -45
- package/dist/index.mjs +15 -38
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -50,12 +50,12 @@ declare namespace Provider {
|
|
|
50
50
|
type NormalProps<E, I = Instance<E>> = {
|
|
51
51
|
for: E;
|
|
52
52
|
children?: Node;
|
|
53
|
-
use?: Model.
|
|
53
|
+
use?: Model.Assign<I>;
|
|
54
54
|
};
|
|
55
55
|
type MultipleProps<T extends Item> = {
|
|
56
56
|
for: Multiple<T>;
|
|
57
57
|
children?: Node;
|
|
58
|
-
use?: Model.
|
|
58
|
+
use?: Model.Assign<Instance<T>>;
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
declare function Provider<T extends Provider.Item>(props: Provider.Props<T>): Provider.Element;
|
|
@@ -100,7 +100,7 @@ declare module '@expressive/mvc' {
|
|
|
100
100
|
*/
|
|
101
101
|
function as<T extends Model, P = {}>(this: Model.New<T>, render: (using: T & P) => React.ReactNode): Component<T, P & Model.Values<T>>;
|
|
102
102
|
/** Fetch instance of this class from context. */
|
|
103
|
-
function get<T extends Model>(this: Model.Type<T>,
|
|
103
|
+
function get<T extends Model>(this: Model.Type<T>, passive?: true): T;
|
|
104
104
|
/** Fetch instance of this class optionally. May be undefined, but will never subscribe. */
|
|
105
105
|
function get<T extends Model>(this: Model.Type<T>, required: boolean): T | undefined;
|
|
106
106
|
function get<T extends Model, R>(this: Model.Type<T>, factory: get.Factory<T, Promise<R> | R>): NoVoid<R>;
|
package/dist/index.js
CHANGED
|
@@ -21,18 +21,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
Consumer: () => Consumer,
|
|
24
|
-
Model: () =>
|
|
24
|
+
Model: () => import_mvc2.Model,
|
|
25
25
|
Provider: () => Provider,
|
|
26
|
-
add: () =>
|
|
27
|
-
default: () =>
|
|
28
|
-
get: () =>
|
|
29
|
-
has: () =>
|
|
30
|
-
ref: () =>
|
|
31
|
-
set: () =>
|
|
32
|
-
use: () =>
|
|
26
|
+
add: () => import_mvc3.add,
|
|
27
|
+
default: () => import_mvc2.Model,
|
|
28
|
+
get: () => import_mvc3.get,
|
|
29
|
+
has: () => import_mvc3.has,
|
|
30
|
+
ref: () => import_mvc3.ref,
|
|
31
|
+
set: () => import_mvc3.set,
|
|
32
|
+
use: () => import_mvc3.use
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(src_exports);
|
|
35
|
-
var
|
|
35
|
+
var import_mvc2 = require("@expressive/mvc");
|
|
36
36
|
|
|
37
37
|
// src/component.ts
|
|
38
38
|
function createComponent(render) {
|
|
@@ -80,37 +80,23 @@ function setContext(model, context) {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
// src/useLocal.ts
|
|
83
|
-
var import_mvc2 = require("@expressive/mvc");
|
|
84
|
-
var PENDING = /* @__PURE__ */ new WeakMap();
|
|
85
83
|
function useLocal(argument, repeat) {
|
|
86
84
|
const state = (0, import_react2.useState)(() => {
|
|
87
|
-
let apply;
|
|
88
85
|
let enabled;
|
|
89
86
|
let local;
|
|
90
|
-
const instance = new
|
|
91
|
-
if (argument)
|
|
92
|
-
PENDING.set(instance, apply = () => {
|
|
93
|
-
if (typeof argument == "function")
|
|
94
|
-
argument(instance);
|
|
95
|
-
else if (argument) {
|
|
96
|
-
for (const key in instance)
|
|
97
|
-
if (argument.hasOwnProperty(key))
|
|
98
|
-
instance[key] = argument[key];
|
|
99
|
-
}
|
|
100
|
-
if (!repeat)
|
|
101
|
-
apply = void 0;
|
|
102
|
-
});
|
|
103
|
-
instance.set(0);
|
|
87
|
+
const instance = this.new(argument);
|
|
104
88
|
const release = instance.get((current) => {
|
|
105
89
|
local = current;
|
|
106
90
|
if (enabled)
|
|
107
91
|
state[1]((x) => x.bind(null));
|
|
108
92
|
});
|
|
109
93
|
return (props) => {
|
|
110
|
-
|
|
111
|
-
if (apply && enabled) {
|
|
94
|
+
if (repeat && enabled) {
|
|
112
95
|
enabled = false;
|
|
113
|
-
|
|
96
|
+
if (typeof props == "function")
|
|
97
|
+
props.call(instance, instance);
|
|
98
|
+
else if (typeof props == "object")
|
|
99
|
+
instance.set(props);
|
|
114
100
|
const update = instance.set();
|
|
115
101
|
if (update)
|
|
116
102
|
update.then(() => enabled = true);
|
|
@@ -132,12 +118,6 @@ function useLocal(argument, repeat) {
|
|
|
132
118
|
});
|
|
133
119
|
return state[0](argument);
|
|
134
120
|
}
|
|
135
|
-
import_mvc2.Model.on((_, subject) => {
|
|
136
|
-
const pending = PENDING.get(subject);
|
|
137
|
-
if (pending)
|
|
138
|
-
pending();
|
|
139
|
-
return null;
|
|
140
|
-
});
|
|
141
121
|
|
|
142
122
|
// src/useRemote.ts
|
|
143
123
|
function useRemote(argument) {
|
|
@@ -197,7 +177,7 @@ function useRemote(argument) {
|
|
|
197
177
|
}
|
|
198
178
|
|
|
199
179
|
// src/index.ts
|
|
200
|
-
var
|
|
180
|
+
var import_mvc3 = require("@expressive/mvc");
|
|
201
181
|
|
|
202
182
|
// src/consumer.ts
|
|
203
183
|
function Consumer(props) {
|
|
@@ -217,11 +197,8 @@ function Provider(props) {
|
|
|
217
197
|
const ambient = useContext();
|
|
218
198
|
const context = (0, import_react2.useMemo)(() => ambient.push(), []);
|
|
219
199
|
context.include(included).forEach((isExplicit, model) => {
|
|
220
|
-
if (assign && isExplicit)
|
|
221
|
-
|
|
222
|
-
if (K in model)
|
|
223
|
-
model.set(K, assign[K]);
|
|
224
|
-
}
|
|
200
|
+
if (assign && isExplicit)
|
|
201
|
+
model.set(assign);
|
|
225
202
|
setContext(model, context);
|
|
226
203
|
});
|
|
227
204
|
(0, import_react2.useEffect)(() => () => context.pop(), []);
|
|
@@ -229,10 +206,10 @@ function Provider(props) {
|
|
|
229
206
|
}
|
|
230
207
|
|
|
231
208
|
// src/index.ts
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
209
|
+
import_mvc2.Model.at = usingContext;
|
|
210
|
+
import_mvc2.Model.as = createComponent;
|
|
211
|
+
import_mvc2.Model.get = useRemote;
|
|
212
|
+
import_mvc2.Model.use = useLocal;
|
|
236
213
|
// Annotate the CommonJS export names for ESM import in node:
|
|
237
214
|
0 && (module.exports = {
|
|
238
215
|
Consumer,
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { Model as
|
|
2
|
+
import { Model as Model2 } from "@expressive/mvc";
|
|
3
3
|
|
|
4
4
|
// src/component.ts
|
|
5
5
|
function createComponent(render) {
|
|
@@ -47,37 +47,23 @@ function setContext(model, context) {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
// src/useLocal.ts
|
|
50
|
-
import { Model as Model2 } from "@expressive/mvc";
|
|
51
|
-
var PENDING = /* @__PURE__ */ new WeakMap();
|
|
52
50
|
function useLocal(argument, repeat) {
|
|
53
51
|
const state = useState(() => {
|
|
54
|
-
let apply;
|
|
55
52
|
let enabled;
|
|
56
53
|
let local;
|
|
57
|
-
const instance = new
|
|
58
|
-
if (argument)
|
|
59
|
-
PENDING.set(instance, apply = () => {
|
|
60
|
-
if (typeof argument == "function")
|
|
61
|
-
argument(instance);
|
|
62
|
-
else if (argument) {
|
|
63
|
-
for (const key in instance)
|
|
64
|
-
if (argument.hasOwnProperty(key))
|
|
65
|
-
instance[key] = argument[key];
|
|
66
|
-
}
|
|
67
|
-
if (!repeat)
|
|
68
|
-
apply = void 0;
|
|
69
|
-
});
|
|
70
|
-
instance.set(0);
|
|
54
|
+
const instance = this.new(argument);
|
|
71
55
|
const release = instance.get((current) => {
|
|
72
56
|
local = current;
|
|
73
57
|
if (enabled)
|
|
74
58
|
state[1]((x) => x.bind(null));
|
|
75
59
|
});
|
|
76
60
|
return (props) => {
|
|
77
|
-
|
|
78
|
-
if (apply && enabled) {
|
|
61
|
+
if (repeat && enabled) {
|
|
79
62
|
enabled = false;
|
|
80
|
-
|
|
63
|
+
if (typeof props == "function")
|
|
64
|
+
props.call(instance, instance);
|
|
65
|
+
else if (typeof props == "object")
|
|
66
|
+
instance.set(props);
|
|
81
67
|
const update = instance.set();
|
|
82
68
|
if (update)
|
|
83
69
|
update.then(() => enabled = true);
|
|
@@ -99,12 +85,6 @@ function useLocal(argument, repeat) {
|
|
|
99
85
|
});
|
|
100
86
|
return state[0](argument);
|
|
101
87
|
}
|
|
102
|
-
Model2.on((_, subject) => {
|
|
103
|
-
const pending = PENDING.get(subject);
|
|
104
|
-
if (pending)
|
|
105
|
-
pending();
|
|
106
|
-
return null;
|
|
107
|
-
});
|
|
108
88
|
|
|
109
89
|
// src/useRemote.ts
|
|
110
90
|
function useRemote(argument) {
|
|
@@ -184,11 +164,8 @@ function Provider(props) {
|
|
|
184
164
|
const ambient = useContext();
|
|
185
165
|
const context = useMemo(() => ambient.push(), []);
|
|
186
166
|
context.include(included).forEach((isExplicit, model) => {
|
|
187
|
-
if (assign && isExplicit)
|
|
188
|
-
|
|
189
|
-
if (K in model)
|
|
190
|
-
model.set(K, assign[K]);
|
|
191
|
-
}
|
|
167
|
+
if (assign && isExplicit)
|
|
168
|
+
model.set(assign);
|
|
192
169
|
setContext(model, context);
|
|
193
170
|
});
|
|
194
171
|
useEffect(() => () => context.pop(), []);
|
|
@@ -196,16 +173,16 @@ function Provider(props) {
|
|
|
196
173
|
}
|
|
197
174
|
|
|
198
175
|
// src/index.ts
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
176
|
+
Model2.at = usingContext;
|
|
177
|
+
Model2.as = createComponent;
|
|
178
|
+
Model2.get = useRemote;
|
|
179
|
+
Model2.use = useLocal;
|
|
203
180
|
export {
|
|
204
181
|
Consumer,
|
|
205
|
-
|
|
182
|
+
Model2 as Model,
|
|
206
183
|
Provider,
|
|
207
184
|
add,
|
|
208
|
-
|
|
185
|
+
Model2 as default,
|
|
209
186
|
get,
|
|
210
187
|
has,
|
|
211
188
|
ref,
|
package/package.json
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"preversion": "npm run test && npm run build"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@expressive/mvc": "^0.
|
|
34
|
+
"@expressive/mvc": "^0.43.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"react": ">=16.8.0 <19.0.0"
|
|
@@ -42,6 +42,6 @@
|
|
|
42
42
|
"react": "^18.2.0",
|
|
43
43
|
"react-test-renderer": "^18.2.0"
|
|
44
44
|
},
|
|
45
|
-
"version": "0.
|
|
46
|
-
"gitHead": "
|
|
45
|
+
"version": "0.43.0",
|
|
46
|
+
"gitHead": "ec66b5e7a3b7d2c525c2e9503c8cd4fd81e121a6"
|
|
47
47
|
}
|