Change the signature of Derivation.changes()
to Derivation.onChange()
This way, we no longer expose the `Tappable` interface so we can remove it later.
This commit is contained in:
parent
f1cb8edc91
commit
f2bb24ef99
5 changed files with 11 additions and 16 deletions
|
@ -1,6 +1,5 @@
|
|||
import type Ticker from '../Ticker'
|
||||
import type {$IntentionalAny, VoidFn} from '../types'
|
||||
import type Tappable from '../utils/Tappable'
|
||||
|
||||
type IDependent = (msgComingFrom: IDerivation<$IntentionalAny>) => void
|
||||
|
||||
|
@ -21,7 +20,7 @@ export interface IDerivation<V> {
|
|||
/**
|
||||
* Returns a `Tappable` of the changes of this derivation.
|
||||
*/
|
||||
changes(ticker: Ticker): Tappable<V>
|
||||
onChange(ticker: Ticker, listener: (v: V) => void): VoidFn
|
||||
|
||||
onStale(cb: () => void): VoidFn
|
||||
|
||||
|
@ -37,7 +36,7 @@ export interface IDerivation<V> {
|
|||
* @param ticker - The ticker to use for batching.
|
||||
* @param fn - The callback to call on update.
|
||||
*
|
||||
* @see changes
|
||||
* @see onChange
|
||||
*/
|
||||
tapImmediate(ticker: Ticker, fn: (cb: V) => void): VoidFn
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ export default function* iterateOver<V>(
|
|||
|
||||
const ticker = new Ticker()
|
||||
|
||||
const untap = d.changes(ticker).tap((v) => {})
|
||||
const untap = d.onChange(ticker, (v) => {})
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
|
|
|
@ -21,7 +21,7 @@ describe('prism', () => {
|
|||
expect(d.getValue()).toEqual('fooboo')
|
||||
|
||||
const changes: Array<$FixMe> = []
|
||||
d.changes(ticker).tap((c) => {
|
||||
d.onChange(ticker, (c) => {
|
||||
changes.push(c)
|
||||
})
|
||||
|
||||
|
@ -112,7 +112,7 @@ describe('prism', () => {
|
|||
return n
|
||||
})
|
||||
|
||||
const untap = derivation.changes(ticker).tap((change) => {
|
||||
const untap = derivation.onChange(ticker, (change) => {
|
||||
sequence.push({change})
|
||||
})
|
||||
|
||||
|
@ -172,7 +172,7 @@ describe('prism', () => {
|
|||
return n
|
||||
})
|
||||
|
||||
const untap = derivation.changes(ticker).tap((change) => {
|
||||
const untap = derivation.onChange(ticker, (change) => {
|
||||
sequence.push({change})
|
||||
})
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import type Ticker from '../../Ticker'
|
||||
import type {$IntentionalAny, VoidFn} from '../../types'
|
||||
import Stack from '../../utils/Stack'
|
||||
import type Tappable from '../../utils/Tappable'
|
||||
import DerivationEmitter from '../DerivationEmitter'
|
||||
import type {IDerivation} from '../IDerivation'
|
||||
import {isDerivation} from '../IDerivation'
|
||||
|
@ -223,11 +222,8 @@ class PrismDerivation<V> implements IDerivation<V> {
|
|||
return this._state.hot
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a `Tappable` of the changes of this derivation.
|
||||
*/
|
||||
changes(ticker: Ticker): Tappable<V> {
|
||||
return new DerivationEmitter(this, ticker).tappable()
|
||||
onChange(ticker: Ticker, listener: (v: V) => void): VoidFn {
|
||||
return new DerivationEmitter(this, ticker).tappable().tap(listener)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -256,10 +252,10 @@ class PrismDerivation<V> implements IDerivation<V> {
|
|||
* @param ticker - The ticker to use for batching.
|
||||
* @param fn - The callback to call on update.
|
||||
*
|
||||
* @see changes
|
||||
* @see onChange
|
||||
*/
|
||||
tapImmediate(ticker: Ticker, fn: (cb: V) => void): VoidFn {
|
||||
const untap = this.changes(ticker).tap(fn)
|
||||
const untap = this.onChange(ticker, fn)
|
||||
fn(this.getValue())
|
||||
return untap
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ describe(`v2 atom`, () => {
|
|||
expect(d.getValue()).toEqual(0)
|
||||
const ticker = new Ticker()
|
||||
const changes: number[] = []
|
||||
d.changes(ticker).tap((c) => {
|
||||
d.onChange(ticker, (c) => {
|
||||
changes.push(c)
|
||||
})
|
||||
a.setState({...data, bar: 1})
|
||||
|
|
Loading…
Reference in a new issue