Skip to content

Commit

Permalink
fix: clash with distinct cells and initial values from the realm
Browse files Browse the repository at this point in the history
  • Loading branch information
petyosi committed Dec 27, 2023
1 parent df98815 commit 9d7e57d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/examples.stories.tsx
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down Expand Up @@ -33,7 +38,7 @@ const WorldChild = () => {

export const Hello = () => {
return (
<RealmProvider>
<RealmProvider initWith={{ [foo$]: 'foo' }} updateWith={{ [foo$]: 'foo' }}>
<WorldChild />
</RealmProvider>
)
Expand Down
6 changes: 3 additions & 3 deletions src/realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ export class Realm {
cellInstance<T>(value: T, distinct: Distinct<T> = true, node = Symbol()): NodeRef<T> {
if (!this.state.has(node)) {
this.state.set(node, value)
if (distinct !== false) {
this.distinctNodes.set(node, distinct === true ? defaultComparator : (distinct as Comparator<unknown>))
}
}
if (distinct !== false && !this.distinctNodes.has(node)) {
this.distinctNodes.set(node, distinct === true ? defaultComparator : (distinct as Comparator<unknown>))
}

return node as NodeRef<T>
Expand Down

0 comments on commit 9d7e57d

Please sign in to comment.