Skip to content

Commit

Permalink
track length in array helpers, fix mobx external source
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansolid committed Jul 24, 2024
1 parent 424a31a commit 3fc015c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-grapes-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"solid-js": patch
---

track length in array helpers, fix mobx external source
13 changes: 7 additions & 6 deletions packages/solid/src/reactive/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ export function mapArray<T, U>(
onCleanup(() => dispose(disposers));
return () => {
let newItems = list() || [],
newLen = newItems.length,
i: number,
j: number;
(newItems as any)[$TRACK]; // top level tracking
return untrack(() => {
let newLen = newItems.length,
newIndices: Map<T | typeof FALLBACK, number>,
let newIndices: Map<T | typeof FALLBACK, number>,
newIndicesNext: number[],
temp: U[],
tempdisposers: (() => void)[],
Expand Down Expand Up @@ -196,10 +196,11 @@ export function indexArray<T, U>(

onCleanup(() => dispose(disposers));
return () => {
const newItems = list() || [];
const newItems = list() || [],
newLen = newItems.length;
(newItems as any)[$TRACK]; // top level tracking
return untrack(() => {
if (newItems.length === 0) {
if (newLen === 0) {
if (len !== 0) {
dispose(disposers);
disposers = [];
Expand All @@ -226,7 +227,7 @@ export function indexArray<T, U>(
len = 0;
}

for (i = 0; i < newItems.length; i++) {
for (i = 0; i < newLen; i++) {
if (i < items.length && items[i] !== newItems[i]) {
signals[i](() => newItems[i]);
} else if (i >= items.length) {
Expand All @@ -236,7 +237,7 @@ export function indexArray<T, U>(
for (; i < items.length; i++) {
disposers[i]();
}
len = signals.length = disposers.length = newItems.length;
len = signals.length = disposers.length = newLen;
items = newItems.slice(0);
return (mapped = mapped.slice(0, len));
});
Expand Down

0 comments on commit 3fc015c

Please sign in to comment.