@expressive/react 0.48.0 → 0.50.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 +5 -3
- package/dist/index.js +29 -23
- package/dist/index.mjs +23 -17
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -100,9 +100,11 @@ declare module '@expressive/mvc' {
|
|
|
100
100
|
*/
|
|
101
101
|
function as<T extends Model, P = {}>(this: Model.Type<T>, render: (using: T & P) => React.ReactNode): Component<T, P & Model.Assign<T>>;
|
|
102
102
|
/** Fetch instance of this class from context. */
|
|
103
|
-
function get<T extends Model>(this: Model.Type<T
|
|
104
|
-
/** Fetch instance of this class optionally.
|
|
105
|
-
function get<T extends Model>(this: Model.Type<T>,
|
|
103
|
+
function get<T extends Model>(this: Model.Type<T>): T;
|
|
104
|
+
/** Fetch instance of this class optionally. */
|
|
105
|
+
function get<T extends Model>(this: Model.Type<T>, expect: false): T | undefined;
|
|
106
|
+
/** Fetch instance of this class from context. */
|
|
107
|
+
function get<T extends Model>(this: Model.Type<T>, expectValues: true): Required<T>;
|
|
106
108
|
function get<T extends Model, R>(this: Model.Type<T>, factory: get.Factory<T, Promise<R> | R>): NoVoid<R>;
|
|
107
109
|
function get<T extends Model, R>(this: Model.Type<T>, factory: get.Factory<T, null>): NoVoid<R> | null;
|
|
108
110
|
function use<T extends Model>(this: Model.Type<T>, apply?: Model.Assign<T>, repeat?: boolean): T;
|
package/dist/index.js
CHANGED
|
@@ -21,17 +21,17 @@ 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_mvc4.Model,
|
|
25
25
|
Provider: () => Provider,
|
|
26
|
-
default: () =>
|
|
27
|
-
get: () =>
|
|
28
|
-
has: () =>
|
|
29
|
-
ref: () =>
|
|
30
|
-
set: () =>
|
|
31
|
-
use: () =>
|
|
26
|
+
default: () => import_mvc4.Model,
|
|
27
|
+
get: () => import_mvc5.get,
|
|
28
|
+
has: () => import_mvc5.has,
|
|
29
|
+
ref: () => import_mvc5.ref,
|
|
30
|
+
set: () => import_mvc5.set,
|
|
31
|
+
use: () => import_mvc5.use
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(src_exports);
|
|
34
|
-
var
|
|
34
|
+
var import_mvc4 = require("@expressive/mvc");
|
|
35
35
|
|
|
36
36
|
// src/component.ts
|
|
37
37
|
function createComponent(render) {
|
|
@@ -59,6 +59,7 @@ var createContext = (value, children) => (0, import_react.createElement)(Shared.
|
|
|
59
59
|
function useLocal(argument, repeat) {
|
|
60
60
|
const state = (0, import_react2.useState)(() => {
|
|
61
61
|
let enabled;
|
|
62
|
+
let context;
|
|
62
63
|
let local;
|
|
63
64
|
const instance = new this(argument);
|
|
64
65
|
const release = instance.get((current) => {
|
|
@@ -79,15 +80,15 @@ function useLocal(argument, repeat) {
|
|
|
79
80
|
else
|
|
80
81
|
enabled = true;
|
|
81
82
|
}
|
|
82
|
-
const
|
|
83
|
-
context
|
|
84
|
-
|
|
85
|
-
instance.set();
|
|
83
|
+
const ctx = useContext();
|
|
84
|
+
if (!context)
|
|
85
|
+
context = ctx.push({ instance });
|
|
86
86
|
(0, import_react2.useEffect)(() => {
|
|
87
87
|
enabled = true;
|
|
88
88
|
return () => {
|
|
89
89
|
release();
|
|
90
90
|
instance.set(null);
|
|
91
|
+
context.pop();
|
|
91
92
|
};
|
|
92
93
|
}, []);
|
|
93
94
|
return local;
|
|
@@ -97,6 +98,7 @@ function useLocal(argument, repeat) {
|
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
// src/useRemote.ts
|
|
101
|
+
var import_mvc2 = require("@expressive/mvc");
|
|
100
102
|
function useRemote(argument) {
|
|
101
103
|
const context = useContext();
|
|
102
104
|
const state = (0, import_react2.useState)(() => {
|
|
@@ -108,8 +110,6 @@ function useRemote(argument) {
|
|
|
108
110
|
};
|
|
109
111
|
else
|
|
110
112
|
throw new Error(`Could not find ${this} in context.`);
|
|
111
|
-
if (typeof argument === "boolean")
|
|
112
|
-
return () => instance;
|
|
113
113
|
function forceUpdate(action) {
|
|
114
114
|
if (typeof action == "function")
|
|
115
115
|
action = action();
|
|
@@ -119,7 +119,7 @@ function useRemote(argument) {
|
|
|
119
119
|
}
|
|
120
120
|
let release;
|
|
121
121
|
let value;
|
|
122
|
-
release =
|
|
122
|
+
release = (0, import_mvc2.effect)(instance, (current) => {
|
|
123
123
|
if (typeof argument === "function") {
|
|
124
124
|
const next = argument.call(current, current, forceUpdate);
|
|
125
125
|
if (next === value)
|
|
@@ -129,7 +129,7 @@ function useRemote(argument) {
|
|
|
129
129
|
value = current;
|
|
130
130
|
if (release)
|
|
131
131
|
refresh();
|
|
132
|
-
});
|
|
132
|
+
}, argument === true);
|
|
133
133
|
if (value instanceof Promise) {
|
|
134
134
|
let error;
|
|
135
135
|
release();
|
|
@@ -154,14 +154,20 @@ function useRemote(argument) {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
// src/index.ts
|
|
157
|
-
var
|
|
157
|
+
var import_mvc5 = require("@expressive/mvc");
|
|
158
158
|
|
|
159
159
|
// src/consumer.ts
|
|
160
160
|
function Consumer(props) {
|
|
161
161
|
const { children, has: has2, get: get2, for: Type } = props;
|
|
162
162
|
if (typeof children == "function")
|
|
163
163
|
return children(Type.get());
|
|
164
|
-
const
|
|
164
|
+
const context = useContext();
|
|
165
|
+
const instance = (0, import_react2.useMemo)(() => {
|
|
166
|
+
const instance2 = context.get(Type);
|
|
167
|
+
if (!instance2 && has2)
|
|
168
|
+
throw new Error(`Could not find ${Type} in context.`);
|
|
169
|
+
return instance2;
|
|
170
|
+
}, []);
|
|
165
171
|
const callback = has2 || get2;
|
|
166
172
|
if (typeof callback == "function")
|
|
167
173
|
callback(instance);
|
|
@@ -169,12 +175,12 @@ function Consumer(props) {
|
|
|
169
175
|
}
|
|
170
176
|
|
|
171
177
|
// src/provider.ts
|
|
172
|
-
var
|
|
178
|
+
var import_mvc3 = require("@expressive/mvc");
|
|
173
179
|
function Provider(props) {
|
|
174
180
|
let { for: include, use: assign } = props;
|
|
175
181
|
const ambient = useContext();
|
|
176
182
|
const context = (0, import_react2.useMemo)(() => ambient.push(), []);
|
|
177
|
-
if (typeof include == "function" || include instanceof
|
|
183
|
+
if (typeof include == "function" || include instanceof import_mvc3.Model)
|
|
178
184
|
include = { [""]: include };
|
|
179
185
|
context.include(include, (model, explicit) => {
|
|
180
186
|
if (assign && explicit)
|
|
@@ -185,9 +191,9 @@ function Provider(props) {
|
|
|
185
191
|
}
|
|
186
192
|
|
|
187
193
|
// src/index.ts
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
194
|
+
import_mvc4.Model.as = createComponent;
|
|
195
|
+
import_mvc4.Model.get = useRemote;
|
|
196
|
+
import_mvc4.Model.use = useLocal;
|
|
191
197
|
// Annotate the CommonJS export names for ESM import in node:
|
|
192
198
|
0 && (module.exports = {
|
|
193
199
|
Consumer,
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { Model as
|
|
2
|
+
import { Model as Model3 } from "@expressive/mvc";
|
|
3
3
|
|
|
4
4
|
// src/component.ts
|
|
5
5
|
function createComponent(render) {
|
|
@@ -27,6 +27,7 @@ var createContext = (value, children) => createElement(Shared.Provider, { key: v
|
|
|
27
27
|
function useLocal(argument, repeat) {
|
|
28
28
|
const state = useState(() => {
|
|
29
29
|
let enabled;
|
|
30
|
+
let context;
|
|
30
31
|
let local;
|
|
31
32
|
const instance = new this(argument);
|
|
32
33
|
const release = instance.get((current) => {
|
|
@@ -47,15 +48,15 @@ function useLocal(argument, repeat) {
|
|
|
47
48
|
else
|
|
48
49
|
enabled = true;
|
|
49
50
|
}
|
|
50
|
-
const
|
|
51
|
-
context
|
|
52
|
-
|
|
53
|
-
instance.set();
|
|
51
|
+
const ctx = useContext();
|
|
52
|
+
if (!context)
|
|
53
|
+
context = ctx.push({ instance });
|
|
54
54
|
useEffect(() => {
|
|
55
55
|
enabled = true;
|
|
56
56
|
return () => {
|
|
57
57
|
release();
|
|
58
58
|
instance.set(null);
|
|
59
|
+
context.pop();
|
|
59
60
|
};
|
|
60
61
|
}, []);
|
|
61
62
|
return local;
|
|
@@ -65,6 +66,7 @@ function useLocal(argument, repeat) {
|
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
// src/useRemote.ts
|
|
69
|
+
import { effect } from "@expressive/mvc";
|
|
68
70
|
function useRemote(argument) {
|
|
69
71
|
const context = useContext();
|
|
70
72
|
const state = useState(() => {
|
|
@@ -76,8 +78,6 @@ function useRemote(argument) {
|
|
|
76
78
|
};
|
|
77
79
|
else
|
|
78
80
|
throw new Error(`Could not find ${this} in context.`);
|
|
79
|
-
if (typeof argument === "boolean")
|
|
80
|
-
return () => instance;
|
|
81
81
|
function forceUpdate(action) {
|
|
82
82
|
if (typeof action == "function")
|
|
83
83
|
action = action();
|
|
@@ -87,7 +87,7 @@ function useRemote(argument) {
|
|
|
87
87
|
}
|
|
88
88
|
let release;
|
|
89
89
|
let value;
|
|
90
|
-
release = instance
|
|
90
|
+
release = effect(instance, (current) => {
|
|
91
91
|
if (typeof argument === "function") {
|
|
92
92
|
const next = argument.call(current, current, forceUpdate);
|
|
93
93
|
if (next === value)
|
|
@@ -97,7 +97,7 @@ function useRemote(argument) {
|
|
|
97
97
|
value = current;
|
|
98
98
|
if (release)
|
|
99
99
|
refresh();
|
|
100
|
-
});
|
|
100
|
+
}, argument === true);
|
|
101
101
|
if (value instanceof Promise) {
|
|
102
102
|
let error;
|
|
103
103
|
release();
|
|
@@ -129,7 +129,13 @@ function Consumer(props) {
|
|
|
129
129
|
const { children, has: has2, get: get2, for: Type } = props;
|
|
130
130
|
if (typeof children == "function")
|
|
131
131
|
return children(Type.get());
|
|
132
|
-
const
|
|
132
|
+
const context = useContext();
|
|
133
|
+
const instance = useMemo(() => {
|
|
134
|
+
const instance2 = context.get(Type);
|
|
135
|
+
if (!instance2 && has2)
|
|
136
|
+
throw new Error(`Could not find ${Type} in context.`);
|
|
137
|
+
return instance2;
|
|
138
|
+
}, []);
|
|
133
139
|
const callback = has2 || get2;
|
|
134
140
|
if (typeof callback == "function")
|
|
135
141
|
callback(instance);
|
|
@@ -137,12 +143,12 @@ function Consumer(props) {
|
|
|
137
143
|
}
|
|
138
144
|
|
|
139
145
|
// src/provider.ts
|
|
140
|
-
import { Model } from "@expressive/mvc";
|
|
146
|
+
import { Model as Model2 } from "@expressive/mvc";
|
|
141
147
|
function Provider(props) {
|
|
142
148
|
let { for: include, use: assign } = props;
|
|
143
149
|
const ambient = useContext();
|
|
144
150
|
const context = useMemo(() => ambient.push(), []);
|
|
145
|
-
if (typeof include == "function" || include instanceof
|
|
151
|
+
if (typeof include == "function" || include instanceof Model2)
|
|
146
152
|
include = { [""]: include };
|
|
147
153
|
context.include(include, (model, explicit) => {
|
|
148
154
|
if (assign && explicit)
|
|
@@ -153,14 +159,14 @@ function Provider(props) {
|
|
|
153
159
|
}
|
|
154
160
|
|
|
155
161
|
// src/index.ts
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
162
|
+
Model3.as = createComponent;
|
|
163
|
+
Model3.get = useRemote;
|
|
164
|
+
Model3.use = useLocal;
|
|
159
165
|
export {
|
|
160
166
|
Consumer,
|
|
161
|
-
|
|
167
|
+
Model3 as Model,
|
|
162
168
|
Provider,
|
|
163
|
-
|
|
169
|
+
Model3 as default,
|
|
164
170
|
get,
|
|
165
171
|
has,
|
|
166
172
|
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.50.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.50.0",
|
|
46
|
+
"gitHead": "d645cd2a453bbe41af16acdc4349e259540ebf67"
|
|
47
47
|
}
|