isomorfeus-preact 10.6.11 → 10.6.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/lib/browser/event.rb +2 -0
  3. data/lib/isomorfeus/preact_view_helper.rb +3 -2
  4. data/lib/isomorfeus/props/validate_hash_proxy.rb +1 -1
  5. data/lib/isomorfeus/props/validator.rb +6 -4
  6. data/lib/isomorfeus-preact.rb +3 -3
  7. data/lib/isomorfeus_preact/lucid_component/api.rb +1 -1
  8. data/lib/isomorfeus_preact/lucid_component/initializer.rb +2 -2
  9. data/lib/isomorfeus_preact/lucid_func/initializer.rb +1 -1
  10. data/lib/isomorfeus_preact/preact/function_component/initializer.rb +1 -1
  11. data/lib/preact/component/api.rb +1 -1
  12. data/lib/preact/component/callbacks.rb +6 -6
  13. data/lib/preact/component/initializer.rb +2 -2
  14. data/lib/preact/component/native_component_constructor.rb +1 -1
  15. data/lib/preact/props.rb +51 -0
  16. data/lib/preact/state.rb +67 -0
  17. data/lib/preact/version.rb +1 -1
  18. data/lib/preact.rb +2 -2
  19. data/node_modules/.package-lock.json +3 -3
  20. data/node_modules/preact/LICENSE +21 -21
  21. data/node_modules/preact/README.md +187 -187
  22. data/node_modules/preact/compat/dist/compat.js +1 -1
  23. data/node_modules/preact/compat/dist/compat.js.map +1 -1
  24. data/node_modules/preact/compat/dist/compat.mjs +1 -1
  25. data/node_modules/preact/compat/dist/compat.module.js +1 -1
  26. data/node_modules/preact/compat/dist/compat.module.js.map +1 -1
  27. data/node_modules/preact/compat/dist/compat.umd.js +1 -1
  28. data/node_modules/preact/compat/dist/compat.umd.js.map +1 -1
  29. data/node_modules/preact/compat/jsx-dev-runtime.js +1 -1
  30. data/node_modules/preact/compat/jsx-dev-runtime.mjs +1 -1
  31. data/node_modules/preact/compat/jsx-runtime.js +1 -1
  32. data/node_modules/preact/compat/jsx-runtime.mjs +1 -1
  33. data/node_modules/preact/compat/package.json +19 -19
  34. data/node_modules/preact/compat/scheduler.js +15 -15
  35. data/node_modules/preact/compat/scheduler.mjs +23 -23
  36. data/node_modules/preact/compat/server.js +15 -15
  37. data/node_modules/preact/compat/server.mjs +4 -4
  38. data/node_modules/preact/compat/src/Children.js +21 -21
  39. data/node_modules/preact/compat/src/PureComponent.js +15 -15
  40. data/node_modules/preact/compat/src/forwardRef.js +51 -51
  41. data/node_modules/preact/compat/src/index.d.ts +141 -141
  42. data/node_modules/preact/compat/src/index.js +187 -187
  43. data/node_modules/preact/compat/src/internal.d.ts +47 -47
  44. data/node_modules/preact/compat/src/memo.js +34 -34
  45. data/node_modules/preact/compat/src/portals.js +80 -80
  46. data/node_modules/preact/compat/src/render.js +229 -230
  47. data/node_modules/preact/compat/src/suspense-list.d.ts +14 -14
  48. data/node_modules/preact/compat/src/suspense-list.js +126 -126
  49. data/node_modules/preact/compat/src/suspense.d.ts +15 -15
  50. data/node_modules/preact/compat/src/suspense.js +270 -270
  51. data/node_modules/preact/compat/src/util.js +28 -28
  52. data/node_modules/preact/compat/test-utils.js +1 -1
  53. data/node_modules/preact/debug/dist/debug.js.map +1 -1
  54. data/node_modules/preact/debug/dist/debug.module.js.map +1 -1
  55. data/node_modules/preact/debug/dist/debug.umd.js.map +1 -1
  56. data/node_modules/preact/debug/package.json +18 -18
  57. data/node_modules/preact/debug/src/check-props.js +54 -54
  58. data/node_modules/preact/debug/src/component-stack.js +146 -146
  59. data/node_modules/preact/debug/src/constants.js +3 -3
  60. data/node_modules/preact/debug/src/debug.js +442 -442
  61. data/node_modules/preact/debug/src/index.js +6 -6
  62. data/node_modules/preact/debug/src/internal.d.ts +82 -82
  63. data/node_modules/preact/debug/src/util.js +11 -11
  64. data/node_modules/preact/devtools/dist/devtools.js +1 -1
  65. data/node_modules/preact/devtools/dist/devtools.js.map +1 -1
  66. data/node_modules/preact/devtools/dist/devtools.mjs +1 -1
  67. data/node_modules/preact/devtools/dist/devtools.module.js +1 -1
  68. data/node_modules/preact/devtools/dist/devtools.module.js.map +1 -1
  69. data/node_modules/preact/devtools/dist/devtools.umd.js +1 -1
  70. data/node_modules/preact/devtools/dist/devtools.umd.js.map +1 -1
  71. data/node_modules/preact/devtools/package.json +16 -16
  72. data/node_modules/preact/devtools/src/devtools.js +10 -10
  73. data/node_modules/preact/devtools/src/index.d.ts +8 -8
  74. data/node_modules/preact/devtools/src/index.js +15 -15
  75. data/node_modules/preact/dist/preact.js.map +1 -1
  76. data/node_modules/preact/dist/preact.min.js.map +1 -1
  77. data/node_modules/preact/dist/preact.module.js.map +1 -1
  78. data/node_modules/preact/dist/preact.umd.js.map +1 -1
  79. data/node_modules/preact/hooks/dist/hooks.js +1 -1
  80. data/node_modules/preact/hooks/dist/hooks.js.map +1 -1
  81. data/node_modules/preact/hooks/dist/hooks.mjs +1 -1
  82. data/node_modules/preact/hooks/dist/hooks.module.js +1 -1
  83. data/node_modules/preact/hooks/dist/hooks.module.js.map +1 -1
  84. data/node_modules/preact/hooks/dist/hooks.umd.js +1 -1
  85. data/node_modules/preact/hooks/dist/hooks.umd.js.map +1 -1
  86. data/node_modules/preact/hooks/package.json +26 -26
  87. data/node_modules/preact/hooks/src/index.d.ts +139 -139
  88. data/node_modules/preact/hooks/src/index.js +386 -388
  89. data/node_modules/preact/hooks/src/internal.d.ts +75 -75
  90. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js.map +1 -1
  91. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js.map +1 -1
  92. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js.map +1 -1
  93. data/node_modules/preact/jsx-runtime/package.json +19 -19
  94. data/node_modules/preact/jsx-runtime/src/index.d.ts +50 -50
  95. data/node_modules/preact/jsx-runtime/src/index.js +77 -77
  96. data/node_modules/preact/package.json +291 -287
  97. data/node_modules/preact/src/cjs.js +3 -3
  98. data/node_modules/preact/src/clone-element.js +34 -34
  99. data/node_modules/preact/src/component.js +225 -225
  100. data/node_modules/preact/src/constants.js +3 -3
  101. data/node_modules/preact/src/create-context.js +68 -68
  102. data/node_modules/preact/src/create-element.js +98 -98
  103. data/node_modules/preact/src/diff/catch-error.js +38 -38
  104. data/node_modules/preact/src/diff/children.js +335 -335
  105. data/node_modules/preact/src/diff/index.js +516 -516
  106. data/node_modules/preact/src/diff/props.js +158 -158
  107. data/node_modules/preact/src/index.d.ts +310 -310
  108. data/node_modules/preact/src/index.js +13 -13
  109. data/node_modules/preact/src/internal.d.ts +146 -146
  110. data/node_modules/preact/src/jsx.d.ts +1005 -1005
  111. data/node_modules/preact/src/options.js +16 -16
  112. data/node_modules/preact/src/render.js +75 -75
  113. data/node_modules/preact/src/util.js +27 -27
  114. data/node_modules/preact/test-utils/dist/testUtils.js.map +1 -1
  115. data/node_modules/preact/test-utils/dist/testUtils.module.js.map +1 -1
  116. data/node_modules/preact/test-utils/dist/testUtils.umd.js.map +1 -1
  117. data/node_modules/preact/test-utils/package.json +19 -19
  118. data/node_modules/preact/test-utils/src/index.d.ts +3 -3
  119. data/node_modules/preact/test-utils/src/index.js +117 -117
  120. data/package.json +1 -1
  121. metadata +8 -8
  122. data/lib/preact/component/props.rb +0 -55
  123. data/lib/preact/component/state.rb +0 -58
