3.0.0 • Published 5 years ago

v3rtigo v3.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

V3rtigo

V3rtigo is a state management library for Ferrugemjs applications.

NPM

install

npm install v3rtigo --save

usage

create a store

eg. stores/count.js

import { Store } from 'v3rtigo';

class CountStore extends Store{
    constructor(){
        super();
        this.state = 1;
    }
    public increment(){
        this.setState( this.getState() + 1 );
    }
}

export default new CountStore();

import store into component

eg. app/hello-world.js

import countStore from "../stores/count";

export class HelloWorld{
  get count(){
    return countStore.getState();
  }
  incrementHandler(){
    countStore.increment();
  }
}

connect-provider componente

eg. app/hello-world.html

<template>
  <require from="v3rtigo as v3r" type="namespace"/>
  <require from="../stores/count as countStore" type="script"/>
  <div>
    <v3r:connect-provider
      stores="${[countStore.default]}"
    >
      <h4>${this.count}</h4>
      <button click.trigger="this.incrementHandler"/>
    </v3r:connect-provider>
  </div>
</template>

With commonjs

const v3rtigo = require('v3rtigo/dist/commonjs/store');

class CountStore extends v3rtigo.Store{
  
}
export default new CountStore();

connect-provider properties

<v3r:connect-provider 
   stores="${[countStore.default]}"
>
...
</v3r:connect-provider>
  • stores : a list of stores which will be connected (obrigatory).

Store methods

dispatch

let payload = {desc: 'a basic info!'};
store.dispatch('storeMethod', payload);
store.dispatch({type: 'storeMethod' , payload});

subscribe

store.subscribe('storeMethod', payload => {
  console.log('subscribe working', payload);
});

unsubscribe

let unsub = store.subscribe('storeMethod', payload => {
  console.log('subscribe working once time ', payload);
  unsub();
});

emit (it's a store protected method)

...
  save(item){
    ...
    this.emit('item:saved', item);
  }
...
3.0.0

5 years ago

2.0.3

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago