V3rtigo is a state management library for Ferrugemjs applications.
npm install v3rtigo --save
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();
eg. app/hello-world.js
import countStore from "../stores/count";
export class HelloWorld{
get count(){
return countStore.getState();
}
incrementHandler(){
countStore.increment();
}
}
eg. app/hello-world.html
<template>
<require from="v3rtigo as v3r" type="namespace"/>
<require from="../stores/count as countStore" type="script"/>
<div>
<h4>${this.count}</h4>
<button click.trigger="this.incrementHandler"/>
<v3r:connect-provider
store="${countStore.default}"
event.handler="this.refresh"
/>
</div>
</template>
const v3rtigo = require('v3rtigo/dist/commonjs/store');
class CountStore extends v3rtigo.Store{
}
export default new CountStore();
<v3r:connect-provider
store="${countStore.default}"
event.handler="this.evtHandler"
event-type="other-store-event"
/>
-
store : a store which will be connected (obrigatory).
-
event.handler : component handler function (obrigatory).
-
event-type : store event which will be connected (optional, default is 'state:changed').
let payload = {desc: 'a basic info!'};
store.dispatch('storeMethod', payload);
store.dispatch({type: 'storeMethod' , payload});
store.subscribe('storeMethod', payload => {
console.log('subscribe working', payload);
});
let unsub = store.subscribe('storeMethod', payload => {
console.log('subscribe working once time ', payload);
unsub();
});
...
save(item){
...
this.emit('item:saved', item);
}
...