Comments (5)
Hey,
by reading from the DOM I really mean things such as grabbing a class name, a data-* attribute, or for example, whether a given paragraph has text matching "Book added successfully" in order to find out if the book was created.
As for using the DOM as means of data input, there really is no other way to do it, so that's a different story.
from backbone-book.
I see, so basically you shouldn't use the view to read data you can otherwise get from a model.
Would be interested to hear about what you think about when a model should be updated by a view. Should a model always accurately reflect the current state of the view, which would require a constant stream of events and parsing of the DOM or is it better to wait until the model is actually requested for use somewhere in the application and just do a batch update at that point.
Also, on a somewhat related note, you advocate views always being destructive (i.e. never append). In general I agree, but aren't there some exceptions to this rule? For example if you have a long list of rendered subviews and need to add an extra one (because a new model has been created)? Isn't it wasteful to trigger such a large DOM update when you could just make a small one?
Rob
from backbone-book.
In general, I always re-render my views when a change
event occurs, so I'm not sure what you mean by a constant stream of events. It generally is cheap enough of an operation that even if you call it a lot it'll still be ok.
As for render
being destructive, in the case you described, you're rendering a collection, and when you add to a collection, it's not a matter of re-rendering, but trapping the add
event and really just appending a new one.
from backbone-book.
What I mean is if you say had a text input element on a page, do you update it's corresponding model on every keystroke/when focus is moved from the element or when the model is requested from something in the application. In other words how important is it for a model to always be in sync with it's corresponding view (when the view is undergoing change from user input)
from backbone-book.
That depends on whether you consider the value in a text field to always have to be an accurate representation of what's in the model. The question is: is this a necessary feature? If so then sure, you'd trap every key pressed and update the model accordingly.
This question really relates to that need (and not so much to Backbone itself). If it doesn't exist, you could probably follow a less granular approach and, say, when submitting the form you'd update the model.
from backbone-book.
Related Issues (8)
- Chapter "Views", part on placing 'tagName' and 'className' into a template - problem/question HOT 4
- Views - Model presenter object JS script issue HOT 1
- navigate from chapter to chapter HOT 2
- Coffeescript/Javascript switch not working on Testing chapter HOT 3
- Coffeescript/javascript toggle on spacebar
- Chapter "Views", part about re-render on each change on a model HOT 1
- Routing And Controllers - some text is unclear HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from backbone-book.