4 ms·
I'm afraid I do mean "real logic" -- in terms of "real function calls", or "real math", or whatever else you might want to do. Let me imagine a few more example
by jashkenas 14y ago
I'm afraid I do mean "real logic" -- in terms of "real function calls", or "real math", or whatever else you might want to do. Let me imagine a few more examples:
inflector.addCommas(arrayOfNames)
document.publicNoteCount + document.privateNoteCount
format.quote(email.selectedText())
... you always can stuff all of those things into an arbitrary "viewmodel" JSON object somewhere else outside of the template, but it's frequently clearer and more convenient just to do it where it's needed -- instead of enforcing an extra layer of indirection for no real reason -- by passing around models directly.
I guess I feel somewhat strongly about this because having multiple sources for the same truth is what gets people into trouble so often with client-side apps. (Where by a "truth" I mean something like: "What are the names of the collaborators on this document".) Having that data in your model and then again in your viewmodel, and some parts of your app access it over here, and your templates access it over there, is exactly that sort of unnecessary duplication...
- clintjhill 14y agoWe agree on having a single source of truth. I'm arguing for it to be derived in a controller and not in a view.
- ricardobeat 14y agoThen the controller becomes a second source of truth, no?