Easy state handling of state updates
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
dist
tests
.gitignore
.travis.yml
LICENSE
README.md
index.js
package.json
webpack.build.js
yarn.lock

README.md

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 Build Status

How to use it

Check out the tests folder for usages, but this is the common usage.

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