Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/dragos-tudor/frontend-states

Rewritten React redux library [functional principles].
https://github.com/dragos-tudor/frontend-states

functional functional-components functional-programming react-redux redux states

Last synced: about 1 month ago
JSON representation

Rewritten React redux library [functional principles].

Awesome Lists containing this project

README

        

## Frontend states library
- simplified React-Redux like library.
- Deno-based states management library [Node-free].
- functional-style library [OOP-free].

### Usage
```javascript
import {render} from "/scripts/rendering.js"
import {createAction, createStoreState, createReducer, dispatchAction, getStoreStates, setSelectors, useSelector, Store} from "/scripts/states.js"

const changeAuthAction = createAction("userState/changeAuth", {isAuth: true})
const userState = createStoreState("userState", ({ isAuth: false }))
const userStateReducer = createReducer("userState", {
changeAuth: (userState, action) => ({ ...userState, ...action.payload })
})

export const App = () =>



export const UserLogin = (props, elem) => {
const selectors = setSelectors(elem)
const states = getStoreStates(elem)
const isAuth = useSelector(selectors, "isAuth", (states) => states.userState.isAuth, states)

return isAuth?

{props.logged}
:
dispatchAction(elem, changeAuthAction)}>{props.login}
}

render(, document.body)
```

### Modules
- *high-level modules*: states, states-components.
- *low-level modules*: states-actions, states-html, states-middlewares, states-reducers, states-states, states-selectors, states-equalities.
- *low-level modules* completely independent ["parallel" modules].

### [State](./states/)
- main functionality: dispatch actions, reduce states, update states consumers.
- state means one states slice.
- reducer means one group of change state funcs.
- states operations:
- `dispatchAction` if action change states then update consumers.
- `chainMiddlewares` send actions through middlewares chain.
- `runAction` based on action type reduce state.
- `updateConsumers`:
- when reduced state is different than previous state.
- when previous selectors values are different than reduced state selectors values.

### [Components](./states-components/)
- main functionality: implement states components.
- `Store`: register state, state reducer, actions middleware.