@expressive/react 0.47.0 → 0.48.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.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: () => import_mvc2.Model,
24
+ Model: () => import_mvc3.Model,
25
25
  Provider: () => Provider,
26
- default: () => import_mvc2.Model,
27
- get: () => import_mvc3.get,
28
- has: () => import_mvc3.has,
29
- ref: () => import_mvc3.ref,
30
- set: () => import_mvc3.set,
31
- use: () => import_mvc3.use
26
+ default: () => import_mvc3.Model,
27
+ get: () => import_mvc4.get,
28
+ has: () => import_mvc4.has,
29
+ ref: () => import_mvc4.ref,
30
+ set: () => import_mvc4.set,
31
+ use: () => import_mvc4.use
32
32
  });
33
33
  module.exports = __toCommonJS(src_exports);
34
- var import_mvc2 = require("@expressive/mvc");
34
+ var import_mvc3 = require("@expressive/mvc");
35
35
 
36
36
  // src/component.ts
37
37
  function createComponent(render) {
@@ -52,31 +52,8 @@ var import_mvc = require("@expressive/mvc");
52
52
  var import_react = require("react");
53
53
  var import_react2 = require("react");
54
54
  var Shared = (0, import_react.createContext)(new import_mvc.Context());
55
- var Register = /* @__PURE__ */ new WeakMap();
56
- function useContext() {
57
- return (0, import_react.useContext)(Shared);
58
- }
59
- function createContext(value, children) {
60
- return (0, import_react.createElement)(Shared.Provider, { key: value.id, value }, children);
61
- }
62
- function usingContext(from, resolve) {
63
- const waiting = Register.get(from);
64
- const callback = (context) => {
65
- resolve(context.get(this));
66
- };
67
- if (waiting instanceof import_mvc.Context)
68
- callback(waiting);
69
- else if (waiting)
70
- waiting.push(callback);
71
- else
72
- Register.set(from, [callback]);
73
- }
74
- function setContext(model, context) {
75
- const waiting = Register.get(model);
76
- if (waiting instanceof Array)
77
- waiting.forEach((cb) => cb(context));
78
- Register.set(model, context);
79
- }
55
+ var useContext = () => (0, import_react.useContext)(Shared);
56
+ var createContext = (value, children) => (0, import_react.createElement)(Shared.Provider, { key: value.id, value }, children);
80
57
 
81
58
  // src/useLocal.ts
82
59
  function useLocal(argument, repeat) {
@@ -103,7 +80,6 @@ function useLocal(argument, repeat) {
103
80
  enabled = true;
104
81
  }
105
82
  const context = useContext();
106
- setContext(instance, context);
107
83
  context.has(instance);
108
84
  if (!local)
109
85
  instance.set();
@@ -178,7 +154,7 @@ function useRemote(argument) {
178
154
  }
179
155
 
180
156
  // src/index.ts
181
- var import_mvc3 = require("@expressive/mvc");
157
+ var import_mvc4 = require("@expressive/mvc");
182
158
 
183
159
  // src/consumer.ts
184
160
  function Consumer(props) {
@@ -193,24 +169,25 @@ function Consumer(props) {
193
169
  }
194
170
 
195
171
  // src/provider.ts
172
+ var import_mvc2 = require("@expressive/mvc");
196
173
  function Provider(props) {
197
- let { for: included, use: assign } = props;
174
+ let { for: include, use: assign } = props;
198
175
  const ambient = useContext();
199
176
  const context = (0, import_react2.useMemo)(() => ambient.push(), []);
200
- context.include(included, (model, explicit) => {
177
+ if (typeof include == "function" || include instanceof import_mvc2.Model)
178
+ include = { [""]: include };
179
+ context.include(include, (model, explicit) => {
201
180
  if (assign && explicit)
202
181
  model.set(assign);
203
- setContext(model, context);
204
182
  });
205
183
  (0, import_react2.useEffect)(() => () => context.pop(), []);
206
184
  return createContext(context, props.children);
207
185
  }
208
186
 
209
187
  // src/index.ts
210
- import_mvc2.Model.at = usingContext;
211
- import_mvc2.Model.as = createComponent;
212
- import_mvc2.Model.get = useRemote;
213
- import_mvc2.Model.use = useLocal;
188
+ import_mvc3.Model.as = createComponent;
189
+ import_mvc3.Model.get = useRemote;
190
+ import_mvc3.Model.use = useLocal;
214
191
  // Annotate the CommonJS export names for ESM import in node:
215
192
  0 && (module.exports = {
216
193
  Consumer,
package/dist/index.mjs CHANGED
@@ -20,31 +20,8 @@ import { Context } from "@expressive/mvc";
20
20
  import { createContext as reactCreateContext, createElement, useContext as reactUseContext } from "react";
21
21
  import { useState, useEffect, useMemo } from "react";
22
22
  var Shared = reactCreateContext(new Context());
23
- var Register = /* @__PURE__ */ new WeakMap();
24
- function useContext() {
25
- return reactUseContext(Shared);
26
- }
27
- function createContext(value, children) {
28
- return createElement(Shared.Provider, { key: value.id, value }, children);
29
- }
30
- function usingContext(from, resolve) {
31
- const waiting = Register.get(from);
32
- const callback = (context) => {
33
- resolve(context.get(this));
34
- };
35
- if (waiting instanceof Context)
36
- callback(waiting);
37
- else if (waiting)
38
- waiting.push(callback);
39
- else
40
- Register.set(from, [callback]);
41
- }
42
- function setContext(model, context) {
43
- const waiting = Register.get(model);
44
- if (waiting instanceof Array)
45
- waiting.forEach((cb) => cb(context));
46
- Register.set(model, context);
47
- }
23
+ var useContext = () => reactUseContext(Shared);
24
+ var createContext = (value, children) => createElement(Shared.Provider, { key: value.id, value }, children);
48
25
 
49
26
  // src/useLocal.ts
50
27
  function useLocal(argument, repeat) {
@@ -71,7 +48,6 @@ function useLocal(argument, repeat) {
71
48
  enabled = true;
72
49
  }
73
50
  const context = useContext();
74
- setContext(instance, context);
75
51
  context.has(instance);
76
52
  if (!local)
77
53
  instance.set();
@@ -161,21 +137,22 @@ function Consumer(props) {
161
137
  }
162
138
 
163
139
  // src/provider.ts
140
+ import { Model } from "@expressive/mvc";
164
141
  function Provider(props) {
165
- let { for: included, use: assign } = props;
142
+ let { for: include, use: assign } = props;
166
143
  const ambient = useContext();
167
144
  const context = useMemo(() => ambient.push(), []);
168
- context.include(included, (model, explicit) => {
145
+ if (typeof include == "function" || include instanceof Model)
146
+ include = { [""]: include };
147
+ context.include(include, (model, explicit) => {
169
148
  if (assign && explicit)
170
149
  model.set(assign);
171
- setContext(model, context);
172
150
  });
173
151
  useEffect(() => () => context.pop(), []);
174
152
  return createContext(context, props.children);
175
153
  }
176
154
 
177
155
  // src/index.ts
178
- Model2.at = usingContext;
179
156
  Model2.as = createComponent;
180
157
  Model2.get = useRemote;
181
158
  Model2.use = useLocal;
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.47.0"
34
+ "@expressive/mvc": "^0.48.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.47.0",
46
- "gitHead": "7c0ddd5ea9b7e08bd5aa21aa8e1ab65ceef17fcf"
45
+ "version": "0.48.0",
46
+ "gitHead": "1f5ddf82e800cf53bf867ac5e546ad3186ce8bf5"
47
47
  }