callbag-state-keyed

👉 Key-track callbag-state
s:
import state from 'callbag-state';
import keyed from 'callbag-state-keyed';
import subscribe from 'callbag-subscribe';
const s = state([
{ id: 1, name: 'John' },
{ id: 2, name: 'Jack' },
{ id: 3, name: 'Jill' },
]);
const k = keyed(s, p => p.id);
subscribe(console.log)(k.key(2));
s.set([
{ id: 2, name: 'Jack' },
{ id: 3, name: 'Jill' }
]);
s.set([
{ id: 2, name: 'Joe' },
{ id: 3, name: 'Jill' }
]);
► TRY IT!
👉 Modify key-tracked sub-states:
const jill = k.key(3);
subscribe(console.log)(jill);
jill.sub('name').set('Jillian');
► TRY IT!
👉 Track index of a particular key:
subscribe(console.log)(k.index(2));
s.set([
{ id: 3, name: 'Jillian' },
{ id: 2, name: 'Joe' }
]);
► TRY IT!
👉 Get detailed list changes for a keyed list:
subscribe(console.log)(k.changes());
s.set([
{ id: 4, name: 'Joseph' },
{ id: 3, name: 'Jillian' },
{ id: 1, name: 'John' },
]);
► TRY IT!
Gotchas
Same as callbag-state
.
Contribution
Be nice and respectful, more importantly super open and welcoming to all.
👉 Useful commands for working on this repo:
git clone https://github.com/loreanvictor/callbag-state-keyed.git
npm i
npm start
npm test
npm run cov:view