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

Consider providing a mechanism to easily observe a set of property paths #194

Closed
sorvell opened this issue Jun 27, 2013 · 3 comments
Closed
Assignees

Comments

@sorvell
Copy link
Contributor

sorvell commented Jun 27, 2013

It's common to want pass object data to a custom element and want to react to changes in some set of paths in that object. We should consider adding a mechanism to make this pattern easy to implement.

It might look like this:

observers: {
  'obj.name.first obj.name.last': 'nameChanged'
}

and this would mean, whenever this.obj.name.first|last changes, the nameChanged method should be called.

@morethanreal
Copy link
Contributor

How about inverting the key-value of the dictionary, ie. 'nameChanged': ['obj.name.first', 'obj.name.last'] etc? The list of paths to observe could get quite long. One example would be the various animation properties in g-animation. It would also make it easier to inherit.

@aeosynth
Copy link

you may want to look at rfc 6901:

JSON Pointer defines a string syntax for identifying a specific value
within a JavaScript Object Notation (JSON) document.

it uses slashes instead of dots as separators

@ghost ghost assigned sorvell Sep 25, 2013
@sorvell
Copy link
Contributor Author

sorvell commented Oct 16, 2013

Fixed via merging CompoundPathObserver branch, fea8c48.

We added an observe block where custom change handlers can be specified. This has a number of advantages. You can use the change handler names you want. If multiple properties are registered to fire the same change handler, it will only fire once if any of the set of properties changes 'at the same time', and it's possible to observe subpaths (a.b.c). For example,

observe: {
  foo: 'invalidate',
  bar: 'invalidate',
  'a.b.c': 'subPathChanged'
},
invalidate: function() { ... },
subPathChanged() { ... },

@sorvell sorvell closed this as completed Oct 16, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants