Note that there are some explanatory texts on larger screens.

plurals
  1. POEmber statemanager, controller, view, model : how to link them together?
    text
    copied!<p>I'm facing a problem where I need to link state manager, controller and view together and at the same time avoid to get an ugly spaghetti code. And the question is : which of these object should be created first and has the responsibility to create the others ?</p> <p>To be specific, here is my example. First the view is a subclass of a container view that has a collection view as child :</p> <pre><code>App.MyView = Ember.ContainerView.extend { childViews: ['streamView'] streamView: Ember.CollectionView.extend { } } </code></pre> <p>The controller is just as subclass of Ember.ArrayController with a load method :</p> <pre><code>App.MyController = Ember.ArrayController.extend { load: -&gt; console.log "loading data" } </code></pre> <p>The state manager has a view state which will instantiate App.MyView :</p> <pre><code>App.MyStateManager = Ember.StateManager.extend { initialeState: 'ready' ready: Ember.ViewState.extend { view: App.MyView } } </code></pre> <p>Now I need to run the following test :</p> <pre><code> controller = App.MyController.create {} manager = App.MyStateManager.create {} expect(manager.getPath('currentState.name').toEqual('ready') expect(controller.load).toHaveBeenCalled() streamView = manager.getPath('currentState.view.streamView.content') expect(streamView.content).toEqual(controller.content) </code></pre> <p>In order to make the last expectation to work, I need to bind the content of my streamView that is a child of App.MyView with the controller content. How can I do this cleanly ?</p> <p>Furthermore, how to pass a reference to the state manager to the view and the controller in order to notify the manager when some event occur so it need to transit to another state. For example a click on an item or controller did finish a job ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload