vigetlabs / microcosm

Flux with actions at center stage. Write optimistic updates, cancel requests, and track changes with ease.
http://code.viget.com/microcosm/
MIT License
487 stars 22 forks source link

Domains and effects are standalone entities #483

Closed nhunzaker closed 6 years ago

nhunzaker commented 6 years ago

This commit makes a change to the dispatch process such that domains and effects own their own dispatch. It does this by creating Effect and Domain classes.

Instead of maintaining a central "snapshot" system, each Domain maintains their own state in a ledger similar to the snapshot system. Domains can also send out updates separately.

Long term, this supports asynchronous Domains. I'd like to be able to sync a Domain to something like window location, or a web socket, and be able to maintain state that way.

What this looks like

domainEngine and effectEngine have been removed. Instead of publishing that an action was appended to history, history emits discrete state updates as actions change. These get dispatched to domains and effects. When a domain changes, it emits a new change via a Subject.

repo.push -> action -> history -> [next,complete,error] -> [domains, effects] 
codecov-io commented 6 years ago

Codecov Report

Merging #483 into master will increase coverage by 0.03%. The diff coverage is 99.02%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #483      +/-   ##
==========================================
+ Coverage    98.5%   98.54%   +0.03%     
==========================================
  Files          28       29       +1     
  Lines         671      686      +15     
  Branches      143      134       -9     
==========================================
+ Hits          661      676      +15     
  Misses          8        8              
  Partials        2        2
Impacted Files Coverage Δ
packages/microcosm/src/subject.js 100% <ø> (ø) :arrow_up:
packages/microcosm/src/install-devtools.js 100% <ø> (ø) :arrow_up:
packages/microcosm/src/history.js 100% <100%> (ø) :arrow_up:
packages/microcosm/src/ledger.js 100% <100%> (ø)
packages/microcosm/src/effect.js 100% <100%> (ø)
packages/microcosm/src/registry.js 100% <100%> (ø) :arrow_up:
packages/microcosm/src/coroutine.js 100% <100%> (ø) :arrow_up:
packages/microcosm/src/microcosm.js 100% <100%> (ø) :arrow_up:
packages/microcosm/src/domain.js 97.91% <97.91%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 6c103a4...dfb8c4a. Read the comment docs.