Remove Atom.set|getState()

This commit is contained in:
Aria Minaei 2023-01-15 12:42:28 +01:00
parent e0465ed3fa
commit 3c68ed26ad
15 changed files with 33 additions and 50 deletions

View file

@ -150,30 +150,15 @@ export default class Atom<State> implements IdentityPrismProvider {
this._checkUpdates(this._rootScope, oldState, newState)
}
/**
* Gets the current state of the atom.
* @deprecated use {@link Atom.get} instead
*/
getState() {
return this._currentState
}
get() {
return this.getState()
}
/**
* @deprecated use {@link Atom.set} instead
*/
setState(newState: State) {
this.set(newState)
return this._currentState
}
/**
* Gets the state of the atom at `path`.
*/
getIn(path: (string | number)[]): unknown {
return path.length === 0 ? this.getState() : get(this.getState(), path)
return path.length === 0 ? this.get() : get(this.get(), path)
}
reduce(fn: (state: State) => State) {

View file

@ -23,11 +23,11 @@ describe(`v2 atom`, () => {
d.onChange(ticker, (c) => {
changes.push(c)
})
a.setState({...data, bar: 1})
a.set({...data, bar: 1})
ticker.tick()
expect(changes).toHaveLength(1)
expect(changes[0]).toEqual(1)
a.setState({...data, bar: 1})
a.set({...data, bar: 1})
ticker.tick()
expect(changes).toHaveLength(1)
})