-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path@preact__signals.patch
160 lines (150 loc) · 4.87 KB
/
@preact__signals.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
diff --git a/package.json b/package.json
index 686b1d1e29ae667baeb5bfc4cf2f52bed1b6202d..bbc57073ca848c265f80c21072bbccdcd0087cf6 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,6 @@
{
"name": "@preact/signals",
+ "type": "module",
"version": "2.0.0",
"license": "MIT",
"description": "Manage state with style in Preact",
@@ -18,18 +19,12 @@
"type": "opencollective",
"url": "https://opencollective.com/preact"
},
- "amdName": "preactSignals",
- "main": "dist/signals.js",
- "module": "dist/signals.module.js",
- "unpkg": "dist/signals.min.js",
- "types": "dist/signals.d.ts",
- "source": "src/index.ts",
"exports": {
".": {
- "types": "./dist/signals.d.ts",
- "browser": "./dist/signals.module.js",
- "import": "./dist/signals.mjs",
- "require": "./dist/signals.js"
+ "node": "./dist/signals.module.js",
+ "browser": "./src/index.ts",
+ "production": "./src/index.ts",
+ "types": "./src/index.ts"
}
},
"mangle": "../../mangle.json",
diff --git a/src/index.ts b/src/index.ts
index cc24fd5179a6f35c8bbafdcac669ad9153f69028..ba1d22140843d541391f8c36626e89e30c905136 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -9,15 +9,17 @@ import {
type ReadonlySignal,
untracked,
} from "@preact/signals-core";
-import {
+import type {
VNode,
- OptionsTypes,
HookFn,
Effect,
PropertyUpdater,
AugmentedComponent,
AugmentedElement as Element,
-} from "./internal";
+} from "./internal.d.ts";
+// @ts-expect-error there is a runtime value (an enum)
+// being imported from a declaration file
+import { OptionsTypes } from "./internal.d.ts"
export {
signal,
@@ -82,10 +84,10 @@ function SignalValue(this: AugmentedComponent, { data }: { data: Signal }) {
const s = useMemo(() => {
let self = this;
// mark the parent component as having computeds so it gets optimized
- let v = this.__v;
- while ((v = v.__!)) {
- if (v.__c) {
- v.__c._updateFlags |= HAS_COMPUTEDS;
+ let v = this._vnode;
+ while ((v = v._parent!)) {
+ if (v._component) {
+ v._component._updateFlags |= HAS_COMPUTEDS;
break;
}
}
@@ -137,7 +139,7 @@ Object.defineProperties(Signal.prototype, {
// Setting a VNode's _depth to 1 forces Preact to clone it before modifying:
// https://github.com/preactjs/preact/blob/d7a433ee8463a7dc23a05111bb47de9ec729ad4d/src/diff/children.js#L77
// @todo remove this for Preact 11
- __b: { configurable: true, value: 1 },
+ _depth: { configurable: true, value: 1 },
});
/** Inject low-level property/attribute bindings for Signals into Preact's diff */
@@ -167,7 +169,7 @@ hook(OptionsTypes.RENDER, (old, vnode) => {
let updater;
- let component = vnode.__c;
+ let component = vnode._component;
if (component) {
component._updateFlags &= ~HAS_PENDING_UPDATE;
@@ -201,7 +203,7 @@ hook(OptionsTypes.DIFFED, (old, vnode) => {
// vnode._dom is undefined during string rendering,
// so we use this to skip prop subscriptions during SSR.
- if (typeof vnode.type === "string" && (dom = vnode.__e as Element)) {
+ if (typeof vnode.type === "string" && (dom = vnode._dom as Element)) {
let props = vnode.__np;
let renderedProps = vnode.props;
if (props) {
@@ -275,7 +277,7 @@ function createPropUpdater(
/** Unsubscribe from Signals when unmounting components/vnodes */
hook(OptionsTypes.UNMOUNT, (old, vnode: VNode) => {
if (typeof vnode.type === "string") {
- let dom = vnode.__e as Element | undefined;
+ let dom = vnode._dom as Element | undefined;
// vnode._dom is undefined during string rendering
if (dom) {
const updaters = dom._updaters;
@@ -288,7 +290,7 @@ hook(OptionsTypes.UNMOUNT, (old, vnode: VNode) => {
}
}
} else {
- let component = vnode.__c;
+ let component = vnode._component;
if (component) {
const updater = component._updater;
if (updater) {
diff --git a/src/internal.d.ts b/src/internal.d.ts
index 7fe89290fc040c505549fa349ad186387c8dcd55..75454075766aaf4217c07fc79357e1fda56577f8 100644
--- a/src/internal.d.ts
+++ b/src/internal.d.ts
@@ -19,28 +19,28 @@ export interface AugmentedElement extends HTMLElement {
}
export interface AugmentedComponent extends Component<any, any> {
- __v: VNode;
+ _vnode: VNode;
_updater?: Effect;
_updateFlags: number;
}
export interface VNode<P = any> extends preact.VNode<P> {
/** The component instance for this VNode */
- __c: AugmentedComponent;
+ _component: AugmentedComponent;
/** The parent VNode */
- __?: VNode;
+ _parent?: VNode;
/** The DOM node for this VNode */
- __e?: Element | Text;
+ _dom?: Element | Text;
/** Props that had Signal values before diffing (used after diffing to subscribe) */
__np?: Record<string, any> | null;
}
export const enum OptionsTypes {
- HOOK = "__h",
- DIFF = "__b",
+ HOOK = "_hook",
+ DIFF = "_diff",
DIFFED = "diffed",
- RENDER = "__r",
- CATCH_ERROR = "__e",
+ RENDER = "_render",
+ CATCH_ERROR = "_catchError",
UNMOUNT = "unmount",
}