support for referencing view in ViewState by path #365

Closed
wants to merge 1 commit into
from

Projects

None yet

5 participants

@tchak
Member
tchak commented Jan 9, 2012

No description provided.

@pangratz pangratz commented on the diff Jan 9, 2012
packages/ember-states/lib/view_state.js
@@ -16,6 +23,13 @@ Ember.ViewState = Ember.State.extend({
exit: function(stateManager) {
var view = get(this, 'view');
+ if (typeof view === 'string') {
+ view = getPath(view);
+ if (view) {
+ this.set('view', view);
@pangratz
pangratz Jan 9, 2012 Member

why are you setting the view again when it is removed a few lines below?

@tchak
tchak Jan 9, 2012 Member

For caching purpose. If later I reenter the state, the reference for view is there

@pangratz
pangratz Jan 9, 2012 Member

ok, I was just confused. because the view is already set in enter state ...

@tchak
tchak Jan 9, 2012 Member

hmm, this is true :) You are probably right...

@pangratz
pangratz Jan 9, 2012 Member

i was just curious. it's a useful addition btw. i was thinking about adding a templateName property. if specified, a new Ember.View.create({ templateView: ... }) is created, so there's no overhead of creating a view where you just want to specify a template on the stateView.

@tchak
tchak Jan 9, 2012 Member

I could probably integrate this in to this patch. Or you prefer add it yourself?

@pangratz
pangratz Jan 9, 2012 Member

I think @kselden has a point with his comment.

@krisselden
Member

Generally things are set by path to aid templating (like itemViewClass in CollectionView for example).

If you need the view to be defined after the state is created (not sure of the use case), why not just bind it to that path?

@tchak
Member
tchak commented Jan 10, 2012

I almost agree, but :

App.states = Em.StateManager.create({
  viewBinding: 'App.MyView'
});

App.MyView = Em.View.create();

This will fail or I will have to use App.set...
This is juste some sugar so I understand if it is rejected.

and to answer @kselden I have some states declared this way in my core app, but the corresponding views are loaded on demand in modules initialized on state enter

@wycats
Member
wycats commented Jan 21, 2012

@tchak can you show some code in a simplified use case?

@tchak
Member
tchak commented Jan 21, 2012

Her is an example alongside with a new implementation proposition (including proposition #413 from @devinus)
https://gist.github.com/1654139

Obviously this is not how I manage my modules, but it gives an idea

@tchak
Member
tchak commented Jan 26, 2012

closing this for now. I will make another PR with a new proposal

@tchak tchak closed this Jan 26, 2012
@devinus
Member
devinus commented Jan 26, 2012

For the record, I'm interested in this too.

@dichen001 dichen001 referenced this pull request in dichen001/Paper-Reading Jun 28, 2016
Open

Summary of the 20 issues in Herbsleb's 2014 FSE paper. #6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment