1.1.0 • Published 7 years ago
vertex-store v1.1.0
import Vertex from 'vertex-store';
const counter1=(pre=0,event)=>{
return pre+event.data;
}
const counter2=(pre=0,event)=>{
return pre+2*event.data;
}
const counter3=(pre=0,event)=>{
return pre+3*event.data;
}
const cursor1=new Vertex({counter1,counter2});
const cursor2=new Vertex({counter3});
const unsubscribe=cursor1.subscribe((event)=>{
console.log('should not be notified',event,cursor1.getState());
});
unsubscribe();
cursor2.subscribe((event)=>{
console.log('notified at cursor2',event, cursor2.getState());
});
cursor1.use({cursor2});
cursor1.actions.counter1({data: 1})
cursor1.actions.counter2({data: 2})
cursor1.actions.cursor2({type: 'counter3',data: {data: 3}} )
cursor2.actions.counter3({data: 4});