Remove Box in favor of Atom

This commit is contained in:
Aria Minaei 2022-12-01 15:37:19 +01:00
parent 2bd1dc85a9
commit c354a602a4
13 changed files with 63 additions and 49 deletions

View file

@ -115,7 +115,7 @@ class Scope {
/**
* Wraps an object whose (sub)properties can be individually tracked.
*/
export default class Atom<State extends {}> implements IdentityPrismProvider {
export default class Atom<State> implements IdentityPrismProvider {
private _currentState: State
/**
* @internal
@ -130,6 +130,8 @@ export default class Atom<State extends {}> implements IdentityPrismProvider {
*/
readonly pointer: Pointer<State>
readonly prism: Prism<State> = this.getIdentityPrism([]) as $IntentionalAny
constructor(initialState: State) {
this._currentState = initialState
this._rootScope = new Scope(undefined, [])
@ -141,7 +143,7 @@ export default class Atom<State extends {}> implements IdentityPrismProvider {
*
* @param newState - The new state of the atom.
*/
setState(newState: State) {
set(newState: State) {
const oldState = this._currentState
this._currentState = newState
@ -150,11 +152,23 @@ export default class Atom<State extends {}> implements IdentityPrismProvider {
/**
* Gets the current state of the atom.
* @deprecated
*/
getState() {
return this._currentState
}
get() {
return this.getState()
}
/**
* @deprecated
*/
setState(newState: State) {
this.set(newState)
}
/**
* Gets the state of the atom at `path`.
*/

View file

@ -6,8 +6,6 @@
export type {IdentityPrismProvider} from './Atom'
export {default as Atom, val, pointerToPrism} from './Atom'
export {default as Box} from './Box'
export type {IBox} from './Box'
export {isPrism} from './prism/Interface'
export type {Prism} from './prism/Interface'
export {default as iterateAndCountTicks} from './prism/iterateAndCountTicks'