Skip to content

Commit

Permalink
Add missing indexArray to server-side runtime.
Browse files Browse the repository at this point in the history
  • Loading branch information
thetarnav committed Oct 16, 2023
1 parent 4968fe2 commit 6167ca7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-oranges-own.md
@@ -0,0 +1,5 @@
---
"solid-js": patch
---

Add missing `indexArray` to server-side runtime.
1 change: 1 addition & 0 deletions packages/solid/src/server/index.ts
Expand Up @@ -24,6 +24,7 @@ export {
equalFn,
requestCallback,
mapArray,
indexArray,
observable,
from,
$PROXY,
Expand Down
22 changes: 15 additions & 7 deletions packages/solid/src/server/reactive.ts
Expand Up @@ -267,21 +267,29 @@ export function requestCallback(fn: () => void, options?: { timeout: number }):
export function cancelCallback(task: Task) {}

export function mapArray<T, U>(
list: () => T[],
mapFn: (v: T, i: () => number) => U,
options: { fallback?: () => any } = {}
list: Accessor<readonly T[] | undefined | null | false>,
mapFn: (v: T, i: Accessor<number>) => U,
options: { fallback?: Accessor<any> } = {}
): () => U[] {
const items = list();
const items = list() || [];
let s: U[] = [];
if (items.length) {
for (let i = 0, len = items.length; i < len; i++) s.push(mapFn(items[i], () => i));
} else if (options.fallback) s = [options.fallback()];
return () => s;
}

function getSymbol() {
const SymbolCopy = Symbol as any;
return SymbolCopy.observable || "@@observable";
export function indexArray<T, U>(
list: Accessor<readonly T[] | undefined | null | false>,
mapFn: (v: Accessor<T>, i: number) => U,
options: { fallback?: Accessor<any> } = {}
): () => U[] {
const items = list() || [];
let s: U[] = [];
if (items.length) {
for (let i = 0, len = items.length; i < len; i++) s.push(mapFn(() => items[i], i));
} else if (options.fallback) s = [options.fallback()];
return () => s;
}

export type ObservableObserver<T> =
Expand Down

0 comments on commit 6167ca7

Please sign in to comment.