realar-project / realar

5 kB Advanced state manager for React
MIT License
45 stars 0 forks source link
data-flow decorators frontend in-production model observable react react-hooks reactive reactive-programming state-manager stream-programming

Realar

npm version npm bundle size code coverage typescript supported

Realar state manager targeted to all scale applications up to complex enterprise solutions on a modular architecture. And has an incredible small size 5 kB for all you need.

Usage

You can make stores and "actions" play on runkit

const store = value(0)

const add = store.updater((state, num: number) => state + num)
const inc = store.updater(state => state + 1)

And bind to React easily play on codesandbox

const App = () => {
  const state = useValue(store)

  return <p>{state}
    <button onClick={inc}>+</button>
  </p>
}

You can make streams play on runkit

const addendum = value('0')
  .pre((ev: ChangeEvent<HTMLInputElement>) => ev.target.value)

const sum = signal()
  .map(() => +addendum.val)
  .filter()
  .to(add)

And bind to React play on codesandbox

const App = () => {
  const addendumState = useValue(addendum)

  return <p>
    <input value={addendumState} onChange={addendum} />
    <button onClick={sum}>sum</button>
  </p>
}

You can use classes with decorators

class Counter {
  @prop state = 0

  add = (num) => this.state += num
  inc = () => this.add(1)
}

And bind to React play on codesandbox

const App = observe(() => {
  const { state, inc } = useLocal(Counter)

  return <p>{state}
    <button onClick={inc}>+</button>
  </p>
})

And you can use it together play on codesandbox

const counter = new Counter()

const double = value.from(() => counter.state)
  .map(num => num * 2)

export const App = observe(() => (
  <p>
    {double.val}
    <button onClick={counter.inc}>+</button>
  </p>
))

Features

Documentation

Installation

npm install realar
# or
yarn add realar

Demos

In Production

Articles

Sponsor

I’m looking for a sponsor because my hands have already been burning from continuing development non-stop! I want to make a beautiful form framework and a streams framework for nodes, with core on Realar. I would like to start recording teaching videos about all actual questions on the modern frontend field. And I dream of writing an open book. If you know any methods for searching sponsors, or if some of your friends know something, I urge you to tell me mail@betula.co. It will be your great contribution to make a better world!

Enjoy and happy coding!