Remove Atom.set|getState()
This commit is contained in:
parent
e0465ed3fa
commit
3c68ed26ad
15 changed files with 33 additions and 50 deletions
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* @packageDocumentation
|
||||
*/
|
||||
|
||||
import type { Prism} from '@theatre/dataverse';
|
||||
import type {Prism} from '@theatre/dataverse'
|
||||
import {Atom} from '@theatre/dataverse'
|
||||
import {prism, val} from '@theatre/dataverse'
|
||||
import {findIndex} from 'lodash-es'
|
||||
|
@ -62,7 +62,7 @@ export function usePrism<T>(
|
|||
if (!atomRef.current) {
|
||||
atomRef.current = new Atom(fnAsCallback)
|
||||
} else {
|
||||
atomRef.current.setState(fnAsCallback)
|
||||
atomRef.current.set(fnAsCallback)
|
||||
}
|
||||
|
||||
const prsm = useMemo(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue