@simpreact/simpreact 0.0.4 → 0.0.5
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/compat/core.js +5 -4
- package/core/mounting.js +0 -3
- package/core/patching.js +0 -3
- package/hooks/index.js +14 -14
- package/package.json +1 -1
package/compat/core.js
CHANGED
|
@@ -50,13 +50,14 @@ export function isValidElement(element) {
|
|
|
50
50
|
export function Suspense(props) {
|
|
51
51
|
const [isSuspended, setIsSuspended] = SimpReactHooks.useState(false);
|
|
52
52
|
SimpReactHooks.useCatch(error => {
|
|
53
|
+
if (!(error instanceof Promise)) {
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
53
56
|
if (isSuspended) {
|
|
54
57
|
return;
|
|
55
58
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
error.then(() => setIsSuspended(false));
|
|
59
|
-
}
|
|
59
|
+
setIsSuspended(true);
|
|
60
|
+
error.then(() => setIsSuspended(false));
|
|
60
61
|
});
|
|
61
62
|
return isSuspended ? props.fallback : props.children;
|
|
62
63
|
}
|
package/core/mounting.js
CHANGED
|
@@ -3,7 +3,6 @@ import { hostAdapter } from './hostAdapter.js';
|
|
|
3
3
|
import { createTextElement, normalizeRoot } from './createElement.js';
|
|
4
4
|
import { applyRef } from './ref.js';
|
|
5
5
|
import { lifecycleEventBus } from './lifecycleEventBus.js';
|
|
6
|
-
import { batchingRerenderLocker } from './rerender.js';
|
|
7
6
|
export function mount(element, parentReference, nextReference, context, hostNamespace) {
|
|
8
7
|
if (element.flag === 'TEXT') {
|
|
9
8
|
mountTextElement(element, parentReference, nextReference);
|
|
@@ -84,9 +83,7 @@ export function mountFunctionalElement(element, parentReference, nextReference,
|
|
|
84
83
|
throw new Error('Too many re-renders.');
|
|
85
84
|
}
|
|
86
85
|
lifecycleEventBus.publish({ type: 'beforeRender', element, phase: 'mounting' });
|
|
87
|
-
batchingRerenderLocker.lock();
|
|
88
86
|
children = element.type(element.props || emptyObject);
|
|
89
|
-
batchingRerenderLocker.flush();
|
|
90
87
|
lifecycleEventBus.publish({ type: 'afterRender', element, phase: 'mounting' });
|
|
91
88
|
} while (triedToRerender);
|
|
92
89
|
children = normalizeRoot(children, false);
|
package/core/patching.js
CHANGED
|
@@ -5,7 +5,6 @@ import { clearElementHostReference, remove, unmount } from './unmounting.js';
|
|
|
5
5
|
import { mount, mountArrayChildren, mountFunctionalElement } from './mounting.js';
|
|
6
6
|
import { applyRef } from './ref.js';
|
|
7
7
|
import { lifecycleEventBus } from './lifecycleEventBus.js';
|
|
8
|
-
import { batchingRerenderLocker } from './rerender.js';
|
|
9
8
|
import { isMemo } from './memo.js';
|
|
10
9
|
export function patch(prevElement, nextElement, parentReference, nextReference, context, hostNamespace) {
|
|
11
10
|
if (prevElement.type !== nextElement.type || prevElement.key !== nextElement.key) {
|
|
@@ -90,9 +89,7 @@ function patchFunctionalComponent(prevElement, nextElement, parentReference, nex
|
|
|
90
89
|
throw new Error('Too many re-renders.');
|
|
91
90
|
}
|
|
92
91
|
lifecycleEventBus.publish({ type: 'beforeRender', element: nextElement, phase: 'updating' });
|
|
93
|
-
batchingRerenderLocker.lock();
|
|
94
92
|
nextChildren = nextElement.type(nextElement.props || emptyObject);
|
|
95
|
-
batchingRerenderLocker.flush();
|
|
96
93
|
lifecycleEventBus.publish({ type: 'afterRender', element: nextElement, phase: 'updating' });
|
|
97
94
|
} while (triedToRerender);
|
|
98
95
|
nextChildren = normalizeRoot(nextChildren, false);
|
package/hooks/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { lifecycleEventBus, rerender as _rerender } from '../core/internal.js';
|
|
2
2
|
import { callOrGet, noop } from '../shared/index.js';
|
|
3
3
|
let currentIndex = 0;
|
|
4
4
|
// In runtime this is a nullable variable.
|
|
@@ -20,19 +20,16 @@ lifecycleEventBus.subscribe(event => {
|
|
|
20
20
|
if (event.type === 'mounted') {
|
|
21
21
|
const element = event.element;
|
|
22
22
|
if (element.store?.effectsHookStates) {
|
|
23
|
-
batchingRerenderLocker.lock();
|
|
24
23
|
const effects = element.store.effectsHookStates;
|
|
25
24
|
element.store.effectsHookStates = undefined;
|
|
26
25
|
for (const state of effects) {
|
|
27
26
|
state.cleanup = state.effect() || undefined;
|
|
28
27
|
}
|
|
29
|
-
batchingRerenderLocker.flush();
|
|
30
28
|
}
|
|
31
29
|
}
|
|
32
30
|
if (event.type === 'updated') {
|
|
33
31
|
const element = event.element;
|
|
34
32
|
if (element.store?.effectsHookStates) {
|
|
35
|
-
batchingRerenderLocker.lock();
|
|
36
33
|
const effects = element.store.effectsHookStates;
|
|
37
34
|
element.store.effectsHookStates = undefined;
|
|
38
35
|
for (const state of effects) {
|
|
@@ -41,7 +38,6 @@ lifecycleEventBus.subscribe(event => {
|
|
|
41
38
|
}
|
|
42
39
|
state.cleanup = state.effect() || undefined;
|
|
43
40
|
}
|
|
44
|
-
batchingRerenderLocker.flush();
|
|
45
41
|
}
|
|
46
42
|
}
|
|
47
43
|
if (event.type === 'unmounted') {
|
|
@@ -57,17 +53,21 @@ lifecycleEventBus.subscribe(event => {
|
|
|
57
53
|
}
|
|
58
54
|
}
|
|
59
55
|
if (event.type === 'errored') {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
56
|
+
function handleError(element, error) {
|
|
57
|
+
element = findElementWithCatchHandlers(element);
|
|
58
|
+
if (!element) {
|
|
59
|
+
throw new Error('Error occurred during rendering a component', { cause: error });
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
for (const state of element.store.catchHandlers) {
|
|
63
|
+
state(error);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
handleError(element.parent, error);
|
|
68
68
|
}
|
|
69
|
-
batchingRerenderLocker.flush();
|
|
70
69
|
}
|
|
70
|
+
handleError(event.element, event.error);
|
|
71
71
|
}
|
|
72
72
|
});
|
|
73
73
|
function findElementWithCatchHandlers(element) {
|