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(
|
||||
|
|
|
@ -123,7 +123,7 @@ export default class Sequence {
|
|||
}
|
||||
|
||||
get position() {
|
||||
return this._playbackControllerBox.getState().getCurrentPosition()
|
||||
return this._playbackControllerBox.get().getCurrentPosition()
|
||||
}
|
||||
|
||||
get subUnitsPerUnit(): number {
|
||||
|
@ -165,7 +165,7 @@ export default class Sequence {
|
|||
}
|
||||
const dur = this.length
|
||||
this._playbackControllerBox
|
||||
.getState()
|
||||
.get()
|
||||
.gotoPosition(position > dur ? dur : position)
|
||||
}
|
||||
|
||||
|
@ -174,7 +174,7 @@ export default class Sequence {
|
|||
}
|
||||
|
||||
get playing() {
|
||||
return val(this._playbackControllerBox.getState().statePointer.playing)
|
||||
return val(this._playbackControllerBox.get().statePointer.playing)
|
||||
}
|
||||
|
||||
_makeRangeFromSequenceTemplate(): Prism<IPlaybackRange> {
|
||||
|
@ -198,9 +198,7 @@ export default class Sequence {
|
|||
rangeD: Prism<IPlaybackRange>,
|
||||
ticker: Ticker,
|
||||
): Promise<unknown> {
|
||||
return this._playbackControllerBox
|
||||
.getState()
|
||||
.playDynamicRange(rangeD, ticker)
|
||||
return this._playbackControllerBox.get().playDynamicRange(rangeD, ticker)
|
||||
}
|
||||
|
||||
async play(
|
||||
|
@ -337,18 +335,18 @@ To fix this, either set \`conf.range[1]\` to be less the duration of the sequenc
|
|||
ticker: Ticker,
|
||||
): Promise<boolean> {
|
||||
return this._playbackControllerBox
|
||||
.getState()
|
||||
.get()
|
||||
.play(iterationCount, range, rate, direction, ticker)
|
||||
}
|
||||
|
||||
pause() {
|
||||
this._playbackControllerBox.getState().pause()
|
||||
this._playbackControllerBox.get().pause()
|
||||
}
|
||||
|
||||
replacePlaybackController(playbackController: IPlaybackController) {
|
||||
this.pause()
|
||||
const oldController = this._playbackControllerBox.getState()
|
||||
this._playbackControllerBox.setState(playbackController)
|
||||
const oldController = this._playbackControllerBox.get()
|
||||
this._playbackControllerBox.set(playbackController)
|
||||
|
||||
const time = oldController.getCurrentPosition()
|
||||
oldController.destroy()
|
||||
|
|
|
@ -331,6 +331,6 @@ export default class SheetObject implements IdentityPrismProvider {
|
|||
|
||||
setInitialValue(val: DeepPartialOfSerializableValue<SheetObjectPropsValue>) {
|
||||
this.validateValue(this.propsP, val)
|
||||
this._initialValue.setState(val)
|
||||
this._initialValue.set(val)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ export default class SheetObjectTemplate {
|
|||
readonly project: Project
|
||||
|
||||
get staticConfig() {
|
||||
return this._config.getState()
|
||||
return this._config.get()
|
||||
}
|
||||
|
||||
get configPointer() {
|
||||
|
@ -75,7 +75,7 @@ export default class SheetObjectTemplate {
|
|||
}
|
||||
|
||||
get staticActions() {
|
||||
return this._actions.getState()
|
||||
return this._actions.get()
|
||||
}
|
||||
|
||||
get actionsPointer() {
|
||||
|
@ -100,12 +100,12 @@ export default class SheetObjectTemplate {
|
|||
nativeObject: unknown,
|
||||
config: SheetObjectPropTypeConfig,
|
||||
): SheetObject {
|
||||
this._config.setState(config)
|
||||
this._config.set(config)
|
||||
return new SheetObject(sheet, this, nativeObject)
|
||||
}
|
||||
|
||||
reconfigure(config: SheetObjectPropTypeConfig) {
|
||||
this._config.setState(config)
|
||||
this._config.set(config)
|
||||
}
|
||||
|
||||
registerAction(name: string, action: SheetObjectAction) {
|
||||
|
|
|
@ -75,7 +75,7 @@ export default class Sheet {
|
|||
}
|
||||
|
||||
getObject(key: ObjectAddressKey): SheetObject | undefined {
|
||||
return this._objects.getState()[key]
|
||||
return this._objects.get()[key]
|
||||
}
|
||||
|
||||
deleteObject(objectKey: ObjectAddressKey) {
|
||||
|
|
|
@ -39,7 +39,7 @@ export default class SheetTemplate {
|
|||
}
|
||||
|
||||
getInstance(instanceId: SheetInstanceId): Sheet {
|
||||
let inst = this._instances.getState()[instanceId]
|
||||
let inst = this._instances.get()[instanceId]
|
||||
|
||||
if (!inst) {
|
||||
inst = new Sheet(this, instanceId)
|
||||
|
@ -55,7 +55,7 @@ export default class SheetTemplate {
|
|||
config: SheetObjectPropTypeConfig,
|
||||
actions: SheetObjectActionsConfig,
|
||||
): SheetObjectTemplate {
|
||||
let template = this._objectTemplates.getState()[objectKey]
|
||||
let template = this._objectTemplates.get()[objectKey]
|
||||
|
||||
if (!template) {
|
||||
template = new SheetObjectTemplate(
|
||||
|
|
|
@ -5,6 +5,6 @@ import {Atom, prism} from '@theatre/dataverse'
|
|||
*/
|
||||
export const valToAtom = <T>(key: string, vals: T): Atom<T> => {
|
||||
const a = prism.memo(key, () => new Atom(vals), [])
|
||||
a.setState(vals)
|
||||
a.set(vals)
|
||||
return a
|
||||
}
|
||||
|
|
|
@ -264,7 +264,7 @@ export class Studio {
|
|||
}
|
||||
|
||||
get core() {
|
||||
return this._coreAtom.getState().core
|
||||
return this._coreAtom.get().core
|
||||
}
|
||||
|
||||
get coreP() {
|
||||
|
|
|
@ -113,7 +113,7 @@ function useCaptureSelection(
|
|||
v: [event.clientY - rect.top, event.clientY - rect.top],
|
||||
}
|
||||
|
||||
val(layoutP.selectionAtom).setState({current: undefined})
|
||||
val(layoutP.selectionAtom).set({current: undefined})
|
||||
|
||||
return {
|
||||
onDrag(_dx, _dy, event) {
|
||||
|
@ -140,7 +140,7 @@ function useCaptureSelection(
|
|||
val(layoutP),
|
||||
ref.current,
|
||||
)
|
||||
val(layoutP.selectionAtom).setState({current: selection})
|
||||
val(layoutP.selectionAtom).set({current: selection})
|
||||
},
|
||||
onDragEnd(_dragHappened) {
|
||||
ref.current = null
|
||||
|
|
|
@ -37,10 +37,10 @@ function createWhatPropIsHighlightedState() {
|
|||
replaceLock(address: WithoutSheetInstance<PropAddress>, cleanup: VoidFn) {
|
||||
const lockId = lastLockId++
|
||||
|
||||
const existingState = whatIsHighlighted.getState()
|
||||
const existingState = whatIsHighlighted.get()
|
||||
if (existingState.hasLock) existingState.cleanup()
|
||||
|
||||
whatIsHighlighted.setState({
|
||||
whatIsHighlighted.set({
|
||||
hasLock: true,
|
||||
lockId,
|
||||
cleanup,
|
||||
|
@ -48,10 +48,10 @@ function createWhatPropIsHighlightedState() {
|
|||
})
|
||||
|
||||
return function unlock() {
|
||||
const curr = whatIsHighlighted.getState()
|
||||
const curr = whatIsHighlighted.get()
|
||||
if (curr.hasLock && curr.lockId === lockId) {
|
||||
curr.cleanup()
|
||||
whatIsHighlighted.setState({hasLock: false})
|
||||
whatIsHighlighted.set({hasLock: false})
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -33,7 +33,7 @@ const ExtensionToolsetRender: React.FC<{
|
|||
|
||||
useLayoutEffect(() => {
|
||||
const detach = extension.toolbars?.[toolbarId]?.(
|
||||
toolsetConfigBox.setState.bind(toolsetConfigBox),
|
||||
toolsetConfigBox.set.bind(toolsetConfigBox),
|
||||
getStudio()!.publicApi,
|
||||
)
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ export default function useValToAtom<S>(val: S): Atom<S> {
|
|||
}, [])
|
||||
|
||||
useLayoutEffect(() => {
|
||||
atom.setState(val)
|
||||
atom.set(val)
|
||||
}, [val])
|
||||
|
||||
return atom
|
||||
|
|
|
@ -9,7 +9,7 @@ export default function atomFromReduxStore<State>(
|
|||
|
||||
store.subscribe(() => {
|
||||
const newState = store.getState()
|
||||
a.setState(newState)
|
||||
a.set(newState)
|
||||
lastState = newState
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue