Code Monkey home page Code Monkey logo

Comments (5)

juliocesar avatar juliocesar commented on August 30, 2024

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.

RobertButera avatar RobertButera commented on August 30, 2024

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.

juliocesar avatar juliocesar commented on August 30, 2024

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.

RobertButera avatar RobertButera commented on August 30, 2024

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.

juliocesar avatar juliocesar commented on August 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.