minimal-reactive
TypeScript icon, indicating that this package has built-in type declarations

1.4.0 • Public • Published

minimal-reactive

Smallest possible implementation of reactive programming, effects and dependencies.

npm i minimal-reactive pnpm add minimal-reactive yarn add minimal-reactive

Examples

# basic
    # view source example/basic.ts

    import { dep, effect } from 'minimal-reactive'
    
    const a = dep(3)
    const b = dep(4)
    
    effect({ a, b }, ({ a, b }) => {
      // a + b are unboxed here
      const result = a + b
    
      console.log(result)
    
      return () => {
        // dispose
      }
    }) // prints 7
    
    // changing values
    a.value = 2 // prints 6
    b.value = 3 // prints 5

API

# Change

    # key

      string

    # next

      any

    # prev

      any

# IDep

    # accessors

      {

      # get()

        get()  =>

          undefined | null | T

# set(value)

    # value

    set(value)  =>

      boolean

}
# current

    undefined | null | T

# stackErr

    Error

# subs

    Set<any>

# value

    undefined | null | T

# trigger()

    trigger()  =>

      void
# Boxs

    [K in StringKeys<T> ]: Dep<T [K]>

# Dep
# Fx
# OffFx

    # (reconnect, disconnect)

      # reconnect

        boolean

      # disconnect

        boolean

      (reconnect, disconnect)  =>

        any

# Sub

    # (prevValue, nextValue)

      # prevValue

        T | null | undefined

      # nextValue

        T | null | undefined

      <T>(prevValue, nextValue)  =>

        void

# Unboxs

    [K in keyof T ]-?: NonNullable<T [K] ["value"]>

# Vals

    [K in keyof T ]: T [K] ["value"]

# dep(value)

    # value

      null | T

    dep<T>(value)  =>

# deps(obj)

    # obj

    deps<T>(obj)  =>

# effect(deps, fn)

Credits

Contributing

Fork or edit and submit a PR.

All contributions are welcome!

License

MIT © 2022 stagas

Readme

Keywords

none

Package Sidebar

Install

npm i minimal-reactive

Weekly Downloads

0

Version

1.4.0

License

MIT

Unpacked Size

130 kB

Total Files

18

Last publish

Collaborators

  • stagas