0.1.8 • Published 6 years ago

statenano v0.1.8

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

Statenano

Statenano is a small state handler with a fairly simple API, which exploits the potential of classes when managing states in an application.

Why use classes?

the classes offer a simple and minimalist inheritance, Statenano uses this to compose states based on classes.

yarn

yarn add -D statenano

npm

npm install -D statenano

Instancia

Statenano by default has a simple interface with 2 methods update and subscribe, update feeds the state with new properties and in turn notifies subscribers of each update.

import State from "statenano";

let initState = { type: "sample" };


let state = new State(initState);

initialState

as you noticed in the previous instance you can define an initial state as the first argument of State

instance.update(mixed objet)

allows subscribers to alert a change within the state

import State from "statenano";

let state = new State();

state.subscribe(state => {});

state.update({ type: "sample" });

instance.subscribe( function )

allows you to subscribe to a status update

Inheritance

Statenano to be a class facilitates the edition of behavior based on the inheritance

import State from "statenano";

class Todo extends State{
    constructor(){
        super();
        this.tasks = [];
    }
    addTask(task){
        this.update({
            tasks : this.tasks.concat({task})
        })
    }
    removeTask(task){
        this.update({
            tasks : this.tasks.filter((save)=>save !== task)
        })
    }
}


let state = new Todo;

    state.subscribe(()=>{
        state.tasks.map((task)=>{
            console.log(task)
        })
    })

    state.addTask("Learn statenano");
    

Examples

Tipolink
TODOCodeSandbox
SHOPProductos - Bodeguita Agroecologica
npmgituso
preact-statenanopreact-statenanoIs a small library that allows you to synchronize state events created on the basis of Statenano with components created with preact all thanks to the high order components.
0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago