ractivejs/ractive — pull request #1590 by Rich-Harris (2014-12-18 05:17:24+00:00)
Title: reduce coupling between viewmodel and ractive instance

**not ready for merge**

One of the things I've come to realise over the last few days of refactoring some of Ractive's internals is that the different bits of the system are probably a bit more tightly coupled than is ideal. Some coupling is inevitable (since Ractive has evolved fairly organically), even desirable (in my experience, religiously modular systems tend to require cumbersome, object-defeating and performance-degrading glue code), but I think we can reduce it. At the moment, it can be hard to make changes to one part of the system without butterfly effects.

As a starting point I'm looking at `Viewmodel`. It seems that the less that `ractive.viewmodel` knows about `ractive`, the better. This PR shuffles things about a bit so that an instance of `Viewmodel` is a bit more agnostic about how it's used. Not completely agnostic - there are some edge cases at the moment around adaptors and computations that depend on unresolved properties - but more so than before. For example, it doesn't depend on `this.ractive.data`, but rather `this.data`, just as it has `this.mappings` and `this.computations`.

It occurs to me that we could remove certain read-only properties from `ractive` if `ractive.viewmodel` is the only thing that cares about them and has independent access to them - `ractive.computed`, `ractive.adapt`, possibly even `ractive.data`. (The same is probably true of `ractive.template`, but that's a separate thing.)