@reatom/core
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.5 • Public • Published

    reatom logo

    @reatom/core

    Core package of Reatom state manager.

    npm npm type definitions npm bundle size GitHub

    Open in docs

    Reatom is declarative and reactive state manager, designed for both simple and complex applications. See docs.

    Install

    npm i @reatom/core

    or

    yarn add @reatom/core

    Usage

    Open in CodeSandbox

    import {
      declareAction,
      declareAtom,
      map,
      combine,
      createStore,
    } from '@reatom/core'
     
    /**
     * Step 1.
     * Declare actions
     */
    const increment = declareAction()
     
    /**
     * Step 2.
     * Declare atoms (like reducers or models)
     */
    const counterAtom = declareAtom(0, on => [on(increment, state => state + 1)])
    const counterDoubledAtom = map(counterAtom, value => value * 2)
    const countersShapeAtom = combine({
      counter: counterAtom,
      counterDoubled: counterDoubledAtom,
    })
     
    /**
     * Step 3.
     * Create store entry point
     */
    const store = createStore(countersShapeAtom)
     
    /**
     * Step 4.
     * Dispatch action
     */
    store.dispatch(increment())
     
    /**
     * Step 5.
     * Get action results
     */
    console.log(store.getState(counterAtom))
    // ➜ 1
     
    console.log(store.getState(counterDoubledAtom))
    // ➜ 2
     
    console.log(store.getState(countersShapeAtom))
    // ➜ { counter: 1, counterDoubled: 2 }

    Install

    npm i @reatom/core

    DownloadsWeekly Downloads

    4,019

    Version

    1.1.5

    License

    MIT

    Unpacked Size

    177 kB

    Total Files

    22

    Last publish

    Collaborators

    • avatar
    • avatar