Skip to content

Commit

Permalink
add passthrough equality to RxRef
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Sep 25, 2023
1 parent ab3d68f commit 0b3f2c5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/soft-clocks-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect-rx/rx": patch
---

add passthrough equality to RxRef
2 changes: 1 addition & 1 deletion docs/rx/RxRef.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Added in v1.0.0
**Signature**

```ts
export interface ReadonlyRef<A> {
export interface ReadonlyRef<A> extends Equal.Equal {
readonly [TypeId]: TypeId
readonly key: string
readonly value: A
Expand Down
18 changes: 17 additions & 1 deletion packages/rx/src/RxRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import * as Equal from "@effect/data/Equal"
import { globalValue } from "@effect/data/GlobalValue"
import * as Hash from "@effect/data/Hash"

/**
* @since 1.0.0
Expand All @@ -20,7 +21,7 @@ export type TypeId = typeof TypeId
* @since 1.0.0
* @category models
*/
export interface ReadonlyRef<A> {
export interface ReadonlyRef<A> extends Equal.Equal {
readonly [TypeId]: TypeId
readonly key: string
readonly value: A
Expand Down Expand Up @@ -73,6 +74,15 @@ class ReadonlyRefImpl<A> implements ReadonlyRef<A> {
constructor(public value: A) {
this[TypeId] = TypeId
}

[Equal.symbol](that: ReadonlyRef<A>) {
return Equal.equals(this.value, that.value)
}

[Hash.symbol]() {
return Hash.hash(this.value)
}

listeners: Array<(a: A) => void> = []
listenerCount = 0

Expand Down Expand Up @@ -122,6 +132,12 @@ class MapRefImpl<A, B> implements ReadonlyRef<B> {
constructor(readonly parent: ReadonlyRef<A>, readonly transform: (a: A) => B) {
this[TypeId] = TypeId
}
[Equal.symbol](that: ReadonlyRef<A>) {
return Equal.equals(this.value, that.value)
}
[Hash.symbol]() {
return Hash.hash(this.value)
}
get value() {
return this.transform(this.parent.value)
}
Expand Down

0 comments on commit 0b3f2c5

Please sign in to comment.