Skip to content

Commit

Permalink
fix(select): options non reactive inside suspense
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3m01 committed May 3, 2024
1 parent 16e4a35 commit d727baa
Showing 1 changed file with 14 additions and 48 deletions.
62 changes: 14 additions & 48 deletions packages/core/src/primitives/create-collection/create-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { access } from "@kobalte/utils";
import { Accessor, createEffect, createSignal, on } from "solid-js";
import { Accessor, createEffect, createMemo, createSignal, on } from "solid-js";

import { Collection, CollectionBase, CollectionNode } from "./types";
import { buildNodes } from "./utils";
Expand All @@ -25,52 +25,18 @@ export function createCollection<C extends Collection<CollectionNode>>(
props: CreateCollectionProps<C>,
deps: Array<Accessor<any>> = [],
) {
const initialNodes = buildNodes({
dataSource: access(props.dataSource),
getKey: access(props.getKey),
getTextValue: access(props.getTextValue),
getDisabled: access(props.getDisabled),
getSectionChildren: access(props.getSectionChildren),
return createMemo(() => {
const nodes = buildNodes({
dataSource: access(props.dataSource),
getKey: access(props.getKey),
getTextValue: access(props.getTextValue),
getDisabled: access(props.getDisabled),
getSectionChildren: access(props.getSectionChildren),
});

// Subscribe to all deps
for (let i = 0; i < deps.length; i++) deps[i]();

return props.factory(nodes);
});

const [collection, setCollection] = createSignal<C>(
props.factory(initialNodes),
);

createEffect(
on(
[
() => access(props.dataSource),
() => access(props.getKey),
() => access(props.getTextValue),
() => access(props.getDisabled),
() => access(props.getSectionChildren),
() => props.factory,
...deps,
],
([
dataSource,
getKey,
getTextValue,
getDisabled,
getSectionChildren,
factory,
]) => {
const nodes = buildNodes({
dataSource,
getKey,
getTextValue,
getDisabled,
getSectionChildren,
});

setCollection(() => factory(nodes));
},
{
defer: true,
},
),
);

return collection;
}

0 comments on commit d727baa

Please sign in to comment.