All Projects → Lucifier129 → relite

Lucifier129 / relite

Licence: MIT license
a redux-like library for managing state with simpler api

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to relite

Freezer
A tree data structure that emits events on updates, even if the modification is triggered by one of the leaves, making it easier to think in a reactive way.
Stars: ✭ 1,268 (+2013.33%)
Mutual labels:  flux, immutable, store
universal-routed-flux-demo
The code in this repo is intended for people who want to get started building universal flux applications, with modern and exciting technologies such as Reactjs, React Router and es6.
Stars: ✭ 31 (-48.33%)
Mutual labels:  flux, immutable
Reatom
State manager with a focus of all needs
Stars: ✭ 567 (+845%)
Mutual labels:  flux, store
RxReduxK
Micro-framework for Redux implemented in Kotlin
Stars: ✭ 65 (+8.33%)
Mutual labels:  flux, store
General Store
Simple, flexible store implementation for Flux. #hubspot-open-source
Stars: ✭ 171 (+185%)
Mutual labels:  flux, store
mafuba
Simple state container for react apps.
Stars: ✭ 20 (-66.67%)
Mutual labels:  flux, store
Flooks
🍸 A state manager for React Hooks
Stars: ✭ 201 (+235%)
Mutual labels:  flux, store
boutique
Immutable data storage
Stars: ✭ 44 (-26.67%)
Mutual labels:  immutable, store
Shopixl
Open-source, self-hosted, Buycraft alternative
Stars: ✭ 17 (-71.67%)
Mutual labels:  store
semicon
A collection of icons for the Semantic Web and Linked Open Data world.
Stars: ✭ 20 (-66.67%)
Mutual labels:  store
bs-immutablejs
Reason + BuckleScript bindings to Immutable.js
Stars: ✭ 28 (-53.33%)
Mutual labels:  immutable
keshi
A better in-memory cache for Node and the browser
Stars: ✭ 76 (+26.67%)
Mutual labels:  store
Open-Mam
Open Source Mobile Application Management (WORK IN PROGRESS)
Stars: ✭ 28 (-53.33%)
Mutual labels:  store
mutable
State containers with dirty checking and more
Stars: ✭ 32 (-46.67%)
Mutual labels:  flux
react-evoke
Straightforward action-driven state management for straightforward apps built with Suspense
Stars: ✭ 15 (-75%)
Mutual labels:  flux
vue-registrar
☘️ A package that dynamically registers your components and vuex modules
Stars: ✭ 17 (-71.67%)
Mutual labels:  store
peds
Type safe persistent/immutable data structures for Go
Stars: ✭ 57 (-5%)
Mutual labels:  immutable
GeometricFlux.jl
Geometric Deep Learning for Flux
Stars: ✭ 288 (+380%)
Mutual labels:  flux
continuous-analytics-examples
A collection of examples of continuous analytics.
Stars: ✭ 17 (-71.67%)
Mutual labels:  flux
gelidum
Freeze your objects in python
Stars: ✭ 50 (-16.67%)
Mutual labels:  immutable

relite

a redux-like library for managing state with simpler api (1kb)

Why

redux is awesome, but is not enough simple for small and middle application.

With relite, we don't need to combine | apply | bind anything, just write pure function and call actions, it done.

What's new(3.0.0)

  • Supoort Typescript.

  • Delete the support of return type Promise | Function of Action.

Installtion

npm install --save relite

How to use

write pure function

the action of relite looks like a reducer of redux, but more simple and powerful.

/**
* an action consist of action-type, action-payload, action-handler and action-result
* at this example
* action-type is EXEC_BY
* action-handler is the function accepts two arguments: state and action-payload
* action-result is the result of function
*/
export let EXEC_BY = (state, input) => {
	let value = parseFloat(input, 10)
	return isNaN(value) ? state : {
		...state,
		count: state.count + value
	}
}

create store by actions and initialState

import { createStore } from 'relite'
import * as actions from './actions'

let initialState = {
	count: 0,
}
let store = createStore(actions, intialState)

/*
* relite will bind state for every actions you gave to `createStore`
* so all the functions in store.actions can only accept one argument, action-payload
* no need to bindActionCreators
* each actions return currentState or promise with currentState
*/
let { INCREMENT, EXEC_BY } = store.actions
INCREMENT() // -> { count: 1 }
EXEC_ASYNC(9) // -> Promise[[{ count: 10 }]]

/**
* subscribe store by store.subscribe
* when the state was changed/updateed, relite would trigger the listeners
* if action-handler return the same state, listeners would not be triggered
*/
let unsubscribe = store.subscribe((data) => {
	let {
		actionType, // action-type
		actionPayload, // action-payload
		start, // start date
		end, // end date
		previousState, // prev-state
		currentState // cur-state
	} = data
})

let newState = {
	count: 0,
}
let simulateData = {
	actionType: 'REPLACE_STATE',
	actionPayload: null,
	start: new Date(),
	end: new Date,
	previousState: store.getState(), // get current state
	currentState: newState,
}
let keepSilent = false // if true, it will not trigger listeners

// replace state by store.replaceState
store.replaceState(newState, simulateData, false)

// trigger listener by store.publish
store.publish(simulateData)

store.dispatch('EXEC_ASYNC', 10) // dispatch the action manually

use build-in logger

import { createStore } from 'relite'
import * as actions from './actions'

let initialState = {
	count: 0,
}
let store = createStore(actions, intialState)

store.subscribe(render)

render()

function render() {
	ReactDOM.render(
		<App {...store.getState()} {...store.actions} />,
		document.getElementById('container')
	)
}

End

Issue and pull request is welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].