@expressive/react 0.50.0 → 0.51.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 +4 -4
- package/dist/index.js +34 -28
- package/dist/index.mjs +26 -20
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ declare namespace Provider {
|
|
|
41
41
|
value: Context;
|
|
42
42
|
children?: ReactNode;
|
|
43
43
|
}>;
|
|
44
|
-
type Item = Model | Model.
|
|
44
|
+
type Item = Model | Model.Init;
|
|
45
45
|
type Multiple<T extends Item = Item> = {
|
|
46
46
|
[key: string | number]: T;
|
|
47
47
|
};
|
|
@@ -98,7 +98,7 @@ declare module '@expressive/mvc' {
|
|
|
98
98
|
*
|
|
99
99
|
* @param render Function which renders component. This function receives all Model state merged with props. Normal subscription behavior still applies.
|
|
100
100
|
*/
|
|
101
|
-
function as<T extends Model, P = {}>(this: Model.
|
|
101
|
+
function as<T extends Model, P = {}>(this: Model.Init<T>, render: (using: T & P) => React.ReactNode): Component<T, P & Model.Assign<T>>;
|
|
102
102
|
/** Fetch instance of this class from context. */
|
|
103
103
|
function get<T extends Model>(this: Model.Type<T>): T;
|
|
104
104
|
/** Fetch instance of this class optionally. */
|
|
@@ -107,8 +107,8 @@ declare module '@expressive/mvc' {
|
|
|
107
107
|
function get<T extends Model>(this: Model.Type<T>, expectValues: true): Required<T>;
|
|
108
108
|
function get<T extends Model, R>(this: Model.Type<T>, factory: get.Factory<T, Promise<R> | R>): NoVoid<R>;
|
|
109
109
|
function get<T extends Model, R>(this: Model.Type<T>, factory: get.Factory<T, null>): NoVoid<R> | null;
|
|
110
|
-
function use<T extends Model>(this: Model.
|
|
111
|
-
function use<T extends Model>(this: Model.
|
|
110
|
+
function use<T extends Model>(this: Model.Init<T>, apply?: Model.Assign<T>, repeat?: boolean): T;
|
|
111
|
+
function use<T extends Model>(this: Model.Init<T>, callback?: Model.Callback<T>, repeat?: boolean): T;
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
package/dist/index.js
CHANGED
|
@@ -21,20 +21,22 @@ 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_mvc6.Model,
|
|
25
25
|
Provider: () => Provider,
|
|
26
|
-
default: () =>
|
|
27
|
-
get: () =>
|
|
28
|
-
has: () =>
|
|
29
|
-
ref: () =>
|
|
30
|
-
set: () =>
|
|
31
|
-
use: () =>
|
|
26
|
+
default: () => import_mvc6.Model,
|
|
27
|
+
get: () => import_mvc7.get,
|
|
28
|
+
has: () => import_mvc7.has,
|
|
29
|
+
ref: () => import_mvc7.ref,
|
|
30
|
+
set: () => import_mvc7.set,
|
|
31
|
+
use: () => import_mvc7.use
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(src_exports);
|
|
34
|
-
var
|
|
34
|
+
var import_mvc6 = require("@expressive/mvc");
|
|
35
35
|
|
|
36
36
|
// src/component.ts
|
|
37
|
+
var import_mvc = require("@expressive/mvc");
|
|
37
38
|
function createComponent(render) {
|
|
39
|
+
import_mvc.Model.is(this);
|
|
38
40
|
const Component = (inputProps) => {
|
|
39
41
|
const props = this.use(inputProps, true);
|
|
40
42
|
for (const key in inputProps)
|
|
@@ -47,20 +49,25 @@ function createComponent(render) {
|
|
|
47
49
|
return Component;
|
|
48
50
|
}
|
|
49
51
|
|
|
52
|
+
// src/useLocal.ts
|
|
53
|
+
var import_mvc3 = require("@expressive/mvc");
|
|
54
|
+
|
|
50
55
|
// src/useContext.ts
|
|
51
|
-
var
|
|
56
|
+
var import_mvc2 = require("@expressive/mvc");
|
|
52
57
|
var import_react = require("react");
|
|
53
58
|
var import_react2 = require("react");
|
|
54
|
-
var Shared = (0, import_react.createContext)(new
|
|
55
|
-
var
|
|
56
|
-
var
|
|
59
|
+
var Shared = (0, import_react.createContext)(new import_mvc2.Context());
|
|
60
|
+
var useShared = () => (0, import_react.useContext)(Shared);
|
|
61
|
+
var createProvider = (value, children) => (0, import_react.createElement)(Shared.Provider, { key: value.id, value }, children);
|
|
57
62
|
|
|
58
63
|
// src/useLocal.ts
|
|
59
64
|
function useLocal(argument, repeat) {
|
|
65
|
+
const outer = useShared();
|
|
60
66
|
const state = (0, import_react2.useState)(() => {
|
|
61
67
|
let enabled;
|
|
62
68
|
let context;
|
|
63
69
|
let local;
|
|
70
|
+
import_mvc3.Model.is(this);
|
|
64
71
|
const instance = new this(argument);
|
|
65
72
|
const release = instance.get((current) => {
|
|
66
73
|
local = current;
|
|
@@ -68,6 +75,8 @@ function useLocal(argument, repeat) {
|
|
|
68
75
|
state[1]((x) => x.bind(null));
|
|
69
76
|
});
|
|
70
77
|
return (props) => {
|
|
78
|
+
if (!context)
|
|
79
|
+
context = outer.push({ instance });
|
|
71
80
|
if (repeat && enabled) {
|
|
72
81
|
enabled = false;
|
|
73
82
|
if (typeof props == "function")
|
|
@@ -80,9 +89,6 @@ function useLocal(argument, repeat) {
|
|
|
80
89
|
else
|
|
81
90
|
enabled = true;
|
|
82
91
|
}
|
|
83
|
-
const ctx = useContext();
|
|
84
|
-
if (!context)
|
|
85
|
-
context = ctx.push({ instance });
|
|
86
92
|
(0, import_react2.useEffect)(() => {
|
|
87
93
|
enabled = true;
|
|
88
94
|
return () => {
|
|
@@ -98,9 +104,9 @@ function useLocal(argument, repeat) {
|
|
|
98
104
|
}
|
|
99
105
|
|
|
100
106
|
// src/useRemote.ts
|
|
101
|
-
var
|
|
107
|
+
var import_mvc4 = require("@expressive/mvc");
|
|
102
108
|
function useRemote(argument) {
|
|
103
|
-
const context =
|
|
109
|
+
const context = useShared();
|
|
104
110
|
const state = (0, import_react2.useState)(() => {
|
|
105
111
|
const instance = context.get(this);
|
|
106
112
|
const refresh = () => state[1]((x) => x.bind(null));
|
|
@@ -119,7 +125,7 @@ function useRemote(argument) {
|
|
|
119
125
|
}
|
|
120
126
|
let release;
|
|
121
127
|
let value;
|
|
122
|
-
release = (0,
|
|
128
|
+
release = (0, import_mvc4.effect)(instance, (current) => {
|
|
123
129
|
if (typeof argument === "function") {
|
|
124
130
|
const next = argument.call(current, current, forceUpdate);
|
|
125
131
|
if (next === value)
|
|
@@ -154,14 +160,14 @@ function useRemote(argument) {
|
|
|
154
160
|
}
|
|
155
161
|
|
|
156
162
|
// src/index.ts
|
|
157
|
-
var
|
|
163
|
+
var import_mvc7 = require("@expressive/mvc");
|
|
158
164
|
|
|
159
165
|
// src/consumer.ts
|
|
160
166
|
function Consumer(props) {
|
|
161
167
|
const { children, has: has2, get: get2, for: Type } = props;
|
|
162
168
|
if (typeof children == "function")
|
|
163
|
-
return
|
|
164
|
-
const context =
|
|
169
|
+
return Type.get(children);
|
|
170
|
+
const context = useShared();
|
|
165
171
|
const instance = (0, import_react2.useMemo)(() => {
|
|
166
172
|
const instance2 = context.get(Type);
|
|
167
173
|
if (!instance2 && has2)
|
|
@@ -175,25 +181,25 @@ function Consumer(props) {
|
|
|
175
181
|
}
|
|
176
182
|
|
|
177
183
|
// src/provider.ts
|
|
178
|
-
var
|
|
184
|
+
var import_mvc5 = require("@expressive/mvc");
|
|
179
185
|
function Provider(props) {
|
|
180
186
|
let { for: include, use: assign } = props;
|
|
181
|
-
const ambient =
|
|
187
|
+
const ambient = useShared();
|
|
182
188
|
const context = (0, import_react2.useMemo)(() => ambient.push(), []);
|
|
183
|
-
if (typeof include == "function" || include instanceof
|
|
189
|
+
if (typeof include == "function" || include instanceof import_mvc5.Model)
|
|
184
190
|
include = { [""]: include };
|
|
185
191
|
context.include(include, (model, explicit) => {
|
|
186
192
|
if (assign && explicit)
|
|
187
193
|
model.set(assign);
|
|
188
194
|
});
|
|
189
195
|
(0, import_react2.useEffect)(() => () => context.pop(), []);
|
|
190
|
-
return
|
|
196
|
+
return createProvider(context, props.children);
|
|
191
197
|
}
|
|
192
198
|
|
|
193
199
|
// src/index.ts
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
200
|
+
import_mvc6.Model.as = createComponent;
|
|
201
|
+
import_mvc6.Model.get = useRemote;
|
|
202
|
+
import_mvc6.Model.use = useLocal;
|
|
197
203
|
// Annotate the CommonJS export names for ESM import in node:
|
|
198
204
|
0 && (module.exports = {
|
|
199
205
|
Consumer,
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { Model as
|
|
2
|
+
import { Model as Model5 } from "@expressive/mvc";
|
|
3
3
|
|
|
4
4
|
// src/component.ts
|
|
5
|
+
import { Model } from "@expressive/mvc";
|
|
5
6
|
function createComponent(render) {
|
|
7
|
+
Model.is(this);
|
|
6
8
|
const Component = (inputProps) => {
|
|
7
9
|
const props = this.use(inputProps, true);
|
|
8
10
|
for (const key in inputProps)
|
|
@@ -15,20 +17,25 @@ function createComponent(render) {
|
|
|
15
17
|
return Component;
|
|
16
18
|
}
|
|
17
19
|
|
|
20
|
+
// src/useLocal.ts
|
|
21
|
+
import { Model as Model2 } from "@expressive/mvc";
|
|
22
|
+
|
|
18
23
|
// src/useContext.ts
|
|
19
24
|
import { Context } from "@expressive/mvc";
|
|
20
|
-
import { createContext
|
|
25
|
+
import { createContext, createElement, useContext } from "react";
|
|
21
26
|
import { useState, useEffect, useMemo } from "react";
|
|
22
|
-
var Shared =
|
|
23
|
-
var
|
|
24
|
-
var
|
|
27
|
+
var Shared = createContext(new Context());
|
|
28
|
+
var useShared = () => useContext(Shared);
|
|
29
|
+
var createProvider = (value, children) => createElement(Shared.Provider, { key: value.id, value }, children);
|
|
25
30
|
|
|
26
31
|
// src/useLocal.ts
|
|
27
32
|
function useLocal(argument, repeat) {
|
|
33
|
+
const outer = useShared();
|
|
28
34
|
const state = useState(() => {
|
|
29
35
|
let enabled;
|
|
30
36
|
let context;
|
|
31
37
|
let local;
|
|
38
|
+
Model2.is(this);
|
|
32
39
|
const instance = new this(argument);
|
|
33
40
|
const release = instance.get((current) => {
|
|
34
41
|
local = current;
|
|
@@ -36,6 +43,8 @@ function useLocal(argument, repeat) {
|
|
|
36
43
|
state[1]((x) => x.bind(null));
|
|
37
44
|
});
|
|
38
45
|
return (props) => {
|
|
46
|
+
if (!context)
|
|
47
|
+
context = outer.push({ instance });
|
|
39
48
|
if (repeat && enabled) {
|
|
40
49
|
enabled = false;
|
|
41
50
|
if (typeof props == "function")
|
|
@@ -48,9 +57,6 @@ function useLocal(argument, repeat) {
|
|
|
48
57
|
else
|
|
49
58
|
enabled = true;
|
|
50
59
|
}
|
|
51
|
-
const ctx = useContext();
|
|
52
|
-
if (!context)
|
|
53
|
-
context = ctx.push({ instance });
|
|
54
60
|
useEffect(() => {
|
|
55
61
|
enabled = true;
|
|
56
62
|
return () => {
|
|
@@ -68,7 +74,7 @@ function useLocal(argument, repeat) {
|
|
|
68
74
|
// src/useRemote.ts
|
|
69
75
|
import { effect } from "@expressive/mvc";
|
|
70
76
|
function useRemote(argument) {
|
|
71
|
-
const context =
|
|
77
|
+
const context = useShared();
|
|
72
78
|
const state = useState(() => {
|
|
73
79
|
const instance = context.get(this);
|
|
74
80
|
const refresh = () => state[1]((x) => x.bind(null));
|
|
@@ -128,8 +134,8 @@ import { get, use, ref, set, has } from "@expressive/mvc";
|
|
|
128
134
|
function Consumer(props) {
|
|
129
135
|
const { children, has: has2, get: get2, for: Type } = props;
|
|
130
136
|
if (typeof children == "function")
|
|
131
|
-
return
|
|
132
|
-
const context =
|
|
137
|
+
return Type.get(children);
|
|
138
|
+
const context = useShared();
|
|
133
139
|
const instance = useMemo(() => {
|
|
134
140
|
const instance2 = context.get(Type);
|
|
135
141
|
if (!instance2 && has2)
|
|
@@ -143,30 +149,30 @@ function Consumer(props) {
|
|
|
143
149
|
}
|
|
144
150
|
|
|
145
151
|
// src/provider.ts
|
|
146
|
-
import { Model as
|
|
152
|
+
import { Model as Model4 } from "@expressive/mvc";
|
|
147
153
|
function Provider(props) {
|
|
148
154
|
let { for: include, use: assign } = props;
|
|
149
|
-
const ambient =
|
|
155
|
+
const ambient = useShared();
|
|
150
156
|
const context = useMemo(() => ambient.push(), []);
|
|
151
|
-
if (typeof include == "function" || include instanceof
|
|
157
|
+
if (typeof include == "function" || include instanceof Model4)
|
|
152
158
|
include = { [""]: include };
|
|
153
159
|
context.include(include, (model, explicit) => {
|
|
154
160
|
if (assign && explicit)
|
|
155
161
|
model.set(assign);
|
|
156
162
|
});
|
|
157
163
|
useEffect(() => () => context.pop(), []);
|
|
158
|
-
return
|
|
164
|
+
return createProvider(context, props.children);
|
|
159
165
|
}
|
|
160
166
|
|
|
161
167
|
// src/index.ts
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
168
|
+
Model5.as = createComponent;
|
|
169
|
+
Model5.get = useRemote;
|
|
170
|
+
Model5.use = useLocal;
|
|
165
171
|
export {
|
|
166
172
|
Consumer,
|
|
167
|
-
|
|
173
|
+
Model5 as Model,
|
|
168
174
|
Provider,
|
|
169
|
-
|
|
175
|
+
Model5 as default,
|
|
170
176
|
get,
|
|
171
177
|
has,
|
|
172
178
|
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.51.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.51.0",
|
|
46
|
+
"gitHead": "9f020cb09a146bcb14e9deb765c07beab345ea95"
|
|
47
47
|
}
|