[ 4 posts ]

Dave Combs

  • Username: davecombs
  • Joined: Wed Jun 06, 2012 8:04 pm
  • Posts: 19
  • Location: Mountain View, CA
  • Offline
  • Profile

How to retrieve the instance of a preserved view in Y.App?

Post Posted: Mon Jun 25, 2012 12:37 pm
+0-
My app happens to have single instances of a number of views, where I just apply data to them as needed--there's no need to have multiple copies of each. So I've declared the views as preserved in the Y.App() constructor 'views' list. The question: once I've called 'createView' or 'showView', how do I retrieve the instance of the view? I've tried getting the view metadata and examining the 'instance' property, but that never seems to change from null.

Is there a predefined method for this? If not, how would you do it?

Dave

Eric Ferraiuolo

YUI Developer

  • Username: ericf
  • Joined: Mon Jan 12, 2009 8:26 pm
  • Posts: 380
  • Location: Boston, MA
  • Twitter: ericf
  • GitHub: ericf
  • Gists: ericf
  • IRC: eric_f
  • YUI Developer
  • Offline
  • Profile
Tags:

Re: How to retrieve the instance of a preserved view in Y.Ap

Post Posted: Tue Jun 26, 2012 7:53 am
+0-
Dave,

There currently isn't an API to support this, it is something I've been thinking about and wanting to build in. The way you are currently looking inside of the `views` object and referencing a view's `instance` property is currently the only way to do it.

The issue with `instance` being `null` is that the view must be "attached" and therefore become the `activeView` (via the `showView()` method) before it will be registered on the `instance` property.
https://github.com/yui/yui3/blob/master ... se.js#L444

The `preserve` config option flags the "detach" process to not destroy the view and to leave `instance` pointing to it.

Back to your original task of applying new data to an existing view, this is possibile as of 3.5.1. When calling the `showView()` method, you can pass options, and there are two newer options that you'll be interested in: `update`, and `render`. This gives you control over updating the attributes of an existing view, and whether or not you want to re-render that existing view. The `update` option was added specifically for this use case.

Code:
app.showView('foo', newData, {update: true});


You can see more details on these options that can be passed to `showView()` here:
http://yuilibrary.com/yui/docs/app/#und ... ew-options

Roman Orazmagomedov

  • Username: oraz
  • Joined: Tue May 08, 2012 9:11 am
  • Posts: 3
  • GitHub: oraz
  • Gists: oraz
  • Offline
  • Profile

Re: How to retrieve the instance of a preserved view in Y.Ap

Post Posted: Tue Jun 26, 2012 10:47 am
+0-
Hi David,

You can get current view instance by handling 'activeViewChange' event:
myApp.after('activeViewChange', function(evt) {
var viewInstance = evt.newVal;
});

Also, accordingly to the docs, you can pass callback function to showView method. The callback will be invoked when view is ready to use and its instance will be passed to callback. But I didn't test this way. See http://yuilibrary.com/yui/docs/api/clas ... d_showView.

Eric Ferraiuolo

YUI Developer

  • Username: ericf
  • Joined: Mon Jan 12, 2009 8:26 pm
  • Posts: 380
  • Location: Boston, MA
  • Twitter: ericf
  • GitHub: ericf
  • Gists: ericf
  • IRC: eric_f
  • YUI Developer
  • Offline
  • Profile
Tags:

Re: How to retrieve the instance of a preserved view in Y.Ap

Post Posted: Thu Jul 05, 2012 6:52 am
+0-
Dave, Roman brings up a good point, I might have been reading too far into your question. Like Roman pointed out, passing a callback function to `showView()` will result in that function being called with the view instance being passed as an argument.
  [ 4 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum