Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/stagas/minimal-reactive

Smallest possible implementation of reactive programming, effects and dependencies.
https://github.com/stagas/minimal-reactive

Last synced: 14 days ago
JSON representation

Smallest possible implementation of reactive programming, effects and dependencies.

Awesome Lists containing this project

README

        


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

    ```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
- [everyday-types](https://npmjs.org/package/everyday-types) by [stagas](https://github.com/stagas) – Everyday utility types
- [everyday-utils](https://npmjs.org/package/everyday-utils) by [stagas](https://github.com/stagas) – Everyday utilities

## Contributing

[Fork](https://github.com/stagas/minimal-reactive/fork) or [edit](https://github.dev/stagas/minimal-reactive) and submit a PR.

All contributions are welcome!

## License

MIT © 2022 [stagas](https://github.com/stagas)