isomorfeus-preact 10.6.14 → 10.6.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/lib/isomorfeus-preact.rb +3 -3
  3. data/lib/isomorfeus_preact/lucid_component/api.rb +1 -1
  4. data/lib/isomorfeus_preact/lucid_component/initializer.rb +2 -2
  5. data/lib/isomorfeus_preact/lucid_func/initializer.rb +1 -1
  6. data/lib/isomorfeus_preact/preact/function_component/initializer.rb +1 -1
  7. data/lib/preact/component/api.rb +1 -1
  8. data/lib/preact/component/callbacks.rb +6 -6
  9. data/lib/preact/component/initializer.rb +2 -2
  10. data/lib/preact/component/native_component_constructor.rb +1 -1
  11. data/lib/preact/props.rb +51 -0
  12. data/lib/preact/state.rb +67 -0
  13. data/lib/preact/version.rb +1 -1
  14. data/lib/preact.rb +2 -2
  15. data/node_modules/.package-lock.json +3 -3
  16. data/node_modules/preact/LICENSE +21 -21
  17. data/node_modules/preact/README.md +187 -187
  18. data/node_modules/preact/compat/dist/compat.js +1 -1
  19. data/node_modules/preact/compat/dist/compat.js.map +1 -1
  20. data/node_modules/preact/compat/dist/compat.mjs +1 -1
  21. data/node_modules/preact/compat/dist/compat.module.js +1 -1
  22. data/node_modules/preact/compat/dist/compat.module.js.map +1 -1
  23. data/node_modules/preact/compat/dist/compat.umd.js +1 -1
  24. data/node_modules/preact/compat/dist/compat.umd.js.map +1 -1
  25. data/node_modules/preact/compat/jsx-dev-runtime.js +1 -1
  26. data/node_modules/preact/compat/jsx-dev-runtime.mjs +1 -1
  27. data/node_modules/preact/compat/jsx-runtime.js +1 -1
  28. data/node_modules/preact/compat/jsx-runtime.mjs +1 -1
  29. data/node_modules/preact/compat/package.json +19 -19
  30. data/node_modules/preact/compat/scheduler.js +15 -15
  31. data/node_modules/preact/compat/scheduler.mjs +23 -23
  32. data/node_modules/preact/compat/server.js +15 -15
  33. data/node_modules/preact/compat/server.mjs +4 -4
  34. data/node_modules/preact/compat/src/Children.js +21 -21
  35. data/node_modules/preact/compat/src/PureComponent.js +15 -15
  36. data/node_modules/preact/compat/src/forwardRef.js +51 -51
  37. data/node_modules/preact/compat/src/index.d.ts +141 -141
  38. data/node_modules/preact/compat/src/index.js +187 -187
  39. data/node_modules/preact/compat/src/internal.d.ts +47 -47
  40. data/node_modules/preact/compat/src/memo.js +34 -34
  41. data/node_modules/preact/compat/src/portals.js +80 -80
  42. data/node_modules/preact/compat/src/render.js +229 -230
  43. data/node_modules/preact/compat/src/suspense-list.d.ts +14 -14
  44. data/node_modules/preact/compat/src/suspense-list.js +126 -126
  45. data/node_modules/preact/compat/src/suspense.d.ts +15 -15
  46. data/node_modules/preact/compat/src/suspense.js +270 -270
  47. data/node_modules/preact/compat/src/util.js +28 -28
  48. data/node_modules/preact/compat/test-utils.js +1 -1
  49. data/node_modules/preact/debug/dist/debug.js.map +1 -1
  50. data/node_modules/preact/debug/dist/debug.module.js.map +1 -1
  51. data/node_modules/preact/debug/dist/debug.umd.js.map +1 -1
  52. data/node_modules/preact/debug/package.json +18 -18
  53. data/node_modules/preact/debug/src/check-props.js +54 -54
  54. data/node_modules/preact/debug/src/component-stack.js +146 -146
  55. data/node_modules/preact/debug/src/constants.js +3 -3
  56. data/node_modules/preact/debug/src/debug.js +442 -442
  57. data/node_modules/preact/debug/src/index.js +6 -6
  58. data/node_modules/preact/debug/src/internal.d.ts +82 -82
  59. data/node_modules/preact/debug/src/util.js +11 -11
  60. data/node_modules/preact/devtools/dist/devtools.js +1 -1
  61. data/node_modules/preact/devtools/dist/devtools.js.map +1 -1
  62. data/node_modules/preact/devtools/dist/devtools.mjs +1 -1
  63. data/node_modules/preact/devtools/dist/devtools.module.js +1 -1
  64. data/node_modules/preact/devtools/dist/devtools.module.js.map +1 -1
  65. data/node_modules/preact/devtools/dist/devtools.umd.js +1 -1
  66. data/node_modules/preact/devtools/dist/devtools.umd.js.map +1 -1
  67. data/node_modules/preact/devtools/package.json +16 -16
  68. data/node_modules/preact/devtools/src/devtools.js +10 -10
  69. data/node_modules/preact/devtools/src/index.d.ts +8 -8
  70. data/node_modules/preact/devtools/src/index.js +15 -15
  71. data/node_modules/preact/dist/preact.js.map +1 -1
  72. data/node_modules/preact/dist/preact.min.js.map +1 -1
  73. data/node_modules/preact/dist/preact.module.js.map +1 -1
  74. data/node_modules/preact/dist/preact.umd.js.map +1 -1
  75. data/node_modules/preact/hooks/dist/hooks.js +1 -1
  76. data/node_modules/preact/hooks/dist/hooks.js.map +1 -1
  77. data/node_modules/preact/hooks/dist/hooks.mjs +1 -1
  78. data/node_modules/preact/hooks/dist/hooks.module.js +1 -1
  79. data/node_modules/preact/hooks/dist/hooks.module.js.map +1 -1
  80. data/node_modules/preact/hooks/dist/hooks.umd.js +1 -1
  81. data/node_modules/preact/hooks/dist/hooks.umd.js.map +1 -1
  82. data/node_modules/preact/hooks/package.json +26 -26
  83. data/node_modules/preact/hooks/src/index.d.ts +139 -139
  84. data/node_modules/preact/hooks/src/index.js +386 -388
  85. data/node_modules/preact/hooks/src/internal.d.ts +75 -75
  86. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js.map +1 -1
  87. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js.map +1 -1
  88. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js.map +1 -1
  89. data/node_modules/preact/jsx-runtime/package.json +19 -19
  90. data/node_modules/preact/jsx-runtime/src/index.d.ts +50 -50
  91. data/node_modules/preact/jsx-runtime/src/index.js +77 -77
  92. data/node_modules/preact/package.json +291 -287
  93. data/node_modules/preact/src/cjs.js +3 -3
  94. data/node_modules/preact/src/clone-element.js +34 -34
  95. data/node_modules/preact/src/component.js +225 -225
  96. data/node_modules/preact/src/constants.js +3 -3
  97. data/node_modules/preact/src/create-context.js +68 -68
  98. data/node_modules/preact/src/create-element.js +98 -98
  99. data/node_modules/preact/src/diff/catch-error.js +38 -38
  100. data/node_modules/preact/src/diff/children.js +335 -335
  101. data/node_modules/preact/src/diff/index.js +516 -516
  102. data/node_modules/preact/src/diff/props.js +158 -158
  103. data/node_modules/preact/src/index.d.ts +310 -310
  104. data/node_modules/preact/src/index.js +13 -13
  105. data/node_modules/preact/src/internal.d.ts +146 -146
  106. data/node_modules/preact/src/jsx.d.ts +1005 -1005
  107. data/node_modules/preact/src/options.js +16 -16
  108. data/node_modules/preact/src/render.js +75 -75
  109. data/node_modules/preact/src/util.js +27 -27
  110. data/node_modules/preact/test-utils/dist/testUtils.js.map +1 -1
  111. data/node_modules/preact/test-utils/dist/testUtils.module.js.map +1 -1
  112. data/node_modules/preact/test-utils/dist/testUtils.umd.js.map +1 -1
  113. data/node_modules/preact/test-utils/package.json +19 -19
  114. data/node_modules/preact/test-utils/src/index.d.ts +3 -3
  115. data/node_modules/preact/test-utils/src/index.js +117 -117
  116. data/package.json +1 -1
  117. metadata +4 -4
  118. data/lib/preact/component/props.rb +0 -55
  119. data/lib/preact/component/state.rb +0 -58
