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 29 forks source link

Domains manage their own history #507

Open nhunzaker opened 6 years ago

nhunzaker commented 6 years ago

This is a placeholder issue for me to do some thinking about the relationship between History and Domains.

Right now domains already maintain a ledger of state revisions for outstanding actions. There is duplication between the history, it's underlying tree data structure, and this ledger. This isn't a functional issue, more of bad feel.

Instead, each domain could manage their own history. This would also let you do some pretty neat stuff:

Patch/Reset

This also allows an optimization for patch/reset: If a domain's state is patched, the state of all prior actions will always be overridden. There is no reason to process them. Unfortunately we can't do anything about this until Domains manage their own history (assuming this is a good idea)

A user logs out

There is another use case: What happens when a user logs out? In this case, you don't want to hold on to any information about the prior user, however this distinction might be split across several domains. It would be valuable to be able to "lose" revision history for a specific domain.

Domains in web workers

Additionally, if each domain has its own history, there's nothing tying them to the main thread. You could easily run a domain inside of a web-worker.