Created
May 27, 2019 14:00
-
-
Save Sangrene/e76756b6f0baf8727a26283437a4ea1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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