@@ -1,270 +1,270 @@
1
- import { Component, createElement, options, Fragment } from 'preact';
2
- import { assign } from './util';
3
-
4
- const oldCatchError = options._catchError;
5
- options._catchError = function(error, newVNode, oldVNode) {
6
- if (error.then) {
7
- /** @type {import('./internal').Component} */
8
- let component;
9
- let vnode = newVNode;
10
-
11
- for (; (vnode = vnode._parent); ) {
12
- if ((component = vnode._component) && component._childDidSuspend) {
13
- if (newVNode._dom == null) {
14
- newVNode._dom = oldVNode._dom;
15
- newVNode._children = oldVNode._children;
16
- }
17
- // Don't call oldCatchError if we found a Suspense
18
- return component._childDidSuspend(error, newVNode);
19
- }
20
- }
21
- }
22
- oldCatchError(error, newVNode, oldVNode);
23
- };
24
-
25
- const oldUnmount = options.unmount;
26
- options.unmount = function(vnode) {
27
- /** @type {import('./internal').Component} */
28
- const component = vnode._component;
29
- if (component && component._onResolve) {
30
- component._onResolve();
31
- }
32
-
33
- // if the component is still hydrating
34
- // most likely it is because the component is suspended
35
- // we set the vnode.type as `null` so that it is not a typeof function
36
- // so the unmount will remove the vnode._dom
37
- if (component && vnode._hydrating === true) {
38
- vnode.type = null;
39
- }
40
-
41
- if (oldUnmount) oldUnmount(vnode);
42
- };
43
-
44
- function detachedClone(vnode, detachedParent, parentDom) {
45
- if (vnode) {
46
- if (vnode._component && vnode._component.__hooks) {
47
- vnode._component.__hooks._list.forEach(effect => {
48
- if (typeof effect._cleanup == 'function') effect._cleanup();
49
- });
50
-
51
- vnode._component.__hooks = null;
52
- }
53
-
54
- vnode = assign({}, vnode);
55
- if (vnode._component != null) {
56
- if (vnode._component._parentDom === parentDom) {
57
- vnode._component._parentDom = detachedParent;
58
- }
59
- vnode._component = null;
60
- }
61
-
62
- vnode._children =
63
- vnode._children &&
64
- vnode._children.map(child =>
65
- detachedClone(child, detachedParent, parentDom)
66
- );
67
- }
68
-
69
- return vnode;
70
- }
71
-
72
- function removeOriginal(vnode, detachedParent, originalParent) {
73
- if (vnode) {
74
- vnode._original = null;
75
- vnode._children =
76
- vnode._children &&
77
- vnode._children.map(child =>
78
- removeOriginal(child, detachedParent, originalParent)
79
- );
80
-
81
- if (vnode._component) {
82
- if (vnode._component._parentDom === detachedParent) {
83
- if (vnode._dom) {
84
- originalParent.insertBefore(vnode._dom, vnode._nextDom);
85
- }
86
- vnode._component._force = true;
87
- vnode._component._parentDom = originalParent;
88
- }
89
- }
90
- }
91
-
92
- return vnode;
93
- }
94
-
95
- // having custom inheritance instead of a class here saves a lot of bytes
96
- export function Suspense() {
97
- // we do not call super here to golf some bytes...
98
- this._pendingSuspensionCount = 0;
99
- this._suspenders = null;
100
- this._detachOnNextRender = null;
101
- }
102
-
103
- // Things we do here to save some bytes but are not proper JS inheritance:
104
- // - call `new Component()` as the prototype
105
- // - do not set `Suspense.prototype.constructor` to `Suspense`
106
- Suspense.prototype = new Component();
107
-
108
- /**
109
- * @this {import('./internal').SuspenseComponent}
110
- * @param {Promise} promise The thrown promise
111
- * @param {import('./internal').VNode<any, any>} suspendingVNode The suspending component
112
- */
113
- Suspense.prototype._childDidSuspend = function(promise, suspendingVNode) {
114
- const suspendingComponent = suspendingVNode._component;
115
-
116
- /** @type {import('./internal').SuspenseComponent} */
117
- const c = this;
118
-
119
- if (c._suspenders == null) {
120
- c._suspenders = [];
121
- }
122
- c._suspenders.push(suspendingComponent);
123
-
124
- const resolve = suspended(c._vnode);
125
-
126
- let resolved = false;
127
- const onResolved = () => {
128
- if (resolved) return;
129
-
130
- resolved = true;
131
- suspendingComponent._onResolve = null;
132
-
133
- if (resolve) {
134
- resolve(onSuspensionComplete);
135
- } else {
136
- onSuspensionComplete();
137
- }
138
- };
139
-
140
- suspendingComponent._onResolve = onResolved;
141
-
142
- const onSuspensionComplete = () => {
143
- if (!--c._pendingSuspensionCount) {
144
- // If the suspension was during hydration we don't need to restore the
145
- // suspended children into the _children array
146
- if (c.state._suspended) {
147
- const suspendedVNode = c.state._suspended;
148
- c._vnode._children[0] = removeOriginal(
149
- suspendedVNode,
150
- suspendedVNode._component._parentDom,
151
- suspendedVNode._component._originalParentDom
152
- );
153
- }
154
-
155
- c.setState({ _suspended: (c._detachOnNextRender = null) });
156
-
157
- let suspended;
158
- while ((suspended = c._suspenders.pop())) {
159
- suspended.forceUpdate();
160
- }
161
- }
162
- };
163
-
164
- /**
165
- * We do not set `suspended: true` during hydration because we want the actual markup
166
- * to remain on screen and hydrate it when the suspense actually gets resolved.
167
- * While in non-hydration cases the usual fallback -> component flow would occour.
168
- */
169
- const wasHydrating = suspendingVNode._hydrating === true;
170
- if (!c._pendingSuspensionCount++ && !wasHydrating) {
171
- c.setState({ _suspended: (c._detachOnNextRender = c._vnode._children[0]) });
172
- }
173
- promise.then(onResolved, onResolved);
174
- };
175
-
176
- Suspense.prototype.componentWillUnmount = function() {
177
- this._suspenders = [];
178
- };
179
-
180
- /**
181
- * @this {import('./internal').SuspenseComponent}
182
- * @param {import('./internal').SuspenseComponent["props"]} props
183
- * @param {import('./internal').SuspenseState} state
184
- */
185
- Suspense.prototype.render = function(props, state) {
186
- if (this._detachOnNextRender) {
187
- // When the Suspense's _vnode was created by a call to createVNode
188
- // (i.e. due to a setState further up in the tree)
189
- // it's _children prop is null, in this case we "forget" about the parked vnodes to detach
190
- if (this._vnode._children) {
191
- const detachedParent = document.createElement('div');
192
- const detachedComponent = this._vnode._children[0]._component;
193
- this._vnode._children[0] = detachedClone(
194
- this._detachOnNextRender,
195
- detachedParent,
196
- (detachedComponent._originalParentDom = detachedComponent._parentDom)
197
- );
198
- }
199
-
200
- this._detachOnNextRender = null;
201
- }
202
-
203
- // Wrap fallback tree in a VNode that prevents itself from being marked as aborting mid-hydration:
204
- /** @type {import('./internal').VNode} */
205
- const fallback =
206
- state._suspended && createElement(Fragment, null, props.fallback);
207
- if (fallback) fallback._hydrating = null;
208
-
209
- return [
210
- createElement(Fragment, null, state._suspended ? null : props.children),
211
- fallback
212
- ];
213
- };
214
-
215
- /**
216
- * Checks and calls the parent component's _suspended method, passing in the
217
- * suspended vnode. This is a way for a parent (e.g. SuspenseList) to get notified
218
- * that one of its children/descendants suspended.
219
- *
220
- * The parent MAY return a callback. The callback will get called when the
221
- * suspension resolves, notifying the parent of the fact.
222
- * Moreover, the callback gets function `unsuspend` as a parameter. The resolved
223
- * child descendant will not actually get unsuspended until `unsuspend` gets called.
224
- * This is a way for the parent to delay unsuspending.
225
- *
226
- * If the parent does not return a callback then the resolved vnode
227
- * gets unsuspended immediately when it resolves.
228
- *
229
- * @param {import('./internal').VNode} vnode
230
- * @returns {((unsuspend: () => void) => void)?}
231
- */
232
- export function suspended(vnode) {
233
- /** @type {import('./internal').Component} */
234
- let component = vnode._parent._component;
235
- return component && component._suspended && component._suspended(vnode);
236
- }
237
-
238
- export function lazy(loader) {
239
- let prom;
240
- let component;
241
- let error;
242
-
243
- function Lazy(props) {
244
- if (!prom) {
245
- prom = loader();
246
- prom.then(
247
- exports => {
248
- component = exports.default || exports;
249
- },
250
- e => {
251
- error = e;
252
- }
253
- );
254
- }
255
-
256
- if (error) {
257
- throw error;
258
- }
259
-
260
- if (!component) {
261
- throw prom;
262
- }
263
-
264
- return createElement(component, props);
265
- }
266
-
267
- Lazy.displayName = 'Lazy';
268
- Lazy._forwarded = true;
269
- return Lazy;
270
- }
1
+ import { Component, createElement, options, Fragment } from 'preact';
2
+ import { assign } from './util';
3
+
4
+ const oldCatchError = options._catchError;
5
+ options._catchError = function(error, newVNode, oldVNode) {
6
+ if (error.then) {
7
+ /** @type {import('./internal').Component} */
8
+ let component;
9
+ let vnode = newVNode;
10
+
11
+ for (; (vnode = vnode._parent); ) {
12
+ if ((component = vnode._component) && component._childDidSuspend) {
13
+ if (newVNode._dom == null) {
14
+ newVNode._dom = oldVNode._dom;
15
+ newVNode._children = oldVNode._children;
16
+ }
17
+ // Don't call oldCatchError if we found a Suspense
18
+ return component._childDidSuspend(error, newVNode);
19
+ }
20
+ }
21
+ }
22
+ oldCatchError(error, newVNode, oldVNode);
23
+ };
24
+
25
+ const oldUnmount = options.unmount;
26
+ options.unmount = function(vnode) {
27
+ /** @type {import('./internal').Component} */
28
+ const component = vnode._component;
29
+ if (component && component._onResolve) {
30
+ component._onResolve();
31
+ }
32
+
33
+ // if the component is still hydrating
34
+ // most likely it is because the component is suspended
35
+ // we set the vnode.type as `null` so that it is not a typeof function
36
+ // so the unmount will remove the vnode._dom
37
+ if (component && vnode._hydrating === true) {
38
+ vnode.type = null;
39
+ }
40
+
41
+ if (oldUnmount) oldUnmount(vnode);
42
+ };
43
+
44
+ function detachedClone(vnode, detachedParent, parentDom) {
45
+ if (vnode) {
46
+ if (vnode._component && vnode._component.__hooks) {
47
+ vnode._component.__hooks._list.forEach(effect => {
48
+ if (typeof effect._cleanup == 'function') effect._cleanup();
49
+ });
50
+
51
+ vnode._component.__hooks = null;
52
+ }
53
+
54
+ vnode = assign({}, vnode);
55
+ if (vnode._component != null) {
56
+ if (vnode._component._parentDom === parentDom) {
57
+ vnode._component._parentDom = detachedParent;
58
+ }
59
+ vnode._component = null;
60
+ }
61
+
62
+ vnode._children =
63
+ vnode._children &&
64
+ vnode._children.map(child =>
65
+ detachedClone(child, detachedParent, parentDom)
66
+ );
67
+ }
68
+
69
+ return vnode;
70
+ }
71
+
72
+ function removeOriginal(vnode, detachedParent, originalParent) {
73
+ if (vnode) {
74
+ vnode._original = null;
75
+ vnode._children =
76
+ vnode._children &&
77
+ vnode._children.map(child =>
78
+ removeOriginal(child, detachedParent, originalParent)
79
+ );
80
+
81
+ if (vnode._component) {
82
+ if (vnode._component._parentDom === detachedParent) {
83
+ if (vnode._dom) {
84
+ originalParent.insertBefore(vnode._dom, vnode._nextDom);
85
+ }
86
+ vnode._component._force = true;
87
+ vnode._component._parentDom = originalParent;
88
+ }
89
+ }
90
+ }
91
+
92
+ return vnode;
93
+ }
94
+
95
+ // having custom inheritance instead of a class here saves a lot of bytes
96
+ export function Suspense() {
97
+ // we do not call super here to golf some bytes...
98
+ this._pendingSuspensionCount = 0;
99
+ this._suspenders = null;
100
+ this._detachOnNextRender = null;
101
+ }
102
+
103
+ // Things we do here to save some bytes but are not proper JS inheritance:
104
+ // - call `new Component()` as the prototype
105
+ // - do not set `Suspense.prototype.constructor` to `Suspense`
106
+ Suspense.prototype = new Component();
107
+
108
+ /**
109
+ * @this {import('./internal').SuspenseComponent}
110
+ * @param {Promise} promise The thrown promise
111
+ * @param {import('./internal').VNode<any, any>} suspendingVNode The suspending component
112
+ */
113
+ Suspense.prototype._childDidSuspend = function(promise, suspendingVNode) {
114
+ const suspendingComponent = suspendingVNode._component;
115
+
116
+ /** @type {import('./internal').SuspenseComponent} */
117
+ const c = this;
118
+
119
+ if (c._suspenders == null) {
120
+ c._suspenders = [];
121
+ }
122
+ c._suspenders.push(suspendingComponent);
123
+
124
+ const resolve = suspended(c._vnode);
125
+
126
+ let resolved = false;
127
+ const onResolved = () => {
128
+ if (resolved) return;
129
+
130
+ resolved = true;
131
+ suspendingComponent._onResolve = null;
132
+
133
+ if (resolve) {
134
+ resolve(onSuspensionComplete);
135
+ } else {
136
+ onSuspensionComplete();
137
+ }
138
+ };
139
+
140
+ suspendingComponent._onResolve = onResolved;
141
+
142
+ const onSuspensionComplete = () => {
143
+ if (!--c._pendingSuspensionCount) {
144
+ // If the suspension was during hydration we don't need to restore the
145
+ // suspended children into the _children array
146
+ if (c.state._suspended) {
147
+ const suspendedVNode = c.state._suspended;
148
+ c._vnode._children[0] = removeOriginal(
149
+ suspendedVNode,
150
+ suspendedVNode._component._parentDom,
151
+ suspendedVNode._component._originalParentDom
152
+ );
153
+ }
154
+
155
+ c.setState({ _suspended: (c._detachOnNextRender = null) });
156
+
157
+ let suspended;
158
+ while ((suspended = c._suspenders.pop())) {
159
+ suspended.forceUpdate();
160
+ }
161
+ }
162
+ };
163
+
164
+ /**
165
+ * We do not set `suspended: true` during hydration because we want the actual markup
166
+ * to remain on screen and hydrate it when the suspense actually gets resolved.
167
+ * While in non-hydration cases the usual fallback -> component flow would occour.
168
+ */
169
+ const wasHydrating = suspendingVNode._hydrating === true;
170
+ if (!c._pendingSuspensionCount++ && !wasHydrating) {
171
+ c.setState({ _suspended: (c._detachOnNextRender = c._vnode._children[0]) });
172
+ }
173
+ promise.then(onResolved, onResolved);
174
+ };
175
+
176
+ Suspense.prototype.componentWillUnmount = function() {
177
+ this._suspenders = [];
178
+ };
179
+
180
+ /**
181
+ * @this {import('./internal').SuspenseComponent}
182
+ * @param {import('./internal').SuspenseComponent["props"]} props
183
+ * @param {import('./internal').SuspenseState} state
184
+ */
185
+ Suspense.prototype.render = function(props, state) {
186
+ if (this._detachOnNextRender) {
187
+ // When the Suspense's _vnode was created by a call to createVNode
188
+ // (i.e. due to a setState further up in the tree)
189
+ // it's _children prop is null, in this case we "forget" about the parked vnodes to detach
190
+ if (this._vnode._children) {
191
+ const detachedParent = document.createElement('div');
192
+ const detachedComponent = this._vnode._children[0]._component;
193
+ this._vnode._children[0] = detachedClone(
194
+ this._detachOnNextRender,
195
+ detachedParent,
196
+ (detachedComponent._originalParentDom = detachedComponent._parentDom)
197
+ );
198
+ }
199
+
200
+ this._detachOnNextRender = null;
201
+ }
202
+
203
+ // Wrap fallback tree in a VNode that prevents itself from being marked as aborting mid-hydration:
204
+ /** @type {import('./internal').VNode} */
205
+ const fallback =
206
+ state._suspended && createElement(Fragment, null, props.fallback);
207
+ if (fallback) fallback._hydrating = null;
208
+
209
+ return [
210
+ createElement(Fragment, null, state._suspended ? null : props.children),
211
+ fallback
212
+ ];
213
+ };
214
+
215
+ /**
216
+ * Checks and calls the parent component's _suspended method, passing in the
217
+ * suspended vnode. This is a way for a parent (e.g. SuspenseList) to get notified
218
+ * that one of its children/descendants suspended.
219
+ *
220
+ * The parent MAY return a callback. The callback will get called when the
221
+ * suspension resolves, notifying the parent of the fact.
222
+ * Moreover, the callback gets function `unsuspend` as a parameter. The resolved
223
+ * child descendant will not actually get unsuspended until `unsuspend` gets called.
224
+ * This is a way for the parent to delay unsuspending.
225
+ *
226
+ * If the parent does not return a callback then the resolved vnode
227
+ * gets unsuspended immediately when it resolves.
228
+ *
229
+ * @param {import('./internal').VNode} vnode
230
+ * @returns {((unsuspend: () => void) => void)?}
231
+ */
232
+ export function suspended(vnode) {
233
+ /** @type {import('./internal').Component} */
234
+ let component = vnode._parent._component;
235
+ return component && component._suspended && component._suspended(vnode);
236
+ }
237
+
238
+ export function lazy(loader) {
239
+ let prom;
240
+ let component;
241
+ let error;
242
+
243
+ function Lazy(props) {
244
+ if (!prom) {
245
+ prom = loader();
246
+ prom.then(
247
+ exports => {
248
+ component = exports.default || exports;
249
+ },
250
+ e => {
251
+ error = e;
252
+ }
253
+ );
254
+ }
255
+
256
+ if (error) {
257
+ throw error;
258
+ }
259
+
260
+ if (!component) {
261
+ throw prom;
262
+ }
263
+
264
+ return createElement(component, props);
265
+ }
266
+
267
+ Lazy.displayName = 'Lazy';
268
+ Lazy._forwarded = true;
269
+ return Lazy;
270
+ }
@@ -1,28 +1,28 @@
1
- /**
2
- * Assign properties from `props` to `obj`
3
- * @template O, P The obj and props types
4
- * @param {O} obj The object to copy properties to
5
- * @param {P} props The object to copy properties from
6
- * @returns {O & P}
7
- */
8
- export function assign(obj, props) {
9
- for (let i in props) obj[i] = props[i];
10
- return /** @type {O & P} */ (obj);
11
- }
12
-
13
- /**
14
- * Check if two objects have a different shape
15
- * @param {object} a
16
- * @param {object} b
17
- * @returns {boolean}
18
- */
19
- export function shallowDiffers(a, b) {
20
- for (let i in a) if (i !== '__source' && !(i in b)) return true;
21
- for (let i in b) if (i !== '__source' && a[i] !== b[i]) return true;
22
- return false;
23
- }
24
-
25
- export function removeNode(node) {
26
- let parentNode = node.parentNode;
27
- if (parentNode) parentNode.removeChild(node);
28
- }
1
+ /**
2
+ * Assign properties from `props` to `obj`
3
+ * @template O, P The obj and props types
4
+ * @param {O} obj The object to copy properties to
5
+ * @param {P} props The object to copy properties from
6
+ * @returns {O & P}
7
+ */
8
+ export function assign(obj, props) {
9
+ for (let i in props) obj[i] = props[i];
10
+ return /** @type {O & P} */ (obj);
11
+ }
12
+
13
+ /**
14
+ * Check if two objects have a different shape
15
+ * @param {object} a
16
+ * @param {object} b
17
+ * @returns {boolean}
18
+ */
19
+ export function shallowDiffers(a, b) {
20
+ for (let i in a) if (i !== '__source' && !(i in b)) return true;
21
+ for (let i in b) if (i !== '__source' && a[i] !== b[i]) return true;
22
+ return false;
23
+ }
24
+
25
+ export function removeNode(node) {
26
+ let parentNode = node.parentNode;
27
+ if (parentNode) parentNode.removeChild(node);
28
+ }
@@ -1 +1 @@
1
- module.exports = require('preact/test-utils');
1
+ module.exports = require('preact/test-utils');