@@ -1,34 +1,34 @@
1
- import { assign, slice } from './util';
2
- import { createVNode } from './create-element';
3
-
4
- /**
5
- * Clones the given VNode, optionally adding attributes/props and replacing its children.
6
- * @param {import('./internal').VNode} vnode The virtual DOM element to clone
7
- * @param {object} props Attributes/props to add when cloning
8
- * @param {Array<import('./internal').ComponentChildren>} rest Any additional arguments will be used as replacement children.
9
- * @returns {import('./internal').VNode}
10
- */
11
- export function cloneElement(vnode, props, children) {
12
- let normalizedProps = assign({}, vnode.props),
13
- key,
14
- ref,
15
- i;
16
- for (i in props) {
17
- if (i == 'key') key = props[i];
18
- else if (i == 'ref') ref = props[i];
19
- else normalizedProps[i] = props[i];
20
- }
21
-
22
- if (arguments.length > 2) {
23
- normalizedProps.children =
24
- arguments.length > 3 ? slice.call(arguments, 2) : children;
25
- }
26
-
27
- return createVNode(
28
- vnode.type,
29
- normalizedProps,
30
- key || vnode.key,
31
- ref || vnode.ref,
32
- null
33
- );
34
- }
1
+ import { assign, slice } from './util';
2
+ import { createVNode } from './create-element';
3
+
4
+ /**
5
+ * Clones the given VNode, optionally adding attributes/props and replacing its children.
6
+ * @param {import('./internal').VNode} vnode The virtual DOM element to clone
7
+ * @param {object} props Attributes/props to add when cloning
8
+ * @param {Array<import('./internal').ComponentChildren>} rest Any additional arguments will be used as replacement children.
9
+ * @returns {import('./internal').VNode}
10
+ */
11
+ export function cloneElement(vnode, props, children) {
12
+ let normalizedProps = assign({}, vnode.props),
13
+ key,
14
+ ref,
15
+ i;
16
+ for (i in props) {
17
+ if (i == 'key') key = props[i];
18
+ else if (i == 'ref') ref = props[i];
19
+ else normalizedProps[i] = props[i];
20
+ }
21
+
22
+ if (arguments.length > 2) {
23
+ normalizedProps.children =
24
+ arguments.length > 3 ? slice.call(arguments, 2) : children;
25
+ }
26
+
27
+ return createVNode(
28
+ vnode.type,
29
+ normalizedProps,
30
+ key || vnode.key,
31
+ ref || vnode.ref,
32
+ null
33
+ );
34
+ }
@@ -1,225 +1,225 @@
1
- import { assign } from './util';
2
- import { diff, commitRoot } from './diff/index';
3
- import options from './options';
4
- import { Fragment } from './create-element';
5
-
6
- /**
7
- * Base Component class. Provides `setState()` and `forceUpdate()`, which
8
- * trigger rendering
9
- * @param {object} props The initial component props
10
- * @param {object} context The initial context from parent components'
11
- * getChildContext
12
- */
13
- export function Component(props, context) {
14
- this.props = props;
15
- this.context = context;
16
- }
17
-
18
- /**
19
- * Update component state and schedule a re-render.
20
- * @this {import('./internal').Component}
21
- * @param {object | ((s: object, p: object) => object)} update A hash of state
22
- * properties to update with new values or a function that given the current
23
- * state and props returns a new partial state
24
- * @param {() => void} [callback] A function to be called once component state is
25
- * updated
26
- */
27
- Component.prototype.setState = function(update, callback) {
28
- // only clone state when copying to nextState the first time.
29
- let s;
30
- if (this._nextState != null && this._nextState !== this.state) {
31
- s = this._nextState;
32
- } else {
33
- s = this._nextState = assign({}, this.state);
34
- }
35
-
36
- if (typeof update == 'function') {
37
- // Some libraries like `immer` mark the current state as readonly,
38
- // preventing us from mutating it, so we need to clone it. See #2716
39
- update = update(assign({}, s), this.props);
40
- }
41
-
42
- if (update) {
43
- assign(s, update);
44
- }
45
-
46
- // Skip update if updater function returned null
47
- if (update == null) return;
48
-
49
- if (this._vnode) {
50
- if (callback) this._renderCallbacks.push(callback);
51
- enqueueRender(this);
52
- }
53
- };
54
-
55
- /**
56
- * Immediately perform a synchronous re-render of the component
57
- * @this {import('./internal').Component}
58
- * @param {() => void} [callback] A function to be called after component is
59
- * re-rendered
60
- */
61
- Component.prototype.forceUpdate = function(callback) {
62
- if (this._vnode) {
63
- // Set render mode so that we can differentiate where the render request
64
- // is coming from. We need this because forceUpdate should never call
65
- // shouldComponentUpdate
66
- this._force = true;
67
- if (callback) this._renderCallbacks.push(callback);
68
- enqueueRender(this);
69
- }
70
- };
71
-
72
- /**
73
- * Accepts `props` and `state`, and returns a new Virtual DOM tree to build.
74
- * Virtual DOM is generally constructed via [JSX](http://jasonformat.com/wtf-is-jsx).
75
- * @param {object} props Props (eg: JSX attributes) received from parent
76
- * element/component
77
- * @param {object} state The component's current state
78
- * @param {object} context Context object, as returned by the nearest
79
- * ancestor's `getChildContext()`
80
- * @returns {import('./index').ComponentChildren | void}
81
- */
82
- Component.prototype.render = Fragment;
83
-
84
- /**
85
- * @param {import('./internal').VNode} vnode
86
- * @param {number | null} [childIndex]
87
- */
88
- export function getDomSibling(vnode, childIndex) {
89
- if (childIndex == null) {
90
- // Use childIndex==null as a signal to resume the search from the vnode's sibling
91
- return vnode._parent
92
- ? getDomSibling(vnode._parent, vnode._parent._children.indexOf(vnode) + 1)
93
- : null;
94
- }
95
-
96
- let sibling;
97
- for (; childIndex < vnode._children.length; childIndex++) {
98
- sibling = vnode._children[childIndex];
99
-
100
- if (sibling != null && sibling._dom != null) {
101
- // Since updateParentDomPointers keeps _dom pointer correct,
102
- // we can rely on _dom to tell us if this subtree contains a
103
- // rendered DOM node, and what the first rendered DOM node is
104
- return sibling._dom;
105
- }
106
- }
107
-
108
- // If we get here, we have not found a DOM node in this vnode's children.
109
- // We must resume from this vnode's sibling (in it's parent _children array)
110
- // Only climb up and search the parent if we aren't searching through a DOM
111
- // VNode (meaning we reached the DOM parent of the original vnode that began
112
- // the search)
113
- return typeof vnode.type == 'function' ? getDomSibling(vnode) : null;
114
- }
115
-
116
- /**
117
- * Trigger in-place re-rendering of a component.
118
- * @param {import('./internal').Component} component The component to rerender
119
- */
120
- function renderComponent(component) {
121
- let vnode = component._vnode,
122
- oldDom = vnode._dom,
123
- parentDom = component._parentDom;
124
-
125
- if (parentDom) {
126
- let commitQueue = [];
127
- const oldVNode = assign({}, vnode);
128
- oldVNode._original = vnode._original + 1;
129
-
130
- diff(
131
- parentDom,
132
- vnode,
133
- oldVNode,
134
- component._globalContext,
135
- parentDom.ownerSVGElement !== undefined,
136
- vnode._hydrating != null ? [oldDom] : null,
137
- commitQueue,
138
- oldDom == null ? getDomSibling(vnode) : oldDom,
139
- vnode._hydrating
140
- );
141
- commitRoot(commitQueue, vnode);
142
-
143
- if (vnode._dom != oldDom) {
144
- updateParentDomPointers(vnode);
145
- }
146
- }
147
- }
148
-
149
- /**
150
- * @param {import('./internal').VNode} vnode
151
- */
152
- function updateParentDomPointers(vnode) {
153
- if ((vnode = vnode._parent) != null && vnode._component != null) {
154
- vnode._dom = vnode._component.base = null;
155
- for (let i = 0; i < vnode._children.length; i++) {
156
- let child = vnode._children[i];
157
- if (child != null && child._dom != null) {
158
- vnode._dom = vnode._component.base = child._dom;
159
- break;
160
- }
161
- }
162
-
163
- return updateParentDomPointers(vnode);
164
- }
165
- }
166
-
167
- /**
168
- * The render queue
169
- * @type {Array<import('./internal').Component>}
170
- */
171
- let rerenderQueue = [];
172
-
173
- /**
174
- * Asynchronously schedule a callback
175
- * @type {(cb: () => void) => void}
176
- */
177
- /* istanbul ignore next */
178
- // Note the following line isn't tree-shaken by rollup cuz of rollup/rollup#2566
179
- const defer =
180
- typeof Promise == 'function'
181
- ? Promise.prototype.then.bind(Promise.resolve())
182
- : setTimeout;
183
-
184
- /*
185
- * The value of `Component.debounce` must asynchronously invoke the passed in callback. It is
186
- * important that contributors to Preact can consistently reason about what calls to `setState`, etc.
187
- * do, and when their effects will be applied. See the links below for some further reading on designing
188
- * asynchronous APIs.
189
- * * [Designing APIs for Asynchrony](https://blog.izs.me/2013/08/designing-apis-for-asynchrony)
190
- * * [Callbacks synchronous and asynchronous](https://blog.ometer.com/2011/07/24/callbacks-synchronous-and-asynchronous/)
191
- */
192
-
193
- let prevDebounce;
194
-
195
- /**
196
- * Enqueue a rerender of a component
197
- * @param {import('./internal').Component} c The component to rerender
198
- */
199
- export function enqueueRender(c) {
200
- if (
201
- (!c._dirty &&
202
- (c._dirty = true) &&
203
- rerenderQueue.push(c) &&
204
- !process._rerenderCount++) ||
205
- prevDebounce !== options.debounceRendering
206
- ) {
207
- prevDebounce = options.debounceRendering;
208
- (prevDebounce || defer)(process);
209
- }
210
- }
211
-
212
- /** Flush the render queue by rerendering all queued components */
213
- function process() {
214
- let queue;
215
- while ((process._rerenderCount = rerenderQueue.length)) {
216
- queue = rerenderQueue.sort((a, b) => a._vnode._depth - b._vnode._depth);
217
- rerenderQueue = [];
218
- // Don't update `renderCount` yet. Keep its value non-zero to prevent unnecessary
219
- // process() calls from getting scheduled while `queue` is still being consumed.
220
- queue.some(c => {
221
- if (c._dirty) renderComponent(c);
222
- });
223
- }
224
- }
225
- process._rerenderCount = 0;
1
+ import { assign } from './util';
2
+ import { diff, commitRoot } from './diff/index';
3
+ import options from './options';
4
+ import { Fragment } from './create-element';
5
+
6
+ /**
7
+ * Base Component class. Provides `setState()` and `forceUpdate()`, which
8
+ * trigger rendering
9
+ * @param {object} props The initial component props
10
+ * @param {object} context The initial context from parent components'
11
+ * getChildContext
12
+ */
13
+ export function Component(props, context) {
14
+ this.props = props;
15
+ this.context = context;
16
+ }
17
+
18
+ /**
19
+ * Update component state and schedule a re-render.
20
+ * @this {import('./internal').Component}
21
+ * @param {object | ((s: object, p: object) => object)} update A hash of state
22
+ * properties to update with new values or a function that given the current
23
+ * state and props returns a new partial state
24
+ * @param {() => void} [callback] A function to be called once component state is
25
+ * updated
26
+ */
27
+ Component.prototype.setState = function(update, callback) {
28
+ // only clone state when copying to nextState the first time.
29
+ let s;
30
+ if (this._nextState != null && this._nextState !== this.state) {
31
+ s = this._nextState;
32
+ } else {
33
+ s = this._nextState = assign({}, this.state);
34
+ }
35
+
36
+ if (typeof update == 'function') {
37
+ // Some libraries like `immer` mark the current state as readonly,
38
+ // preventing us from mutating it, so we need to clone it. See #2716
39
+ update = update(assign({}, s), this.props);
40
+ }
41
+
42
+ if (update) {
43
+ assign(s, update);
44
+ }
45
+
46
+ // Skip update if updater function returned null
47
+ if (update == null) return;
48
+
49
+ if (this._vnode) {
50
+ if (callback) this._renderCallbacks.push(callback);
51
+ enqueueRender(this);
52
+ }
53
+ };
54
+
55
+ /**
56
+ * Immediately perform a synchronous re-render of the component
57
+ * @this {import('./internal').Component}
58
+ * @param {() => void} [callback] A function to be called after component is
59
+ * re-rendered
60
+ */
61
+ Component.prototype.forceUpdate = function(callback) {
62
+ if (this._vnode) {
63
+ // Set render mode so that we can differentiate where the render request
64
+ // is coming from. We need this because forceUpdate should never call
65
+ // shouldComponentUpdate
66
+ this._force = true;
67
+ if (callback) this._renderCallbacks.push(callback);
68
+ enqueueRender(this);
69
+ }
70
+ };
71
+
72
+ /**
73
+ * Accepts `props` and `state`, and returns a new Virtual DOM tree to build.
74
+ * Virtual DOM is generally constructed via [JSX](http://jasonformat.com/wtf-is-jsx).
75
+ * @param {object} props Props (eg: JSX attributes) received from parent
76
+ * element/component
77
+ * @param {object} state The component's current state
78
+ * @param {object} context Context object, as returned by the nearest
79
+ * ancestor's `getChildContext()`
80
+ * @returns {import('./index').ComponentChildren | void}
81
+ */
82
+ Component.prototype.render = Fragment;
83
+
84
+ /**
85
+ * @param {import('./internal').VNode} vnode
86
+ * @param {number | null} [childIndex]
87
+ */
88
+ export function getDomSibling(vnode, childIndex) {
89
+ if (childIndex == null) {
90
+ // Use childIndex==null as a signal to resume the search from the vnode's sibling
91
+ return vnode._parent
92
+ ? getDomSibling(vnode._parent, vnode._parent._children.indexOf(vnode) + 1)
93
+ : null;
94
+ }
95
+
96
+ let sibling;
97
+ for (; childIndex < vnode._children.length; childIndex++) {
98
+ sibling = vnode._children[childIndex];
99
+
100
+ if (sibling != null && sibling._dom != null) {
101
+ // Since updateParentDomPointers keeps _dom pointer correct,
102
+ // we can rely on _dom to tell us if this subtree contains a
103
+ // rendered DOM node, and what the first rendered DOM node is
104
+ return sibling._dom;
105
+ }
106
+ }
107
+
108
+ // If we get here, we have not found a DOM node in this vnode's children.
109
+ // We must resume from this vnode's sibling (in it's parent _children array)
110
+ // Only climb up and search the parent if we aren't searching through a DOM
111
+ // VNode (meaning we reached the DOM parent of the original vnode that began
112
+ // the search)
113
+ return typeof vnode.type == 'function' ? getDomSibling(vnode) : null;
114
+ }
115
+
116
+ /**
117
+ * Trigger in-place re-rendering of a component.
118
+ * @param {import('./internal').Component} component The component to rerender
119
+ */
120
+ function renderComponent(component) {
121
+ let vnode = component._vnode,
122
+ oldDom = vnode._dom,
123
+ parentDom = component._parentDom;
124
+
125
+ if (parentDom) {
126
+ let commitQueue = [];
127
+ const oldVNode = assign({}, vnode);
128
+ oldVNode._original = vnode._original + 1;
129
+
130
+ diff(
131
+ parentDom,
132
+ vnode,
133
+ oldVNode,
134
+ component._globalContext,
135
+ parentDom.ownerSVGElement !== undefined,
136
+ vnode._hydrating != null ? [oldDom] : null,
137
+ commitQueue,
138
+ oldDom == null ? getDomSibling(vnode) : oldDom,
139
+ vnode._hydrating
140
+ );
141
+ commitRoot(commitQueue, vnode);
142
+
143
+ if (vnode._dom != oldDom) {
144
+ updateParentDomPointers(vnode);
145
+ }
146
+ }
147
+ }
148
+
149
+ /**
150
+ * @param {import('./internal').VNode} vnode
151
+ */
152
+ function updateParentDomPointers(vnode) {
153
+ if ((vnode = vnode._parent) != null && vnode._component != null) {
154
+ vnode._dom = vnode._component.base = null;
155
+ for (let i = 0; i < vnode._children.length; i++) {
156
+ let child = vnode._children[i];
157
+ if (child != null && child._dom != null) {
158
+ vnode._dom = vnode._component.base = child._dom;
159
+ break;
160
+ }
161
+ }
162
+
163
+ return updateParentDomPointers(vnode);
164
+ }
165
+ }
166
+
167
+ /**
168
+ * The render queue
169
+ * @type {Array<import('./internal').Component>}
170
+ */
171
+ let rerenderQueue = [];
172
+
173
+ /**
174
+ * Asynchronously schedule a callback
175
+ * @type {(cb: () => void) => void}
176
+ */
177
+ /* istanbul ignore next */
178
+ // Note the following line isn't tree-shaken by rollup cuz of rollup/rollup#2566
179
+ const defer =
180
+ typeof Promise == 'function'
181
+ ? Promise.prototype.then.bind(Promise.resolve())
182
+ : setTimeout;
183
+
184
+ /*
185
+ * The value of `Component.debounce` must asynchronously invoke the passed in callback. It is
186
+ * important that contributors to Preact can consistently reason about what calls to `setState`, etc.
187
+ * do, and when their effects will be applied. See the links below for some further reading on designing
188
+ * asynchronous APIs.
189
+ * * [Designing APIs for Asynchrony](https://blog.izs.me/2013/08/designing-apis-for-asynchrony)
190
+ * * [Callbacks synchronous and asynchronous](https://blog.ometer.com/2011/07/24/callbacks-synchronous-and-asynchronous/)
191
+ */
192
+
193
+ let prevDebounce;
194
+
195
+ /**
196
+ * Enqueue a rerender of a component
197
+ * @param {import('./internal').Component} c The component to rerender
198
+ */
199
+ export function enqueueRender(c) {
200
+ if (
201
+ (!c._dirty &&
202
+ (c._dirty = true) &&
203
+ rerenderQueue.push(c) &&
204
+ !process._rerenderCount++) ||
205
+ prevDebounce !== options.debounceRendering
206
+ ) {
207
+ prevDebounce = options.debounceRendering;
208
+ (prevDebounce || defer)(process);
209
+ }
210
+ }
211
+
212
+ /** Flush the render queue by rerendering all queued components */
213
+ function process() {
214
+ let queue;
215
+ while ((process._rerenderCount = rerenderQueue.length)) {
216
+ queue = rerenderQueue.sort((a, b) => a._vnode._depth - b._vnode._depth);
217
+ rerenderQueue = [];
218
+ // Don't update `renderCount` yet. Keep its value non-zero to prevent unnecessary
219
+ // process() calls from getting scheduled while `queue` is still being consumed.
220
+ queue.some(c => {
221
+ if (c._dirty) renderComponent(c);
222
+ });
223
+ }
224
+ }
225
+ process._rerenderCount = 0;
@@ -1,3 +1,3 @@
1
- export const EMPTY_OBJ = {};
2
- export const EMPTY_ARR = [];
3
- export const IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;
1
+ export const EMPTY_OBJ = {};
2
+ export const EMPTY_ARR = [];
3
+ export const IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;
@@ -1,68 +1,68 @@
1
- import { enqueueRender } from './component';
2
-
3
- export let i = 0;
4
-
5
- export function createContext(defaultValue, contextId) {
6
- contextId = '__cC' + i++;
7
-
8
- const context = {
9
- _id: contextId,
10
- _defaultValue: defaultValue,
11
- /** @type {import('./internal').FunctionComponent} */
12
- Consumer(props, contextValue) {
13
- // return props.children(
14
- // context[contextId] ? context[contextId].props.value : defaultValue
15
- // );
16
- return props.children(contextValue);
17
- },
18
- /** @type {import('./internal').FunctionComponent} */
19
- Provider(props) {
20
- if (!this.getChildContext) {
21
- let subs = [];
22
- let ctx = {};
23
- ctx[contextId] = this;
24
-
25
- this.getChildContext = () => ctx;
26
-
27
- this.shouldComponentUpdate = function(_props) {
28
- if (this.props.value !== _props.value) {
29
- // I think the forced value propagation here was only needed when `options.debounceRendering` was being bypassed:
30
- // https://github.com/preactjs/preact/commit/4d339fb803bea09e9f198abf38ca1bf8ea4b7771#diff-54682ce380935a717e41b8bfc54737f6R358
31
- // In those cases though, even with the value corrected, we're double-rendering all nodes.
32
- // It might be better to just tell folks not to use force-sync mode.
33
- // Currently, using `useContext()` in a class component will overwrite its `this.context` value.
34
- // subs.some(c => {
35
- // c.context = _props.value;
36
- // enqueueRender(c);
37
- // });
38
-
39
- // subs.some(c => {
40
- // c.context[contextId] = _props.value;
41
- // enqueueRender(c);
42
- // });
43
- subs.some(enqueueRender);
44
- }
45
- };
46
-
47
- this.sub = c => {
48
- subs.push(c);
49
- let old = c.componentWillUnmount;
50
- c.componentWillUnmount = () => {
51
- subs.splice(subs.indexOf(c), 1);
52
- if (old) old.call(c);
53
- };
54
- };
55
- }
56
-
57
- return props.children;
58
- }
59
- };
60
-
61
- // Devtools needs access to the context object when it
62
- // encounters a Provider. This is necessary to support
63
- // setting `displayName` on the context object instead
64
- // of on the component itself. See:
65
- // https://reactjs.org/docs/context.html#contextdisplayname
66
-
67
- return (context.Provider._contextRef = context.Consumer.contextType = context);
68
- }
1
+ import { enqueueRender } from './component';
2
+
3
+ export let i = 0;
4
+
5
+ export function createContext(defaultValue, contextId) {
6
+ contextId = '__cC' + i++;
7
+
8
+ const context = {
9
+ _id: contextId,
10
+ _defaultValue: defaultValue,
11
+ /** @type {import('./internal').FunctionComponent} */
12
+ Consumer(props, contextValue) {
13
+ // return props.children(
14
+ // context[contextId] ? context[contextId].props.value : defaultValue
15
+ // );
16
+ return props.children(contextValue);
17
+ },
18
+ /** @type {import('./internal').FunctionComponent} */
19
+ Provider(props) {
20
+ if (!this.getChildContext) {
21
+ let subs = [];
22
+ let ctx = {};
23
+ ctx[contextId] = this;
24
+
25
+ this.getChildContext = () => ctx;
26
+
27
+ this.shouldComponentUpdate = function(_props) {
28
+ if (this.props.value !== _props.value) {
29
+ // I think the forced value propagation here was only needed when `options.debounceRendering` was being bypassed:
30
+ // https://github.com/preactjs/preact/commit/4d339fb803bea09e9f198abf38ca1bf8ea4b7771#diff-54682ce380935a717e41b8bfc54737f6R358
31
+ // In those cases though, even with the value corrected, we're double-rendering all nodes.
32
+ // It might be better to just tell folks not to use force-sync mode.
33
+ // Currently, using `useContext()` in a class component will overwrite its `this.context` value.
34
+ // subs.some(c => {
35
+ // c.context = _props.value;
36
+ // enqueueRender(c);
37
+ // });
38
+
39
+ // subs.some(c => {
40
+ // c.context[contextId] = _props.value;
41
+ // enqueueRender(c);
42
+ // });
43
+ subs.some(enqueueRender);
44
+ }
45
+ };
46
+
47
+ this.sub = c => {
48
+ subs.push(c);
49
+ let old = c.componentWillUnmount;
50
+ c.componentWillUnmount = () => {
51
+ subs.splice(subs.indexOf(c), 1);
52
+ if (old) old.call(c);
53
+ };
54
+ };
55
+ }
56
+
57
+ return props.children;
58
+ }
59
+ };
60
+
61
+ // Devtools needs access to the context object when it
62
+ // encounters a Provider. This is necessary to support
63
+ // setting `displayName` on the context object instead
64
+ // of on the component itself. See:
65
+ // https://reactjs.org/docs/context.html#contextdisplayname
66
+
67
+ return (context.Provider._contextRef = context.Consumer.contextType = context);
68
+ }