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

Breaking change: Microcosm forks can not add domains at the same key, only one domain per key #427

Closed nhunzaker closed 6 years ago

nhunzaker commented 7 years ago

Generally I want to make Domain mounting more strict so that I can add some optimizations and support new features. For some new features I need isolation between domains. Sharing keys, mounting a domain to the same key as a parent, and root level Domains are problematic for those use cases.

No duplicate domain keys on forks

While I like forks for mounting new state, I think I was wrong to allow them to process data again:

let parent = new Microcosm()
parent.addDomain('planets', {...})

let child = parent.fork
child.addDomain('planets', {...}) // Add new processors on top of whatever the parent gives you

The original idea was to use this for features like pagination and layering on app section specific data to a resource. It turns out that this just makes things complicated and our presenter models are more appropriate for that.

It also causes a lot of internal complexity and extra object clones, and I'd appreciate not having to maintain that.

No duplicate domain keys on the same repo

Additionally, I'd like to make it so that you can only mount one domain per key. Adding more than one domain for the same key has only caused trouble. One alternative would be to allow you to add "subdomains" at specific keys within a root level domain.

No root level domains

I want to get rid of root level domains as a part of this purge as well. They prevent us from doing some neat optimizations and other future ideas for domains:

this.addDomain([], RootDomain)