Skip to content

cristianbote/preducs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Easy state handling of state updates

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published