Skip to content

Instantly share code, notes, and snippets.

@Sangrene
Created May 27, 2019 14:00
Show Gist options
  • Save Sangrene/e76756b6f0baf8727a26283437a4ea1d to your computer and use it in GitHub Desktop.
Save Sangrene/e76756b6f0baf8727a26283437a4ea1d to your computer and use it in GitHub Desktop.
const bills = createStore([{id: 0, state: 0}, {id: 1, state: 2}]);
const selected = createStore(0);
const cheatersStore = createStoreObject({
bills,
selected
})
const validate = createEvent('validate')
bills.on(validate, (bills, idBill) => {
const idx = bills.findIndex(bill => bill.id === idBill);
bills[idx].state = 1;
return bills;
});
const reject = createEvent('reject')
bills.on(reject, (bills, idBill) => {
const idx = bills.findIndex(bill => bill.id === idBill);
bills[idx].state = 2;
return bills;
});
const selectBill = createEvent("select bill");
selected.on(selectBill, (previous, newSelected) => newSelected);
selected.on(validate, (previous, idBill) => previous + 1);
validate(1);
reject(0);
selectBill(20);
validate(1);
bills.watch(console.log);
selected.watch(console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment