Skip to content

Instantly share code, notes, and snippets.

@artalar
Created December 20, 2018 07:57
Show Gist options
  • Select an option

  • Save artalar/97b1747bd5523a4672e9a6b02b559962 to your computer and use it in GitHub Desktop.

Select an option

Save artalar/97b1747bd5523a4672e9a6b02b559962 to your computer and use it in GitHub Desktop.
// implicit cohesions
root = store({ data: { list: [] }, loading: false, error: null })
.on(req, state => ({ ...state, error: null, loading: true }))
.on(res, (state, list) => ({ ...state, data: { list }, loading: false }))
.on(err, (state, error) => ({ ...state, error, loading: false }));
// explicit cohesions
export const data = store({ list: [] })
.on(res, list => ({ list }));
export const error = store(null)
.on(req, () => null)
.on(err, e => e);
export const loading = store(false)
.on(req, () => true)
.on(res, () => false)
.on(err, () => false);
root = store({ data, error, loading });
@artalar

artalar commented Dec 20, 2018

Copy link
Copy Markdown
Author
store({ prop: null }).subscribe(1)
.map(v => v.prop).subscribe(2)
.map(prop => ({prop})).subscribe(3)
.map(v => v.prop).subscribe(4)
// VS
const prop = store(null)
.subscribe(2)
.subscribe(3)
store({ prop })
.subscribe(1)
.subscribe(3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment