Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cristianbote/preducs
Easy state handling of state updates
https://github.com/cristianbote/preducs
javascript preducs redux state state-management
Last synced: 21 days ago
JSON representation
Easy state handling of state updates
- Host: GitHub
- URL: https://github.com/cristianbote/preducs
- Owner: cristianbote
- License: mit
- Created: 2017-03-07T22:07:08.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-05-09T09:36:39.000Z (over 7 years ago)
- Last Synced: 2024-04-23T10:45:45.558Z (7 months ago)
- Topics: javascript, preducs, redux, state, state-management
- Language: JavaScript
- Homepage:
- Size: 54.7 KB
- Stars: 14
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# preducs
Tiny library(1.3Kb) to manage your application state. It supports interceptors(modifiers) to handle and modify data on the fly.
## Status
[![npm version](https://badge.fury.io/js/preducs.svg)](https://badge.fury.io/js/preducs) [![Build Status](https://travis-ci.org/cristianbote/preducs.svg?branch=master)](https://travis-ci.org/cristianbote/preducs)## How to use it
Check out the `tests` folder for usages, but this is the common usage.```javascript
import createStore from 'preducs';// Create the store
let store = createStore({
loading: true // Your data
});// Subscribe to updates
let unsubscribe = store.subscribeToUpdates((state) => {
console.log('I got updated', state);
// Unsubscribe the current listener
unsubscribe();
});// Our lightweight interceptor(modifier)
const initialDataModifier = (currentState, newState) => {
return fetch('/api/endpoint')
.then(res => {
return {
...newState,
...res.json()
}
});
};// Update the store, with a call to a api
store.update({
loading: false
}, initialDataModifier);```
And that's about it!## Instal it
`npm install preducs`or
`yarn add preducs`