diff --git a/packages/dataverse/src/Atom.ts b/packages/dataverse/src/Atom.ts index 500bc25..d7056fc 100644 --- a/packages/dataverse/src/Atom.ts +++ b/packages/dataverse/src/Atom.ts @@ -150,30 +150,15 @@ export default class Atom 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) { diff --git a/packages/dataverse/src/integration.test.ts b/packages/dataverse/src/integration.test.ts index 4ef3550..6a23b9e 100644 --- a/packages/dataverse/src/integration.test.ts +++ b/packages/dataverse/src/integration.test.ts @@ -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) }) diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts index 15e3315..e1a881f 100644 --- a/packages/react/src/index.ts +++ b/packages/react/src/index.ts @@ -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( if (!atomRef.current) { atomRef.current = new Atom(fnAsCallback) } else { - atomRef.current.setState(fnAsCallback) + atomRef.current.set(fnAsCallback) } const prsm = useMemo( diff --git a/theatre/core/src/sequences/Sequence.ts b/theatre/core/src/sequences/Sequence.ts index ee83e57..7b49785 100644 --- a/theatre/core/src/sequences/Sequence.ts +++ b/theatre/core/src/sequences/Sequence.ts @@ -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 { @@ -198,9 +198,7 @@ export default class Sequence { rangeD: Prism, ticker: Ticker, ): Promise { - 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 { 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() diff --git a/theatre/core/src/sheetObjects/SheetObject.ts b/theatre/core/src/sheetObjects/SheetObject.ts index cd82ea8..deef0d4 100644 --- a/theatre/core/src/sheetObjects/SheetObject.ts +++ b/theatre/core/src/sheetObjects/SheetObject.ts @@ -331,6 +331,6 @@ export default class SheetObject implements IdentityPrismProvider { setInitialValue(val: DeepPartialOfSerializableValue) { this.validateValue(this.propsP, val) - this._initialValue.setState(val) + this._initialValue.set(val) } } diff --git a/theatre/core/src/sheetObjects/SheetObjectTemplate.ts b/theatre/core/src/sheetObjects/SheetObjectTemplate.ts index 77162fe..5cad18a 100644 --- a/theatre/core/src/sheetObjects/SheetObjectTemplate.ts +++ b/theatre/core/src/sheetObjects/SheetObjectTemplate.ts @@ -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) { diff --git a/theatre/core/src/sheets/Sheet.ts b/theatre/core/src/sheets/Sheet.ts index 49cbc15..17ad484 100644 --- a/theatre/core/src/sheets/Sheet.ts +++ b/theatre/core/src/sheets/Sheet.ts @@ -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) { diff --git a/theatre/core/src/sheets/SheetTemplate.ts b/theatre/core/src/sheets/SheetTemplate.ts index 3712b1f..bd5fb57 100644 --- a/theatre/core/src/sheets/SheetTemplate.ts +++ b/theatre/core/src/sheets/SheetTemplate.ts @@ -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( diff --git a/theatre/shared/src/utils/valToAtom.ts b/theatre/shared/src/utils/valToAtom.ts index 4cf3932..0915846 100644 --- a/theatre/shared/src/utils/valToAtom.ts +++ b/theatre/shared/src/utils/valToAtom.ts @@ -5,6 +5,6 @@ import {Atom, prism} from '@theatre/dataverse' */ export const valToAtom = (key: string, vals: T): Atom => { const a = prism.memo(key, () => new Atom(vals), []) - a.setState(vals) + a.set(vals) return a } diff --git a/theatre/studio/src/Studio.ts b/theatre/studio/src/Studio.ts index 62431b9..2511443 100644 --- a/theatre/studio/src/Studio.ts +++ b/theatre/studio/src/Studio.ts @@ -264,7 +264,7 @@ export class Studio { } get core() { - return this._coreAtom.getState().core + return this._coreAtom.get().core } get coreP() { diff --git a/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Right/DopeSheetSelectionView.tsx b/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Right/DopeSheetSelectionView.tsx index dadf020..ca101a1 100644 --- a/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Right/DopeSheetSelectionView.tsx +++ b/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Right/DopeSheetSelectionView.tsx @@ -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 diff --git a/theatre/studio/src/panels/SequenceEditorPanel/whatPropIsHighlighted.ts b/theatre/studio/src/panels/SequenceEditorPanel/whatPropIsHighlighted.ts index 90ce749..ebd949f 100644 --- a/theatre/studio/src/panels/SequenceEditorPanel/whatPropIsHighlighted.ts +++ b/theatre/studio/src/panels/SequenceEditorPanel/whatPropIsHighlighted.ts @@ -37,10 +37,10 @@ function createWhatPropIsHighlightedState() { replaceLock(address: WithoutSheetInstance, 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}) } } }, diff --git a/theatre/studio/src/toolbars/ExtensionToolbar/ExtensionToolbar.tsx b/theatre/studio/src/toolbars/ExtensionToolbar/ExtensionToolbar.tsx index d7c9282..b4754f9 100644 --- a/theatre/studio/src/toolbars/ExtensionToolbar/ExtensionToolbar.tsx +++ b/theatre/studio/src/toolbars/ExtensionToolbar/ExtensionToolbar.tsx @@ -33,7 +33,7 @@ const ExtensionToolsetRender: React.FC<{ useLayoutEffect(() => { const detach = extension.toolbars?.[toolbarId]?.( - toolsetConfigBox.setState.bind(toolsetConfigBox), + toolsetConfigBox.set.bind(toolsetConfigBox), getStudio()!.publicApi, ) diff --git a/theatre/studio/src/uiComponents/useValToAtom.ts b/theatre/studio/src/uiComponents/useValToAtom.ts index ae2cfa9..368a382 100644 --- a/theatre/studio/src/uiComponents/useValToAtom.ts +++ b/theatre/studio/src/uiComponents/useValToAtom.ts @@ -7,7 +7,7 @@ export default function useValToAtom(val: S): Atom { }, []) useLayoutEffect(() => { - atom.setState(val) + atom.set(val) }, [val]) return atom diff --git a/theatre/studio/src/utils/redux/atomFromReduxStore.ts b/theatre/studio/src/utils/redux/atomFromReduxStore.ts index 14862d3..98ed40f 100644 --- a/theatre/studio/src/utils/redux/atomFromReduxStore.ts +++ b/theatre/studio/src/utils/redux/atomFromReduxStore.ts @@ -9,7 +9,7 @@ export default function atomFromReduxStore( store.subscribe(() => { const newState = store.getState() - a.setState(newState) + a.set(newState) lastState = newState })