@solidjs/universal 2.0.0-experimental.14 → 2.0.0-experimental.16
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/dist/dev.cjs +21 -9
- package/dist/dev.js +22 -10
- package/dist/universal.cjs +21 -9
- package/dist/universal.js +22 -10
- package/package.json +3 -3
- package/types/index.d.ts +30 -0
package/dist/dev.cjs
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var solidJs = require('solid-js');
|
|
4
4
|
|
|
5
|
+
const effect = (fn, effectFn, initial) => solidJs.createRenderEffect(fn, effectFn, initial, {
|
|
6
|
+
transparent: true
|
|
7
|
+
});
|
|
5
8
|
const memo = fn => solidJs.createMemo(() => fn());
|
|
6
9
|
|
|
7
10
|
function createRenderer({
|
|
@@ -23,7 +26,7 @@ function createRenderer({
|
|
|
23
26
|
accessor = normalize(accessor, multi, true);
|
|
24
27
|
if (typeof accessor !== "function") return insertExpression(parent, accessor, initial, marker);
|
|
25
28
|
}
|
|
26
|
-
|
|
29
|
+
effect(() => normalize(accessor, multi), (value, current) => insertExpression(parent, value, current, marker), initial);
|
|
27
30
|
}
|
|
28
31
|
function insertExpression(parent, value, current, marker) {
|
|
29
32
|
if (value === current) return;
|
|
@@ -71,7 +74,7 @@ function createRenderer({
|
|
|
71
74
|
for (let i = 0, len = value.length; i < len; i++) {
|
|
72
75
|
const item = value[i],
|
|
73
76
|
t = typeof item;
|
|
74
|
-
if (t === "string" || t === "number") value[i] =
|
|
77
|
+
if (t === "string" || t === "number") value[i] = createTextNode(item);
|
|
75
78
|
}
|
|
76
79
|
}
|
|
77
80
|
return value;
|
|
@@ -161,13 +164,16 @@ function createRenderer({
|
|
|
161
164
|
const prevProps = {};
|
|
162
165
|
props || (props = {});
|
|
163
166
|
if (!skipChildren) {
|
|
164
|
-
|
|
167
|
+
effect(() => normalize(props.children), value => {
|
|
165
168
|
insertExpression(node, value, prevProps.children);
|
|
166
169
|
prevProps.children = value;
|
|
167
170
|
});
|
|
168
171
|
}
|
|
169
|
-
|
|
170
|
-
|
|
172
|
+
effect(() => {
|
|
173
|
+
const r = props.ref;
|
|
174
|
+
(typeof r === "function" || Array.isArray(r)) && ref(() => r, node);
|
|
175
|
+
}, () => {});
|
|
176
|
+
effect(() => {
|
|
171
177
|
const newProps = {};
|
|
172
178
|
for (const prop in props) {
|
|
173
179
|
if (prop === "children" || prop === "ref") continue;
|
|
@@ -185,6 +191,13 @@ function createRenderer({
|
|
|
185
191
|
});
|
|
186
192
|
return prevProps;
|
|
187
193
|
}
|
|
194
|
+
function applyRef(r, element) {
|
|
195
|
+
Array.isArray(r) ? r.flat(Infinity).forEach(f => f && f(element)) : r(element);
|
|
196
|
+
}
|
|
197
|
+
function ref(fn, element) {
|
|
198
|
+
const resolved = solidJs.untrack(fn);
|
|
199
|
+
solidJs.runWithOwner(null, () => applyRef(resolved, element));
|
|
200
|
+
}
|
|
188
201
|
return {
|
|
189
202
|
render(code, element) {
|
|
190
203
|
let disposer;
|
|
@@ -204,12 +217,11 @@ function createRenderer({
|
|
|
204
217
|
return value;
|
|
205
218
|
},
|
|
206
219
|
mergeProps: solidJs.merge,
|
|
207
|
-
effect
|
|
220
|
+
effect,
|
|
208
221
|
memo,
|
|
209
222
|
createComponent: solidJs.createComponent,
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
223
|
+
applyRef,
|
|
224
|
+
ref
|
|
213
225
|
};
|
|
214
226
|
}
|
|
215
227
|
|
package/dist/dev.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { createMemo,
|
|
1
|
+
import { createMemo, createRenderEffect, createComponent, merge, createRoot, flatten, untrack, runWithOwner } from 'solid-js';
|
|
2
2
|
|
|
3
|
+
const effect = (fn, effectFn, initial) => createRenderEffect(fn, effectFn, initial, {
|
|
4
|
+
transparent: true
|
|
5
|
+
});
|
|
3
6
|
const memo = fn => createMemo(() => fn());
|
|
4
7
|
|
|
5
8
|
function createRenderer({
|
|
@@ -21,7 +24,7 @@ function createRenderer({
|
|
|
21
24
|
accessor = normalize(accessor, multi, true);
|
|
22
25
|
if (typeof accessor !== "function") return insertExpression(parent, accessor, initial, marker);
|
|
23
26
|
}
|
|
24
|
-
|
|
27
|
+
effect(() => normalize(accessor, multi), (value, current) => insertExpression(parent, value, current, marker), initial);
|
|
25
28
|
}
|
|
26
29
|
function insertExpression(parent, value, current, marker) {
|
|
27
30
|
if (value === current) return;
|
|
@@ -69,7 +72,7 @@ function createRenderer({
|
|
|
69
72
|
for (let i = 0, len = value.length; i < len; i++) {
|
|
70
73
|
const item = value[i],
|
|
71
74
|
t = typeof item;
|
|
72
|
-
if (t === "string" || t === "number") value[i] =
|
|
75
|
+
if (t === "string" || t === "number") value[i] = createTextNode(item);
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
78
|
return value;
|
|
@@ -159,13 +162,16 @@ function createRenderer({
|
|
|
159
162
|
const prevProps = {};
|
|
160
163
|
props || (props = {});
|
|
161
164
|
if (!skipChildren) {
|
|
162
|
-
|
|
165
|
+
effect(() => normalize(props.children), value => {
|
|
163
166
|
insertExpression(node, value, prevProps.children);
|
|
164
167
|
prevProps.children = value;
|
|
165
168
|
});
|
|
166
169
|
}
|
|
167
|
-
|
|
168
|
-
|
|
170
|
+
effect(() => {
|
|
171
|
+
const r = props.ref;
|
|
172
|
+
(typeof r === "function" || Array.isArray(r)) && ref(() => r, node);
|
|
173
|
+
}, () => {});
|
|
174
|
+
effect(() => {
|
|
169
175
|
const newProps = {};
|
|
170
176
|
for (const prop in props) {
|
|
171
177
|
if (prop === "children" || prop === "ref") continue;
|
|
@@ -183,6 +189,13 @@ function createRenderer({
|
|
|
183
189
|
});
|
|
184
190
|
return prevProps;
|
|
185
191
|
}
|
|
192
|
+
function applyRef(r, element) {
|
|
193
|
+
Array.isArray(r) ? r.flat(Infinity).forEach(f => f && f(element)) : r(element);
|
|
194
|
+
}
|
|
195
|
+
function ref(fn, element) {
|
|
196
|
+
const resolved = untrack(fn);
|
|
197
|
+
runWithOwner(null, () => applyRef(resolved, element));
|
|
198
|
+
}
|
|
186
199
|
return {
|
|
187
200
|
render(code, element) {
|
|
188
201
|
let disposer;
|
|
@@ -202,12 +215,11 @@ function createRenderer({
|
|
|
202
215
|
return value;
|
|
203
216
|
},
|
|
204
217
|
mergeProps: merge,
|
|
205
|
-
effect
|
|
218
|
+
effect,
|
|
206
219
|
memo,
|
|
207
220
|
createComponent,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
221
|
+
applyRef,
|
|
222
|
+
ref
|
|
211
223
|
};
|
|
212
224
|
}
|
|
213
225
|
|
package/dist/universal.cjs
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var solidJs = require('solid-js');
|
|
4
4
|
|
|
5
|
+
const effect = (fn, effectFn, initial) => solidJs.createRenderEffect(fn, effectFn, initial, {
|
|
6
|
+
transparent: true
|
|
7
|
+
});
|
|
5
8
|
const memo = fn => solidJs.createMemo(() => fn());
|
|
6
9
|
|
|
7
10
|
function createRenderer({
|
|
@@ -23,7 +26,7 @@ function createRenderer({
|
|
|
23
26
|
accessor = normalize(accessor, multi, true);
|
|
24
27
|
if (typeof accessor !== "function") return insertExpression(parent, accessor, initial, marker);
|
|
25
28
|
}
|
|
26
|
-
|
|
29
|
+
effect(() => normalize(accessor, multi), (value, current) => insertExpression(parent, value, current, marker), initial);
|
|
27
30
|
}
|
|
28
31
|
function insertExpression(parent, value, current, marker) {
|
|
29
32
|
if (value === current) return;
|
|
@@ -71,7 +74,7 @@ function createRenderer({
|
|
|
71
74
|
for (let i = 0, len = value.length; i < len; i++) {
|
|
72
75
|
const item = value[i],
|
|
73
76
|
t = typeof item;
|
|
74
|
-
if (t === "string" || t === "number") value[i] =
|
|
77
|
+
if (t === "string" || t === "number") value[i] = createTextNode(item);
|
|
75
78
|
}
|
|
76
79
|
}
|
|
77
80
|
return value;
|
|
@@ -161,13 +164,16 @@ function createRenderer({
|
|
|
161
164
|
const prevProps = {};
|
|
162
165
|
props || (props = {});
|
|
163
166
|
if (!skipChildren) {
|
|
164
|
-
|
|
167
|
+
effect(() => normalize(props.children), value => {
|
|
165
168
|
insertExpression(node, value, prevProps.children);
|
|
166
169
|
prevProps.children = value;
|
|
167
170
|
});
|
|
168
171
|
}
|
|
169
|
-
|
|
170
|
-
|
|
172
|
+
effect(() => {
|
|
173
|
+
const r = props.ref;
|
|
174
|
+
(typeof r === "function" || Array.isArray(r)) && ref(() => r, node);
|
|
175
|
+
}, () => {});
|
|
176
|
+
effect(() => {
|
|
171
177
|
const newProps = {};
|
|
172
178
|
for (const prop in props) {
|
|
173
179
|
if (prop === "children" || prop === "ref") continue;
|
|
@@ -185,6 +191,13 @@ function createRenderer({
|
|
|
185
191
|
});
|
|
186
192
|
return prevProps;
|
|
187
193
|
}
|
|
194
|
+
function applyRef(r, element) {
|
|
195
|
+
Array.isArray(r) ? r.flat(Infinity).forEach(f => f && f(element)) : r(element);
|
|
196
|
+
}
|
|
197
|
+
function ref(fn, element) {
|
|
198
|
+
const resolved = solidJs.untrack(fn);
|
|
199
|
+
solidJs.runWithOwner(null, () => applyRef(resolved, element));
|
|
200
|
+
}
|
|
188
201
|
return {
|
|
189
202
|
render(code, element) {
|
|
190
203
|
let disposer;
|
|
@@ -204,12 +217,11 @@ function createRenderer({
|
|
|
204
217
|
return value;
|
|
205
218
|
},
|
|
206
219
|
mergeProps: solidJs.merge,
|
|
207
|
-
effect
|
|
220
|
+
effect,
|
|
208
221
|
memo,
|
|
209
222
|
createComponent: solidJs.createComponent,
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
223
|
+
applyRef,
|
|
224
|
+
ref
|
|
213
225
|
};
|
|
214
226
|
}
|
|
215
227
|
|
package/dist/universal.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { createMemo,
|
|
1
|
+
import { createMemo, createRenderEffect, createComponent, merge, createRoot, flatten, untrack, runWithOwner } from 'solid-js';
|
|
2
2
|
|
|
3
|
+
const effect = (fn, effectFn, initial) => createRenderEffect(fn, effectFn, initial, {
|
|
4
|
+
transparent: true
|
|
5
|
+
});
|
|
3
6
|
const memo = fn => createMemo(() => fn());
|
|
4
7
|
|
|
5
8
|
function createRenderer({
|
|
@@ -21,7 +24,7 @@ function createRenderer({
|
|
|
21
24
|
accessor = normalize(accessor, multi, true);
|
|
22
25
|
if (typeof accessor !== "function") return insertExpression(parent, accessor, initial, marker);
|
|
23
26
|
}
|
|
24
|
-
|
|
27
|
+
effect(() => normalize(accessor, multi), (value, current) => insertExpression(parent, value, current, marker), initial);
|
|
25
28
|
}
|
|
26
29
|
function insertExpression(parent, value, current, marker) {
|
|
27
30
|
if (value === current) return;
|
|
@@ -69,7 +72,7 @@ function createRenderer({
|
|
|
69
72
|
for (let i = 0, len = value.length; i < len; i++) {
|
|
70
73
|
const item = value[i],
|
|
71
74
|
t = typeof item;
|
|
72
|
-
if (t === "string" || t === "number") value[i] =
|
|
75
|
+
if (t === "string" || t === "number") value[i] = createTextNode(item);
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
78
|
return value;
|
|
@@ -159,13 +162,16 @@ function createRenderer({
|
|
|
159
162
|
const prevProps = {};
|
|
160
163
|
props || (props = {});
|
|
161
164
|
if (!skipChildren) {
|
|
162
|
-
|
|
165
|
+
effect(() => normalize(props.children), value => {
|
|
163
166
|
insertExpression(node, value, prevProps.children);
|
|
164
167
|
prevProps.children = value;
|
|
165
168
|
});
|
|
166
169
|
}
|
|
167
|
-
|
|
168
|
-
|
|
170
|
+
effect(() => {
|
|
171
|
+
const r = props.ref;
|
|
172
|
+
(typeof r === "function" || Array.isArray(r)) && ref(() => r, node);
|
|
173
|
+
}, () => {});
|
|
174
|
+
effect(() => {
|
|
169
175
|
const newProps = {};
|
|
170
176
|
for (const prop in props) {
|
|
171
177
|
if (prop === "children" || prop === "ref") continue;
|
|
@@ -183,6 +189,13 @@ function createRenderer({
|
|
|
183
189
|
});
|
|
184
190
|
return prevProps;
|
|
185
191
|
}
|
|
192
|
+
function applyRef(r, element) {
|
|
193
|
+
Array.isArray(r) ? r.flat(Infinity).forEach(f => f && f(element)) : r(element);
|
|
194
|
+
}
|
|
195
|
+
function ref(fn, element) {
|
|
196
|
+
const resolved = untrack(fn);
|
|
197
|
+
runWithOwner(null, () => applyRef(resolved, element));
|
|
198
|
+
}
|
|
186
199
|
return {
|
|
187
200
|
render(code, element) {
|
|
188
201
|
let disposer;
|
|
@@ -202,12 +215,11 @@ function createRenderer({
|
|
|
202
215
|
return value;
|
|
203
216
|
},
|
|
204
217
|
mergeProps: merge,
|
|
205
|
-
effect
|
|
218
|
+
effect,
|
|
206
219
|
memo,
|
|
207
220
|
createComponent,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
221
|
+
applyRef,
|
|
222
|
+
ref
|
|
211
223
|
};
|
|
212
224
|
}
|
|
213
225
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidjs/universal",
|
|
3
3
|
"description": "Solid's universal runtime for creating custom renderers",
|
|
4
|
-
"version": "2.0.0-experimental.
|
|
4
|
+
"version": "2.0.0-experimental.16",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://solidjs.com",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"./types/*": "./types/*"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"solid-js": "^2.0.0-experimental.
|
|
40
|
+
"solid-js": "^2.0.0-experimental.16"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"solid-js": "2.0.0-experimental.
|
|
43
|
+
"solid-js": "2.0.0-experimental.16"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "npm-run-all -nl build:*",
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface RendererOptions<NodeType> {
|
|
2
|
+
createElement(tag: string): NodeType;
|
|
3
|
+
createTextNode(value: string): NodeType;
|
|
4
|
+
replaceText(textNode: NodeType, value: string): void;
|
|
5
|
+
isTextNode(node: NodeType): boolean;
|
|
6
|
+
setProperty<T>(node: NodeType, name: string, value: T, prev?: T): void;
|
|
7
|
+
insertNode(parent: NodeType, node: NodeType, anchor?: NodeType): void;
|
|
8
|
+
removeNode(parent: NodeType, node: NodeType): void;
|
|
9
|
+
getParentNode(node: NodeType): NodeType | undefined;
|
|
10
|
+
getFirstChild(node: NodeType): NodeType | undefined;
|
|
11
|
+
getNextSibling(node: NodeType): NodeType | undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface Renderer<NodeType> {
|
|
15
|
+
render(code: () => NodeType, node: NodeType): () => void;
|
|
16
|
+
effect<T>(fn: (prev?: T) => T, effect: (value: T, prev?: T) => void, init?: T): void;
|
|
17
|
+
memo<T>(fn: () => T, equal: boolean): () => T;
|
|
18
|
+
createComponent<T>(Comp: (props: T) => NodeType, props: T): NodeType;
|
|
19
|
+
createElement(tag: string): NodeType;
|
|
20
|
+
createTextNode(value: string): NodeType;
|
|
21
|
+
insertNode(parent: NodeType, node: NodeType, anchor?: NodeType): void;
|
|
22
|
+
insert<T>(parent: any, accessor: (() => T) | T, marker?: any | null, initial?: any): NodeType;
|
|
23
|
+
spread<T>(node: any, accessor: (() => T) | T, skipChildren?: boolean): void;
|
|
24
|
+
setProp<T>(node: NodeType, name: string, value: T, prev?: T): T;
|
|
25
|
+
mergeProps(...sources: unknown[]): unknown;
|
|
26
|
+
use<A, T>(fn: (element: NodeType, arg: A) => T, element: NodeType, arg: A): T;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function createRenderer<NodeType>(options: RendererOptions<NodeType>): Renderer<NodeType>;
|
|
30
|
+
|