@expressive/react 0.48.0 → 0.49.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 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>, passive?: true): T;
104
- /** Fetch instance of this class optionally. May be undefined, but will never subscribe. */
105
- function get<T extends Model>(this: Model.Type<T>, required: boolean): T | undefined;
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: () => import_mvc3.Model,
24
+ Model: () => import_mvc4.Model,
25
25
  Provider: () => Provider,
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
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 import_mvc3 = require("@expressive/mvc");
34
+ var import_mvc4 = require("@expressive/mvc");
35
35
 
36
36
  // src/component.ts
37
37
  function createComponent(render) {
@@ -97,6 +97,7 @@ function useLocal(argument, repeat) {
97
97
  }
98
98
 
99
99
  // src/useRemote.ts
100
+ var import_mvc2 = require("@expressive/mvc");
100
101
  function useRemote(argument) {
101
102
  const context = useContext();
102
103
  const state = (0, import_react2.useState)(() => {
@@ -108,8 +109,6 @@ function useRemote(argument) {
108
109
  };
109
110
  else
110
111
  throw new Error(`Could not find ${this} in context.`);
111
- if (typeof argument === "boolean")
112
- return () => instance;
113
112
  function forceUpdate(action) {
114
113
  if (typeof action == "function")
115
114
  action = action();
@@ -119,7 +118,7 @@ function useRemote(argument) {
119
118
  }
120
119
  let release;
121
120
  let value;
122
- release = instance.get((current) => {
121
+ release = (0, import_mvc2.effect)(instance, (current) => {
123
122
  if (typeof argument === "function") {
124
123
  const next = argument.call(current, current, forceUpdate);
125
124
  if (next === value)
@@ -129,7 +128,7 @@ function useRemote(argument) {
129
128
  value = current;
130
129
  if (release)
131
130
  refresh();
132
- });
131
+ }, argument === true);
133
132
  if (value instanceof Promise) {
134
133
  let error;
135
134
  release();
@@ -154,14 +153,20 @@ function useRemote(argument) {
154
153
  }
155
154
 
156
155
  // src/index.ts
157
- var import_mvc4 = require("@expressive/mvc");
156
+ var import_mvc5 = require("@expressive/mvc");
158
157
 
159
158
  // src/consumer.ts
160
159
  function Consumer(props) {
161
160
  const { children, has: has2, get: get2, for: Type } = props;
162
161
  if (typeof children == "function")
163
162
  return children(Type.get());
164
- const instance = Type.get(!!has2);
163
+ const context = useContext();
164
+ const instance = (0, import_react2.useMemo)(() => {
165
+ const instance2 = context.get(Type);
166
+ if (!instance2 && has2)
167
+ throw new Error(`Could not find ${Type} in context.`);
168
+ return instance2;
169
+ }, []);
165
170
  const callback = has2 || get2;
166
171
  if (typeof callback == "function")
167
172
  callback(instance);
@@ -169,12 +174,12 @@ function Consumer(props) {
169
174
  }
170
175
 
171
176
  // src/provider.ts
172
- var import_mvc2 = require("@expressive/mvc");
177
+ var import_mvc3 = require("@expressive/mvc");
173
178
  function Provider(props) {
174
179
  let { for: include, use: assign } = props;
175
180
  const ambient = useContext();
176
181
  const context = (0, import_react2.useMemo)(() => ambient.push(), []);
177
- if (typeof include == "function" || include instanceof import_mvc2.Model)
182
+ if (typeof include == "function" || include instanceof import_mvc3.Model)
178
183
  include = { [""]: include };
179
184
  context.include(include, (model, explicit) => {
180
185
  if (assign && explicit)
@@ -185,9 +190,9 @@ function Provider(props) {
185
190
  }
186
191
 
187
192
  // src/index.ts
188
- import_mvc3.Model.as = createComponent;
189
- import_mvc3.Model.get = useRemote;
190
- import_mvc3.Model.use = useLocal;
193
+ import_mvc4.Model.as = createComponent;
194
+ import_mvc4.Model.get = useRemote;
195
+ import_mvc4.Model.use = useLocal;
191
196
  // Annotate the CommonJS export names for ESM import in node:
192
197
  0 && (module.exports = {
193
198
  Consumer,
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/index.ts
2
- import { Model as Model2 } from "@expressive/mvc";
2
+ import { Model as Model3 } from "@expressive/mvc";
3
3
 
4
4
  // src/component.ts
5
5
  function createComponent(render) {
@@ -65,6 +65,7 @@ function useLocal(argument, repeat) {
65
65
  }
66
66
 
67
67
  // src/useRemote.ts
68
+ import { effect } from "@expressive/mvc";
68
69
  function useRemote(argument) {
69
70
  const context = useContext();
70
71
  const state = useState(() => {
@@ -76,8 +77,6 @@ function useRemote(argument) {
76
77
  };
77
78
  else
78
79
  throw new Error(`Could not find ${this} in context.`);
79
- if (typeof argument === "boolean")
80
- return () => instance;
81
80
  function forceUpdate(action) {
82
81
  if (typeof action == "function")
83
82
  action = action();
@@ -87,7 +86,7 @@ function useRemote(argument) {
87
86
  }
88
87
  let release;
89
88
  let value;
90
- release = instance.get((current) => {
89
+ release = effect(instance, (current) => {
91
90
  if (typeof argument === "function") {
92
91
  const next = argument.call(current, current, forceUpdate);
93
92
  if (next === value)
@@ -97,7 +96,7 @@ function useRemote(argument) {
97
96
  value = current;
98
97
  if (release)
99
98
  refresh();
100
- });
99
+ }, argument === true);
101
100
  if (value instanceof Promise) {
102
101
  let error;
103
102
  release();
@@ -129,7 +128,13 @@ function Consumer(props) {
129
128
  const { children, has: has2, get: get2, for: Type } = props;
130
129
  if (typeof children == "function")
131
130
  return children(Type.get());
132
- const instance = Type.get(!!has2);
131
+ const context = useContext();
132
+ const instance = useMemo(() => {
133
+ const instance2 = context.get(Type);
134
+ if (!instance2 && has2)
135
+ throw new Error(`Could not find ${Type} in context.`);
136
+ return instance2;
137
+ }, []);
133
138
  const callback = has2 || get2;
134
139
  if (typeof callback == "function")
135
140
  callback(instance);
@@ -137,12 +142,12 @@ function Consumer(props) {
137
142
  }
138
143
 
139
144
  // src/provider.ts
140
- import { Model } from "@expressive/mvc";
145
+ import { Model as Model2 } from "@expressive/mvc";
141
146
  function Provider(props) {
142
147
  let { for: include, use: assign } = props;
143
148
  const ambient = useContext();
144
149
  const context = useMemo(() => ambient.push(), []);
145
- if (typeof include == "function" || include instanceof Model)
150
+ if (typeof include == "function" || include instanceof Model2)
146
151
  include = { [""]: include };
147
152
  context.include(include, (model, explicit) => {
148
153
  if (assign && explicit)
@@ -153,14 +158,14 @@ function Provider(props) {
153
158
  }
154
159
 
155
160
  // src/index.ts
156
- Model2.as = createComponent;
157
- Model2.get = useRemote;
158
- Model2.use = useLocal;
161
+ Model3.as = createComponent;
162
+ Model3.get = useRemote;
163
+ Model3.use = useLocal;
159
164
  export {
160
165
  Consumer,
161
- Model2 as Model,
166
+ Model3 as Model,
162
167
  Provider,
163
- Model2 as default,
168
+ Model3 as default,
164
169
  get,
165
170
  has,
166
171
  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.48.0"
34
+ "@expressive/mvc": "^0.49.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.48.0",
46
- "gitHead": "1f5ddf82e800cf53bf867ac5e546ad3186ce8bf5"
45
+ "version": "0.49.0",
46
+ "gitHead": "3a1423ef6d335d0e876904459d360a2e0ebdff7b"
47
47
  }