MDV: How to know that view has updated on model changes

47 views
Skip to first unread message

akhile...@gmail.com

unread,
Aug 8, 2013, 6:47:03 PM8/8/13
to polym...@googlegroups.com
Is there a way (event/method) to get a callback when a template based view has updated after the model changes?

Rafael Weinstein

unread,
Aug 8, 2013, 6:48:55 PM8/8/13
to Akhilesh Gupta, polymer-dev
There's no MDV-way to directly discover this (at the moment). You can
obviously use Mutation Observers to observe the DOM changing.

Can you say more about your use case?

On Thu, Aug 8, 2013 at 3:47 PM, <akhile...@gmail.com> wrote:
> Is there a way (event/method) to get a callback when a template based view
> has updated after the model changes?
>
> Follow us on Google+ : plus.google.com/107187849809354688692
> ---
> You received this message because you are subscribed to the Google Groups
> "Polymer" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to polymer-dev...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/polymer-dev/477914f6-8ae2-464e-bd3b-3a12bfd6c563%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

akhile...@gmail.com

unread,
Aug 8, 2013, 7:00:59 PM8/8/13
to polym...@googlegroups.com, Akhilesh Gupta
Sure. One use case is where I am trying to integrate my custom element's view, which is essentially a UL element generated and managed by MDV, with JQueryMobile to apply the styling. Now JQueryMobile needs to know whenever the children of my UL element change so that JQueryMobile can apply it's styles/events to those new elements. Basically I need to call something like $('ul').listview('refresh'); whenever my list view changes.

Without knowing when the DOM has updated, I can't properly guarantee the call to the $('ul').listview('refresh') of JQueryMobile. EmberJS has an "afterRender" queue to manage such situations where one can queue up the methods to be triggered after the DOM changes.

Rafael Weinstein

unread,
Aug 8, 2013, 7:07:06 PM8/8/13
to Akhilesh Gupta, polymer-dev
Got it.

So yes, I think Mutation Observers is a good fit here. When you have
this kind of timing dependency, it's best to depend explicitly on the
thing which you are waiting for. In this case it is new children of
the UL.

A MutationObserver should be very efficient and straightforward to
implement (if the elements you care about are always direct children,
you won't even need to do subtree observation).
> https://groups.google.com/d/msgid/polymer-dev/6af4d58b-930a-48da-a753-e9697bf1d58e%40googlegroups.com.

Scott Miles

unread,
Aug 8, 2013, 9:15:05 PM8/8/13
to Rafael Weinstein, Akhilesh Gupta, polymer-dev
This has come up a few times. 

Fwiw, there is work on the drawing board to introduce sugaring to set up Mutation Observers automatically to provide signals when these changes occur.

Scott


Reply all
Reply to author
Forward
0 new messages