From 9d7e57d53c6886d22aa271fb221cc0e91eaabd59 Mon Sep 17 00:00:00 2001 From: Petyo Ivanov Date: Wed, 27 Dec 2023 18:42:56 +0200 Subject: [PATCH] fix: clash with distinct cells and initial values from the realm --- src/examples.stories.tsx | 9 +++++++-- src/realm.ts | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/examples.stories.tsx b/src/examples.stories.tsx index 9ad8833..505f6f3 100644 --- a/src/examples.stories.tsx +++ b/src/examples.stories.tsx @@ -1,6 +1,11 @@ import { Action, Cell, RealmProvider, useCellValue, useCellValues, usePublisher } from '.' -const foo$ = Cell('foo') +const foo$ = Cell('foo', (r) => { + r.sub(foo$, (v) => { + console.log('foo', v) + }) +}) + const bar$ = Cell('bar') const q$ = Action((r) => { @@ -33,7 +38,7 @@ const WorldChild = () => { export const Hello = () => { return ( - + ) diff --git a/src/realm.ts b/src/realm.ts index c3a3358..0caa8bb 100644 --- a/src/realm.ts +++ b/src/realm.ts @@ -117,9 +117,9 @@ export class Realm { cellInstance(value: T, distinct: Distinct = true, node = Symbol()): NodeRef { if (!this.state.has(node)) { this.state.set(node, value) - if (distinct !== false) { - this.distinctNodes.set(node, distinct === true ? defaultComparator : (distinct as Comparator)) - } + } + if (distinct !== false && !this.distinctNodes.has(node)) { + this.distinctNodes.set(node, distinct === true ? defaultComparator : (distinct as Comparator)) } return node as NodeRef