Raynos / mercury

A truly modular frontend framework
http://raynos.github.io/mercury/
MIT License
2.82k stars 142 forks source link

observ-* and Object.observe, immutability of state and its content #144

Closed kuraga closed 9 years ago

kuraga commented 9 years ago

Hey folks,

can we replace observ-* dependencies with a Object.observe technique in the future?

What's your thoughts?

Raynos commented 9 years ago

No.

Object.observe allows you to observe changes, however that requires you to mutate your state object. If you read the observ-* source code, you find that all mutation methods actually make shallow copies.

The ability to "observe" state is less important then the ability to keep the state immutable.

kuraga commented 9 years ago

UPD: It's clear now, thanks to @kristianmandrup. We do mutate a state's reference. But don't mutete state. Like in git. Every commit is immutable. We mutate HEAD only.

Original question: Where does immutability end and does mutability start?

Facts: 1a) we set new value property 1b) and then get new state via event (channel), i.e. not from previous render; 2) leaves are mutable.

So, do we store current state? Where? So, do we change it? Do we mutate it? Or do we mutate state reference but not the state object, do you mean?

kristianmandrup commented 9 years ago

You don't want to mutate EVER (IMO)! See clojure, datomic etc. Mutable programs were mostly "invented" for ease of use and limited memory back in the day... a mutable app doesn't scale, causing too many problems as it grows...

https://thechangelog.com/rich-hickeys-greatest-hits/ http://www.datomic.com/videos.html https://vimeo.com/97408202

We are finally rethinking our whole approach to computing, leveraging our much improved infrastructure. Save current state in Datomic, simple source of truth. See also: datomicjs ;)