atmover
Atom overlay: abstraction layer on top of mobx, cellx, derivable with hot reload support and error handling.
Some limitations: Only object and functions as atom values: atmover attaches to them metadata. No observable collections, maps, etc.
- Setup
- Value get/set
- Get atom from object metadata
- Transactions
- Computed class
- Objects in constructor arguments
- Computed function
- Listen changes
- Error handling in computable
- onUpdate hook
- Replacing prototype
Setup
mobx
// @flow const hotReloadingEnabled = trueconst atmover = mobx hotReloadingEnabled
derivable
// @flow const hotReloadingEnabled = trueconst atmover = derivable hotReloadingEnabled/// ...
cellx
// @flow const hotReloadingEnabled = trueconst atmover = cellx hotReloadingEnabled/// ...
Value get/set
// @flow interface BOpts a: number const aAtom: Atom<BOpts> = atmovervaluea: 1: BOptsaAtom // {a: 1}aAtom
Get atom from object metadata
// @flow const a = aAtomaa === 1const atom: Atom<BOpts> =
Transactions
// @flow const bAtom: Atom<BOpts> = atmovervaluea: 10: BOpts atmover
Computed class
// @flow v: number { thisv = opts1a + opts2a } const cAtom: Computed<C> = atmoverconst c: C = cAtom
Objects in constructor arguments
// @flow v: number { thisv = opts1a + opts2ba } const cAtom: Computed<C> = atmoverconst c: C = cAtom
Computed function
// @flow interface CResult v: number; : CResult { return v: optsa } const fAtom: Computed<CResult> = atmoverconst f: CResult = fAtom
Listen changes
// @flow const unsubscribe: => void = cAtom aAtom // console: c.v = 15
Error handling in computable
// @flow v: number { thisv = opts1a + opts2a if thisv === 0 throw 'Example error' } const dAtom: Computed<D> = atmover const unsubscribe: => void = dAtom atmover// console: Error: Example error dAtom === undefined
onUpdate hook
// @flow v: number some: number { thisv = opts1a } : void thissome = some // $FlowFixMe: computed property key not supported, see https://github.com/facebook/flow/issues/2286 { next } const eAtom: Computed<E> = atmover const oldValue: E = eAtom oldValue aAtom const newValue: E = eAtom
Replacing prototype
// @flow v: number { thisv = optsa } v: number { superopts thisv = thisv * 2 }const b1Atom: Computed<B1> = atmoverb1Atomv === 10 // Hot reloading:atmover b1Atomv === 20