@expressive/react 0.20.0 → 0.21.1

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 } from '@expressive/mvc';
2
- export { Control, Debug, Model, default, get, ref, run, set, use } from '@expressive/mvc';
2
+ export * from '@expressive/mvc';
3
3
  import * as React$1 from 'react';
4
4
  import React__default from 'react';
5
5
 
package/lib/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
- import { Context, issues, Model, Control } from '@expressive/mvc';
2
- export { Control, Debug, Model, default, get, ref, run, set, use } from '@expressive/mvc';
1
+ import { Context, Model, Control } from '@expressive/mvc';
2
+ export * from '@expressive/mvc';
3
3
  import React, { createContext, useContext, useState, useMemo, useLayoutEffect, Suspense } from 'react';
4
4
 
5
5
  const LookupContext = createContext(new Context());
@@ -48,9 +48,6 @@ const useModel = (adapter) => {
48
48
  return hook.render;
49
49
  };
50
50
 
51
- const Oops$1 = issues({
52
- BadProps: () => `Provider expects either a render function, 'get' or 'has' props.`
53
- });
54
51
  function Consumer(props) {
55
52
  const { children, has, get, for: Type } = props;
56
53
  if (typeof children == "function")
@@ -59,44 +56,25 @@ function Consumer(props) {
59
56
  if (typeof callback == "function")
60
57
  callback(Type.get(!!has));
61
58
  else
62
- throw Oops$1.BadProps();
59
+ throw new Error("Provider expects either a render function, 'get' or 'has' props.");
63
60
  return null;
64
61
  }
65
62
 
66
- const Oops = issues({
67
- NoType: () => "Provider 'for' prop must be Model, typeof Model or a collection of them."
68
- });
69
63
  function Provider(props) {
70
- let { for: include, use: assign } = props;
71
- const init = new Set();
64
+ let { for: included, use: assign } = props;
72
65
  const ambient = useLookup();
73
- const context = useMemo(() => {
74
- if (include)
75
- return ambient.push();
76
- throw Oops.NoType();
77
- }, []);
78
- if (typeof include == "function" || include instanceof Model)
79
- include = { [0]: include };
80
- for (const key in include) {
81
- const instance = context.add(include[key], key);
82
- init.add(instance);
83
- if (assign)
66
+ const context = useMemo(() => ambient.push(), []);
67
+ if (typeof included == "function" || included instanceof Model)
68
+ included = { [0]: included };
69
+ context.include(included).forEach((explicit, model) => {
70
+ if (assign && explicit)
84
71
  for (const K in assign)
85
- if (K in instance)
86
- instance[K] = assign[K];
87
- }
88
- for (const model of init) {
89
- const control = Control.for(model, true);
72
+ if (K in model)
73
+ model[K] = assign[K];
90
74
  const pending = Pending.get(model);
91
75
  if (pending)
92
76
  pending.forEach(cb => cb(context));
93
- Object.values(control.state).forEach(value => {
94
- if (value instanceof Model && Control.for(value).parent === model) {
95
- context.add(value);
96
- init.add(value);
97
- }
98
- });
99
- }
77
+ });
100
78
  useLayoutEffect(() => () => context.pop(), []);
101
79
  return (React.createElement(LookupContext.Provider, { value: context }, props.fallback === false
102
80
  ? props.children
package/lib/index.js CHANGED
@@ -7,7 +7,6 @@ var React = require('react');
7
7
 
8
8
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
9
 
10
- var mvc__default = /*#__PURE__*/_interopDefaultLegacy(mvc);
11
10
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
12
11
 
13
12
  const LookupContext = React.createContext(new mvc.Context());
@@ -56,9 +55,6 @@ const useModel = (adapter) => {
56
55
  return hook.render;
57
56
  };
58
57
 
59
- const Oops$1 = mvc.issues({
60
- BadProps: () => `Provider expects either a render function, 'get' or 'has' props.`
61
- });
62
58
  function Consumer(props) {
63
59
  const { children, has, get, for: Type } = props;
64
60
  if (typeof children == "function")
@@ -67,44 +63,25 @@ function Consumer(props) {
67
63
  if (typeof callback == "function")
68
64
  callback(Type.get(!!has));
69
65
  else
70
- throw Oops$1.BadProps();
66
+ throw new Error("Provider expects either a render function, 'get' or 'has' props.");
71
67
  return null;
72
68
  }
73
69
 
74
- const Oops = mvc.issues({
75
- NoType: () => "Provider 'for' prop must be Model, typeof Model or a collection of them."
76
- });
77
70
  function Provider(props) {
78
- let { for: include, use: assign } = props;
79
- const init = new Set();
71
+ let { for: included, use: assign } = props;
80
72
  const ambient = useLookup();
81
- const context = React.useMemo(() => {
82
- if (include)
83
- return ambient.push();
84
- throw Oops.NoType();
85
- }, []);
86
- if (typeof include == "function" || include instanceof mvc.Model)
87
- include = { [0]: include };
88
- for (const key in include) {
89
- const instance = context.add(include[key], key);
90
- init.add(instance);
91
- if (assign)
73
+ const context = React.useMemo(() => ambient.push(), []);
74
+ if (typeof included == "function" || included instanceof mvc.Model)
75
+ included = { [0]: included };
76
+ context.include(included).forEach((explicit, model) => {
77
+ if (assign && explicit)
92
78
  for (const K in assign)
93
- if (K in instance)
94
- instance[K] = assign[K];
95
- }
96
- for (const model of init) {
97
- const control = mvc.Control.for(model, true);
79
+ if (K in model)
80
+ model[K] = assign[K];
98
81
  const pending = Pending.get(model);
99
82
  if (pending)
100
83
  pending.forEach(cb => cb(context));
101
- Object.values(control.state).forEach(value => {
102
- if (value instanceof mvc.Model && mvc.Control.for(value).parent === model) {
103
- context.add(value);
104
- init.add(value);
105
- }
106
- });
107
- }
84
+ });
108
85
  React.useLayoutEffect(() => () => context.pop(), []);
109
86
  return (React__default["default"].createElement(LookupContext.Provider, { value: context }, props.fallback === false
110
87
  ? props.children
@@ -115,41 +92,11 @@ mvc.Control.get = getModel;
115
92
  mvc.Control.use = useModel;
116
93
  mvc.Control.has = hasModel;
117
94
 
118
- Object.defineProperty(exports, 'Control', {
119
- enumerable: true,
120
- get: function () { return mvc.Control; }
121
- });
122
- Object.defineProperty(exports, 'Debug', {
123
- enumerable: true,
124
- get: function () { return mvc.Debug; }
125
- });
126
- Object.defineProperty(exports, 'Model', {
127
- enumerable: true,
128
- get: function () { return mvc.Model; }
129
- });
130
- Object.defineProperty(exports, 'default', {
131
- enumerable: true,
132
- get: function () { return mvc__default["default"]; }
133
- });
134
- Object.defineProperty(exports, 'get', {
135
- enumerable: true,
136
- get: function () { return mvc.get; }
137
- });
138
- Object.defineProperty(exports, 'ref', {
139
- enumerable: true,
140
- get: function () { return mvc.ref; }
141
- });
142
- Object.defineProperty(exports, 'run', {
143
- enumerable: true,
144
- get: function () { return mvc.run; }
145
- });
146
- Object.defineProperty(exports, 'set', {
147
- enumerable: true,
148
- get: function () { return mvc.set; }
149
- });
150
- Object.defineProperty(exports, 'use', {
151
- enumerable: true,
152
- get: function () { return mvc.use; }
153
- });
154
95
  exports.Consumer = Consumer;
155
96
  exports.Provider = Provider;
97
+ Object.keys(mvc).forEach(function (k) {
98
+ if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
99
+ enumerable: true,
100
+ get: function () { return mvc[k]; }
101
+ });
102
+ });
package/package.json CHANGED
@@ -30,7 +30,7 @@
30
30
  "postversion": "git push & npm publish"
31
31
  },
32
32
  "dependencies": {
33
- "@expressive/mvc": "^0.20.0"
33
+ "@expressive/mvc": "^0.21.1"
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.20.0"
45
+ "version": "0.21.1"
46
46
  }