Closed jessehattabaugh closed 9 years ago
No, the ViewModel doesn't know anything about the DOM elements it's bound to. When Observables change the binding system automatically updates the DOM. The binding system also attaches event handlers so ideally the developer never actually interacts with the DOM directly. If you consider VDOM's relation to the DOM to be implicit then you should consider KO's View Bindings the same way.
I think it's really important to note that the developer has to interactively change Observables from Event Handlers in order to actually push data around. That's where KO's reactivity breaks down.
So if you want to make it more succinct, I'd put it this way;
View => ViewModel <- View
If you consider VDOM's relation to the DOM to be implicit then you should consider KO's View Bindings the same way.
You're right. Actually, I thought about removal of that VDOM because it's implicit part.
What's about that MVVM. Why don't we show the Model part? Because it's pure data?
Model is kind of optional actually, KO leaves it up to you. When I create one I use ko.observables and ko.computeds so that the data flows reactively. But the ViewModel always acts as the intermediary to the View so it looks like this
View => ViewModel <- Model <- ViewModel <- View
@jessehattabaugh could you add "KO with Model" diagram to the whole picture? (in other PR) This is very interesting.
"Commands" means "Event Handlers" and "Bindings" means "DOM mutations"
I think this is where KO stands. ko.observables are totally different from Rx Observables of course, but they do allow for reactive programming in that the code that updates them doesn't need to know anything about the code that depends on them.
Let me know what you think, cause I've done a lot of KO programming and I'm trying to move toward Rx streams now and it's confusing me :-)