Skip to content

Commit 6167ca7

Browse files
committed
Add missing indexArray to server-side runtime.
1 parent 4968fe2 commit 6167ca7

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

.changeset/modern-oranges-own.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"solid-js": patch
3+
---
4+
5+
Add missing `indexArray` to server-side runtime.

packages/solid/src/server/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export {
2424
equalFn,
2525
requestCallback,
2626
mapArray,
27+
indexArray,
2728
observable,
2829
from,
2930
$PROXY,

packages/solid/src/server/reactive.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,21 +267,29 @@ export function requestCallback(fn: () => void, options?: { timeout: number }):
267267
export function cancelCallback(task: Task) {}
268268

269269
export function mapArray<T, U>(
270-
list: () => T[],
271-
mapFn: (v: T, i: () => number) => U,
272-
options: { fallback?: () => any } = {}
270+
list: Accessor<readonly T[] | undefined | null | false>,
271+
mapFn: (v: T, i: Accessor<number>) => U,
272+
options: { fallback?: Accessor<any> } = {}
273273
): () => U[] {
274-
const items = list();
274+
const items = list() || [];
275275
let s: U[] = [];
276276
if (items.length) {
277277
for (let i = 0, len = items.length; i < len; i++) s.push(mapFn(items[i], () => i));
278278
} else if (options.fallback) s = [options.fallback()];
279279
return () => s;
280280
}
281281

282-
function getSymbol() {
283-
const SymbolCopy = Symbol as any;
284-
return SymbolCopy.observable || "@@observable";
282+
export function indexArray<T, U>(
283+
list: Accessor<readonly T[] | undefined | null | false>,
284+
mapFn: (v: Accessor<T>, i: number) => U,
285+
options: { fallback?: Accessor<any> } = {}
286+
): () => U[] {
287+
const items = list() || [];
288+
let s: U[] = [];
289+
if (items.length) {
290+
for (let i = 0, len = items.length; i < len; i++) s.push(mapFn(() => items[i], i));
291+
} else if (options.fallback) s = [options.fallback()];
292+
return () => s;
285293
}
286294

287295
export type ObservableObserver<T> =

0 commit comments

Comments
 (0)