| 192 | } |
| 193 | |
| 194 | class 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 | |
| 229 | class PropRefImpl<A, K extends keyof A> implements AtomRef<A[K]> { |
| 230 | readonly [TypeId]: TypeId |
nothing calls this directly
no test coverage detected
searching dependent graphs…