@expressive/react 0.35.1 → 0.35.5-alpha.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
@@ -1,22 +1,24 @@
1
1
  import { Model, Context } from '@expressive/mvc';
2
2
  export * from '@expressive/mvc';
3
3
  export { Model as default } from '@expressive/mvc';
4
- import { ReactElement, FunctionComponentElement, ProviderProps, ReactNode } from 'react';
4
+ import { ReactElement, FunctionComponentElement, ProviderProps } from 'react';
5
5
 
6
6
  declare namespace Consumer {
7
7
  type HasProps<T extends Model> = {
8
8
  /** Type of controller to fetch from context. */
9
9
  for: Model.Type<T>;
10
10
  /**
11
- * Getter function. Is called on every natural render of this component.
11
+ * If boolean, will assert controller of type `for` is present in context.
12
+ *
13
+ * If function, will called on every natural render of this component.
12
14
  * Will throw if usable instance cannot be found in context.
13
15
  */
14
- has: (value: T) => void;
16
+ has: ((value: T) => void) | boolean;
15
17
  };
16
18
  type GetProps<T extends Model> = {
17
19
  /** Type of controller to fetch from context. */
18
20
  for: Model.Type<T>;
19
- /** Getter function. Is called on every natural render of this component. */
21
+ /** Function called on every natural render of this component. */
20
22
  get: (value: T | undefined) => void;
21
23
  };
22
24
  type RenderProps<T extends Model> = {
@@ -44,12 +46,12 @@ declare namespace Provider {
44
46
  type Props<T extends Item = Item> = MultipleProps<T> | NormalProps<T>;
45
47
  type NormalProps<E, I = Instance<E>> = {
46
48
  for: E;
47
- children?: ReactNode;
49
+ children?: unknown;
48
50
  use?: Model.Values<I>;
49
51
  };
50
52
  type MultipleProps<T extends Item> = {
51
53
  for: Multiple<T>;
52
- children?: ReactNode;
54
+ children?: unknown;
53
55
  use?: Model.Values<Instance<T>>;
54
56
  };
55
57
  }
package/dist/index.js CHANGED
@@ -57,7 +57,11 @@ function useLocal(apply, repeat) {
57
57
  }
58
58
  if (!repeat)
59
59
  shouldApply = false;
60
- instance.set().then(() => enabled = true);
60
+ const update = instance.set();
61
+ if (update)
62
+ update.then(() => enabled = true);
63
+ else
64
+ enabled = true;
61
65
  }
62
66
  setContext(instance, (0, import_react.useContext)(Shared));
63
67
  (0, import_react.useEffect)(() => {
@@ -152,11 +156,10 @@ __reExport(src_exports, require("@expressive/mvc"), module.exports);
152
156
  // src/consumer.ts
153
157
  function Consumer(props) {
154
158
  const { children, has, get, for: Type } = props;
155
- if (typeof children == "function")
156
- return children(Type.get());
157
- const callback = has || get;
159
+ const instance = Type.get(!!has);
160
+ const callback = children || has || get;
158
161
  if (typeof callback == "function")
159
- callback(Type.get(!!has));
162
+ callback(instance);
160
163
  return null;
161
164
  }
162
165
 
package/dist/index.mjs CHANGED
@@ -30,7 +30,11 @@ function useLocal(apply, repeat) {
30
30
  }
31
31
  if (!repeat)
32
32
  shouldApply = false;
33
- instance.set().then(() => enabled = true);
33
+ const update = instance.set();
34
+ if (update)
35
+ update.then(() => enabled = true);
36
+ else
37
+ enabled = true;
34
38
  }
35
39
  setContext(instance, useContext(Shared));
36
40
  useEffect(() => {
@@ -125,11 +129,10 @@ export * from "@expressive/mvc";
125
129
  // src/consumer.ts
126
130
  function Consumer(props) {
127
131
  const { children, has, get, for: Type } = props;
128
- if (typeof children == "function")
129
- return children(Type.get());
130
- const callback = has || get;
132
+ const instance = Type.get(!!has);
133
+ const callback = children || has || get;
131
134
  if (typeof callback == "function")
132
- callback(Type.get(!!has));
135
+ callback(instance);
133
136
  return null;
134
137
  }
135
138
 
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.35.1"
34
+ "@expressive/mvc": "^0.35.5-alpha.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.35.1",
46
- "gitHead": "cca282d36102e4691e3d24a07f95e7652b27f5c3"
45
+ "version": "0.35.5-alpha.0",
46
+ "gitHead": "9626c3d85bd2fa7a8e5368c845ff8d889843be0b"
47
47
  }