@expressive/react 0.21.5 → 0.21.7

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/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Model, Context } from '@expressive/mvc';
2
- export { Context, Control, Debug, Model, default, get, ref, run, set, use } from '@expressive/mvc';
2
+ export { Context, Control, Debug, Model, Model as default, get, ref, run, set, use } from '@expressive/mvc';
3
3
  import { ReactElement, ReactNode, FunctionComponentElement, ProviderProps } from 'react';
4
4
 
5
5
  declare namespace Consumer {
package/lib/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Context, Model, Control } from '@expressive/mvc';
2
- export { Context, Control, Debug, Model, default, get, ref, run, set, use } from '@expressive/mvc';
2
+ export { Context, Control, Debug, Model, Model as default, get, ref, run, set, use } from '@expressive/mvc';
3
3
  import { createContext, useContext, useMemo, useLayoutEffect, createElement, Suspense, useState } from 'react';
4
4
 
5
5
  const LookupContext = createContext(new Context());
@@ -15,23 +15,28 @@ function usePeerContext(instance) {
15
15
  if (pending) {
16
16
  const local = useLookup();
17
17
  pending.forEach(init => init(local));
18
+ Applied.set(instance, local);
18
19
  Pending.delete(instance);
19
- Applied.set(instance, true);
20
20
  }
21
21
  }
22
22
  }
23
- function getPeerContext(type, relativeTo, callback) {
24
- let pending = Pending.get(relativeTo);
23
+ function setContext(model, has) {
24
+ let pending = Pending.get(model);
25
25
  if (!pending)
26
- Pending.set(relativeTo, pending = []);
27
- pending.push(context => {
28
- callback(context.get(type));
29
- });
26
+ Pending.set(model, pending = []);
27
+ pending.forEach(cb => cb(has));
30
28
  }
31
- function setPeerContext(model, context) {
32
- const pending = Pending.get(model);
33
- if (pending)
34
- pending.forEach(cb => cb(context));
29
+ function hasContext(model) {
30
+ let pending = Pending.get(model);
31
+ if (!pending)
32
+ Pending.set(model, pending = []);
33
+ return (callback) => {
34
+ const applied = Applied.get(model);
35
+ if (applied)
36
+ callback(applied);
37
+ else
38
+ pending.push(callback);
39
+ };
35
40
  }
36
41
 
37
42
  function Consumer(props) {
@@ -50,12 +55,12 @@ function Provider(props) {
50
55
  const context = useMemo(() => ambient.push(), []);
51
56
  if (typeof included == "function" || included instanceof Model)
52
57
  included = { [0]: included };
53
- context.include(included).forEach((explicit, model) => {
54
- if (assign && explicit)
58
+ context.include(included).forEach((isExplicit, model) => {
59
+ if (assign && isExplicit)
55
60
  for (const K in assign)
56
61
  if (K in model)
57
62
  model[K] = assign[K];
58
- setPeerContext(model, context);
63
+ setContext(model, context);
59
64
  });
60
65
  useLayoutEffect(() => () => context.pop(), []);
61
66
  return createElement(LookupContext.Provider, { value: context, key: context.key }, props.fallback == false
@@ -63,7 +68,7 @@ function Provider(props) {
63
68
  : createElement(Suspense, { fallback: props.fallback || null }, props.children));
64
69
  }
65
70
 
66
- Control.has = getPeerContext;
71
+ Control.has = hasContext;
67
72
  Control.get = (adapter) => {
68
73
  const context = useLookup();
69
74
  const state = useState(0);
package/lib/index.js CHANGED
@@ -5,10 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var mvc = require('@expressive/mvc');
6
6
  var react = require('react');
7
7
 
8
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
-
10
- var mvc__default = /*#__PURE__*/_interopDefaultLegacy(mvc);
11
-
12
8
  const LookupContext = react.createContext(new mvc.Context());
13
9
  const useLookup = () => react.useContext(LookupContext);
14
10
  const Pending = new WeakMap();
@@ -22,23 +18,28 @@ function usePeerContext(instance) {
22
18
  if (pending) {
23
19
  const local = useLookup();
24
20
  pending.forEach(init => init(local));
21
+ Applied.set(instance, local);
25
22
  Pending.delete(instance);
26
- Applied.set(instance, true);
27
23
  }
28
24
  }
29
25
  }
30
- function getPeerContext(type, relativeTo, callback) {
31
- let pending = Pending.get(relativeTo);
26
+ function setContext(model, has) {
27
+ let pending = Pending.get(model);
32
28
  if (!pending)
33
- Pending.set(relativeTo, pending = []);
34
- pending.push(context => {
35
- callback(context.get(type));
36
- });
29
+ Pending.set(model, pending = []);
30
+ pending.forEach(cb => cb(has));
37
31
  }
38
- function setPeerContext(model, context) {
39
- const pending = Pending.get(model);
40
- if (pending)
41
- pending.forEach(cb => cb(context));
32
+ function hasContext(model) {
33
+ let pending = Pending.get(model);
34
+ if (!pending)
35
+ Pending.set(model, pending = []);
36
+ return (callback) => {
37
+ const applied = Applied.get(model);
38
+ if (applied)
39
+ callback(applied);
40
+ else
41
+ pending.push(callback);
42
+ };
42
43
  }
43
44
 
44
45
  function Consumer(props) {
@@ -57,12 +58,12 @@ function Provider(props) {
57
58
  const context = react.useMemo(() => ambient.push(), []);
58
59
  if (typeof included == "function" || included instanceof mvc.Model)
59
60
  included = { [0]: included };
60
- context.include(included).forEach((explicit, model) => {
61
- if (assign && explicit)
61
+ context.include(included).forEach((isExplicit, model) => {
62
+ if (assign && isExplicit)
62
63
  for (const K in assign)
63
64
  if (K in model)
64
65
  model[K] = assign[K];
65
- setPeerContext(model, context);
66
+ setContext(model, context);
66
67
  });
67
68
  react.useLayoutEffect(() => () => context.pop(), []);
68
69
  return react.createElement(LookupContext.Provider, { value: context, key: context.key }, props.fallback == false
@@ -70,7 +71,7 @@ function Provider(props) {
70
71
  : react.createElement(react.Suspense, { fallback: props.fallback || null }, props.children));
71
72
  }
72
73
 
73
- mvc.Control.has = getPeerContext;
74
+ mvc.Control.has = hasContext;
74
75
  mvc.Control.get = (adapter) => {
75
76
  const context = useLookup();
76
77
  const state = react.useState(0);
@@ -106,7 +107,7 @@ Object.defineProperty(exports, 'Model', {
106
107
  });
107
108
  Object.defineProperty(exports, 'default', {
108
109
  enumerable: true,
109
- get: function () { return mvc__default["default"]; }
110
+ get: function () { return mvc.Model; }
110
111
  });
111
112
  Object.defineProperty(exports, 'get', {
112
113
  enumerable: true,
package/package.json CHANGED
@@ -30,7 +30,7 @@
30
30
  "postversion": "git push & npm publish"
31
31
  },
32
32
  "dependencies": {
33
- "@expressive/mvc": "^0.21.3"
33
+ "@expressive/mvc": "^0.21.7"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "react": ">=16.8.0 <19.0.0"
@@ -42,5 +42,5 @@
42
42
  "react": ">=17.0.2",
43
43
  "react-test-renderer": "^17.0.2"
44
44
  },
45
- "version": "0.21.5"
45
+ "version": "0.21.7"
46
46
  }