reclare

Declarative State and Logic Management

  • 所有者: oguzgelal/reclare
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

What is Reclare ?

Reclare is a lightweight library to manage the application state alongside business logic, without compromising from the predictability of the state. It is inspired by Redux and the Elm architecture and includes many of the familiar concepts.

Key Features

  • Manage state and logic together
  • Unidirectional data flows
  • Predictable, immutable state
  • Handle requests / side effects
  • Built-in way to modularise your code
  • For all frameworks - offical middleware for React
  • Easy to install, minimal configuration
  • Easy-to-grasp concepts

Basic Example

View on JSFiddle

Below is an example of what declarations would look like in the context of a simple counter implementation with one simple rule: the counter cannot go below zero:

{
  on: 'increment',
  reducer: ({ state }) => ({ ...state, counter: state.counter + 1 })
  reaction: ({ state }) => console.log(`Incremented to ${state.counter}`)
},
{
  on: 'decrement',
  when: ({ state }) => state.counter > 0,
  reducer: ({ state }) => ({ ...state, counter: state.counter - 1 }),
  reaction: ({ state }) => console.log(`Decremented to ${state.counter}`)
},
{
  on: 'decrement',
  when: ({ state }) => state.counter <= 0,
  reaction: () => alert('Counter already at zero')
}

Upon the broadcast of increment, the first declaration will be invoked. It will increment the counter and log the updated number. decrement event hits two declarations. First one only invokes when the counter is greater than zero and decrements the counter. Second one invokes when counter is zero, and alerts the error message.

Broadcasting these events would look something like this:

<Button value="+" onClick={() => broadcast('increment')} />
<Button value="-" onClick={() => broadcast('decrement')} />

Documentation

The documentation is still under construction, it still has some missing parts. My apologies for that. I will try to complete it as soon as possible.

Click here for the documentation

Feedback

What do you think about Reclare? Do you have any ideas? I would love to hear them, and kind of feedback would be much appreciated. You can email me or contact me some other way.

Contribution

The contribution guideline for Reclare is not ready at the time being, but if you love this project and want to help, please contact me.

主要指標

概覽
名稱與所有者oguzgelal/reclare
主編程語言JavaScript
編程語言JavaScript (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2018-04-28 14:53:56
推送於2019-03-07 14:25:31
最后一次提交2019-03-07 09:25:04
發布數0
用户参与
星數281
關注者數5
派生數4
提交數175
已啟用問題?
問題數1
打開的問題數0
拉請求數1
打開的拉請求數0
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?