MCPcopy Create free account
hub / github.com/effect-app/libs / MapRefImpl

Class MapRefImpl

repos/effect/packages/effect/src/unstable/reactivity/AtomRef.ts:194–227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192}
193
194class MapRefImpl<A, B> implements ReadonlyRef<B> {
195 readonly [TypeId]: TypeId
196 readonly key = keyState.generate()
197 readonly parent: ReadonlyRef<A>
198 readonly transform: (a: A) => B
199 constructor(parent: ReadonlyRef<A>, transform: (a: A) => B) {
200 this[TypeId] = TypeId
201 this.parent = parent
202 this.transform = transform
203 }
204 [Equal.symbol](that: Equal.Equal) {
205 return Equal.equals(this.value, (that as ReadonlyRef<B>).value)
206 }
207 [Hash.symbol]() {
208 return Hash.hash(this.value)
209 }
210 get value() {
211 return this.transform(this.parent.value)
212 }
213 subscribe(f: (a: B) => void): () => void {
214 let previous = this.transform(this.parent.value)
215 return this.parent.subscribe((a) => {
216 const next = this.transform(a)
217 if (Equal.equals(next, previous)) {
218 return
219 }
220 previous = next
221 f(next)
222 })
223 }
224 map<C>(f: (a: B) => C): ReadonlyRef<C> {
225 return new MapRefImpl(this, f)
226 }
227}
228
229class PropRefImpl<A, K extends keyof A> implements AtomRef<A[K]> {
230 readonly [TypeId]: TypeId

Callers

nothing calls this directly

Calls 1

generateMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…