@expressive/react 0.21.1 → 0.21.2

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,7 +1,8 @@
1
1
  import { Model } from '@expressive/mvc';
2
2
  export * from '@expressive/mvc';
3
- import * as React$1 from 'react';
4
- import React__default from 'react';
3
+ import * as react from 'react';
4
+ import { ReactNode } from 'react';
5
+ import * as packages_mvc_src_context from 'packages/mvc/src/context';
5
6
 
6
7
  declare namespace Consumer {
7
8
  type HasProps<T extends Model> = {
@@ -32,7 +33,7 @@ declare namespace Consumer {
32
33
  };
33
34
  type Props<T extends Model> = HasProps<T> | GetProps<T> | RenderProps<T>;
34
35
  }
35
- declare function Consumer<T extends Model>(props: Consumer.Props<T>): React$1.ReactElement<any, any> | null;
36
+ declare function Consumer<T extends Model>(props: Consumer.Props<T>): react.ReactElement<any, any> | null;
36
37
 
37
38
  type Class = new () => any;
38
39
  declare namespace Provider {
@@ -44,17 +45,17 @@ declare namespace Provider {
44
45
  type Props<T extends Item> = MultipleProps<T> | NormalProps<T>;
45
46
  type NormalProps<E, I = Instance<E>> = {
46
47
  for: E;
47
- fallback?: React__default.ReactNode;
48
- children?: React__default.ReactNode | ((instance: I) => React__default.ReactNode);
48
+ fallback?: ReactNode;
49
+ children?: ReactNode | ((instance: I) => ReactNode);
49
50
  use?: Model.Compat<I>;
50
51
  };
51
52
  type MultipleProps<T extends Item> = {
52
53
  for: Multiple<T>;
53
- fallback?: React__default.ReactNode;
54
- children?: React__default.ReactNode;
54
+ fallback?: ReactNode;
55
+ children?: ReactNode;
55
56
  use?: Model.Compat<Instance<T>>;
56
57
  };
57
58
  }
58
- declare function Provider<T extends Provider.Item>(props: Provider.Props<T>): JSX.Element;
59
+ declare function Provider<T extends Provider.Item>(props: Provider.Props<T>): react.FunctionComponentElement<react.ProviderProps<packages_mvc_src_context.Context>>;
59
60
 
60
61
  export { Consumer, Provider };
package/lib/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Context, Model, Control } from '@expressive/mvc';
2
2
  export * from '@expressive/mvc';
3
- import React, { createContext, useContext, useState, useMemo, useLayoutEffect, Suspense } from 'react';
3
+ import { createContext, useContext, useState, useMemo, useLayoutEffect, createElement, Suspense } from 'react';
4
4
 
5
5
  const LookupContext = createContext(new Context());
6
6
  const useLookup = () => useContext(LookupContext);
@@ -15,10 +15,10 @@ function hasModel(type, relativeTo, callback) {
15
15
  }
16
16
  const Applied = new WeakMap();
17
17
  function usePeerContext(instance) {
18
- const applyPeers = Applied.get(instance);
19
- if (applyPeers)
18
+ const applied = Applied.get(instance);
19
+ if (applied)
20
20
  useLookup();
21
- else if (applyPeers === undefined) {
21
+ else if (applied === undefined) {
22
22
  const pending = Pending.get(instance);
23
23
  if (pending) {
24
24
  const local = useLookup();
@@ -55,8 +55,6 @@ function Consumer(props) {
55
55
  const callback = has || get;
56
56
  if (typeof callback == "function")
57
57
  callback(Type.get(!!has));
58
- else
59
- throw new Error("Provider expects either a render function, 'get' or 'has' props.");
60
58
  return null;
61
59
  }
62
60
 
@@ -76,9 +74,9 @@ function Provider(props) {
76
74
  pending.forEach(cb => cb(context));
77
75
  });
78
76
  useLayoutEffect(() => () => context.pop(), []);
79
- return (React.createElement(LookupContext.Provider, { value: context }, props.fallback === false
77
+ return createElement(LookupContext.Provider, { value: context }, props.fallback == false
80
78
  ? props.children
81
- : (React.createElement(Suspense, { fallback: props.fallback || null }, props.children))));
79
+ : createElement(Suspense, { fallback: props.fallback || null }, props.children));
82
80
  }
83
81
 
84
82
  Control.get = getModel;
package/lib/index.js CHANGED
@@ -3,14 +3,10 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var mvc = require('@expressive/mvc');
6
- var React = require('react');
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 React__default = /*#__PURE__*/_interopDefaultLegacy(React);
11
-
12
- const LookupContext = React.createContext(new mvc.Context());
13
- const useLookup = () => React.useContext(LookupContext);
8
+ const LookupContext = react.createContext(new mvc.Context());
9
+ const useLookup = () => react.useContext(LookupContext);
14
10
  const Pending = new WeakMap();
15
11
  function hasModel(type, relativeTo, callback) {
16
12
  let pending = Pending.get(relativeTo);
@@ -22,10 +18,10 @@ function hasModel(type, relativeTo, callback) {
22
18
  }
23
19
  const Applied = new WeakMap();
24
20
  function usePeerContext(instance) {
25
- const applyPeers = Applied.get(instance);
26
- if (applyPeers)
21
+ const applied = Applied.get(instance);
22
+ if (applied)
27
23
  useLookup();
28
- else if (applyPeers === undefined) {
24
+ else if (applied === undefined) {
29
25
  const pending = Pending.get(instance);
30
26
  if (pending) {
31
27
  const local = useLookup();
@@ -38,20 +34,20 @@ function usePeerContext(instance) {
38
34
 
39
35
  const getModel = (type, adapter) => {
40
36
  const context = useLookup();
41
- const state = React.useState(0);
42
- const hook = React.useMemo(() => {
37
+ const state = react.useState(0);
38
+ const hook = react.useMemo(() => {
43
39
  return adapter(() => state[1](x => x + 1), cb => cb(context.get(type)));
44
40
  }, []);
45
41
  if (!hook)
46
42
  return null;
47
- React.useLayoutEffect(hook.mount, []);
43
+ react.useLayoutEffect(hook.mount, []);
48
44
  return hook.render();
49
45
  };
50
46
  const useModel = (adapter) => {
51
- const state = React.useState(0);
52
- const hook = React.useMemo(() => (adapter(() => state[1](x => x + 1))), []);
47
+ const state = react.useState(0);
48
+ const hook = react.useMemo(() => (adapter(() => state[1](x => x + 1))), []);
53
49
  usePeerContext(hook.instance);
54
- React.useLayoutEffect(hook.mount, []);
50
+ react.useLayoutEffect(hook.mount, []);
55
51
  return hook.render;
56
52
  };
57
53
 
@@ -62,15 +58,13 @@ function Consumer(props) {
62
58
  const callback = has || get;
63
59
  if (typeof callback == "function")
64
60
  callback(Type.get(!!has));
65
- else
66
- throw new Error("Provider expects either a render function, 'get' or 'has' props.");
67
61
  return null;
68
62
  }
69
63
 
70
64
  function Provider(props) {
71
65
  let { for: included, use: assign } = props;
72
66
  const ambient = useLookup();
73
- const context = React.useMemo(() => ambient.push(), []);
67
+ const context = react.useMemo(() => ambient.push(), []);
74
68
  if (typeof included == "function" || included instanceof mvc.Model)
75
69
  included = { [0]: included };
76
70
  context.include(included).forEach((explicit, model) => {
@@ -82,10 +76,10 @@ function Provider(props) {
82
76
  if (pending)
83
77
  pending.forEach(cb => cb(context));
84
78
  });
85
- React.useLayoutEffect(() => () => context.pop(), []);
86
- return (React__default["default"].createElement(LookupContext.Provider, { value: context }, props.fallback === false
79
+ react.useLayoutEffect(() => () => context.pop(), []);
80
+ return react.createElement(LookupContext.Provider, { value: context }, props.fallback == false
87
81
  ? props.children
88
- : (React__default["default"].createElement(React.Suspense, { fallback: props.fallback || null }, props.children))));
82
+ : react.createElement(react.Suspense, { fallback: props.fallback || null }, props.children));
89
83
  }
90
84
 
91
85
  mvc.Control.get = getModel;
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.1"
33
+ "@expressive/mvc": "^0.21.2"
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.1"
45
+ "version": "0.21.2"
46
46
  }