Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dependent fields? #25

Open
rubiii opened this issue Aug 5, 2013 · 2 comments
Open

dependent fields? #25

rubiii opened this issue Aug 5, 2013 · 2 comments
Assignees
Labels

Comments

@rubiii
Copy link
Collaborator

rubiii commented Aug 5, 2013

hey @asciidisco,

i may be missing something, but it doesn't look like mutators supports dependent fields, right?
is there any good reason against this? if so, would you recommend any other library?

cheers,
daniel

@ghost ghost assigned asciidisco and rubiii Oct 30, 2013
@cluebcke
Copy link
Collaborator

cluebcke commented Dec 7, 2013

Hi @rubiii,

(@asciidisco has gotten super busy and has asked for folks to help out around here, so maybe I can help implement this. If you're not interested in the issue anymore, feel free to ignore; I still like the idea :)

You're correct, Mutators does not currently support dependency declarations. There are at least a couple of other libraries, backbone-computedfields and backbone-spark, that do. (backbone-spark is apparently heavily based on backbone-mutators).

This would be a great feature to add, and I think would close the major gap that prompted computed-fields and spark to be created. To make sure we're on the same page, let me state what I think the two uses/benefits of this are, and tell me if you agree:

  1. When a field a getter depends on is modified, backbone.mutators will emit a change event for the dependent field, so listeners know the computed value has changed.
  2. Getters declared with dependencies can have their values cached the first time they're accessed, and the computation (the body of the get function) only needs to be run when one of the dependencies is updated.

The first one seems like a slam-dunk to me. The second one seems like a great idea, but it worries me a little, because backbone.mutators can't really tell if your get function depends on, and only on, the fields listed independs. This means that if somebody adds a depends field to a getter, but doesn't actually declare every field the getter depends on, then the getter could return stale results from its cache.

Let me know what you think.

@chiplay
Copy link
Collaborator

chiplay commented Feb 18, 2014

+1 for this feature. We use Mutators along side BB Stickit, so without this feature stickit wont correctly update our 'bound' dom elements when observing a mutator property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants