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

Replace Object And Array Controllers With Ember.Controller and remove ItemControllers #379

Closed
teddyzeenny opened this issue Jun 3, 2015 · 13 comments
Labels

Comments

@teddyzeenny
Copy link
Contributor

Part of #360

Ember.ObjectController, Ember.ArrayController and itemController are going away. We need to replace them with Ember.Controller.

  • Create app/controllers/object.js that exports Ember.Controller. This will prevent Ember from automatically creating object controllers:
// app/controllers/object.js
import Ember from 'ember';
const { Controller } = Ember;
export default Controller;
  • Replace all Ember.ObjectController with Ember.Controller. This means that properties that access model properties will need to use model.propertyName instead of just propertyName since the Controller will no longer be a proxy.
  • Create app/controllers/array.js that exports Ember.Controller. This will prevent Ember from automatically creating array controllers:
// app/controllers/array.js
import Ember from 'ember';
const { Controller } = Ember;
export default Controller;
  • Replace all Ember.ArrayController with Ember.Controller. This means that all array methods/properties called on the controller will need to be called on the model instead. Example: this.forEach will need to be this.get('model').forEach, this.get('length') will need to be this.get('model.length'). sortProperties will also no longer work. We would need to create a computed property that sorts the model. {{#each}} and {{#each controller}} need to be replaced with {{#each model as |item|}}.
  • Replace itemController in {{#each}} helpers with components.
    Old Version:
{{!-- app/templates/people.hbs --}}
{{#each model itemController="person-item"}}
  {{if #canDrive}}
    Old enough to drive
  {{/if}}
{{/each}]
// app/controllers/person-item.js
export default Ember.ObjectController.extend({
  canDrive: computed.gte('age', 18);
});

New Version:

{{!-- app/templates/people.hbs --}}
{{#each model as |person|}}
  {{#person-item model=person as |personItem|}}
    {{#if personItem.canDrive}}
      Old enough to drive
    {{/if}}
  {{/person-item}}
{{/each}}
// app/components/person-item.js
import Ember from 'ember';
const { Component, computed: { gte } } = Ember;
export default Component.extend({
  canDrive: gte('model.age', 18)
});
// app/components/person-item.hbs
{{yield this}}
@rwjblue
Copy link
Member

rwjblue commented Jun 3, 2015

Might want to lump itemController in with this one...

@teddyzeenny teddyzeenny changed the title Replace Object And Array Controllers With Ember.Controller Replace Object And Array Controllers With Ember.Controller and remove ItemControllers Jun 3, 2015
@teddyzeenny
Copy link
Contributor Author

@rwjblue 👍 added item controller.

@camskene
Copy link

camskene commented Jun 4, 2015

I can work on this.

@camskene
Copy link

camskene commented Jun 5, 2015

@teddyzeenny should I branch off master or stable? I noticed both of those branches have ~60 failing tests.

@teddyzeenny
Copy link
Contributor Author

@camskene hey, sorry for the mess. Regenerator library made a breaking change incompatible with Babel runtime in a patch version which broke all the tests. Working on a fix.

To answer your question, all PRs go against master, so always branch off master.

@teddyzeenny
Copy link
Contributor Author

Should be fixed with #384.

Make sure to rm -rf node_modules && npm cache clean && npm install

@teddyzeenny
Copy link
Contributor Author

You won't be able to use block params ({{yield this}}) until we upgrade to Ember 1.11

@bjonord
Copy link

bjonord commented Jun 5, 2015

@camskene You working on this one?

Otherwise I can pick it up.

@camskene
Copy link

camskene commented Jun 5, 2015

@bjoska If you could pick it up that would be great! I was investigating last night and it's a bit beyond my ember foo...

@bjonord
Copy link

bjonord commented Jun 6, 2015

Got it!

Cheers!

On 6 jun 2015, at 01:53, Cam Skene notifications@github.com wrote:

@bjoska If you could pick it up that would be great! I was investigating last night and it's a bit beyond my ember foo...


Reply to this email directly or view it on GitHub.

@teddyzeenny
Copy link
Contributor Author

If anyone has any questions feel free to ping me (@teddy) on the Ember Community slack #ember-inspector channel. Automated invite at https://ember-community-slackin.herokuapp.com

@zzr994
Copy link

zzr994 commented Jun 1, 2016

Hi teddyzeenny,
We are using ember 1.9.1 and we want to move towards ember 2.0.0. As an intermediate step we are using ember 1.11.3 and get rid of all the depreciation warnings. One of the items that need to be refactored is the ArrayController and the ObjectController. We have managed to take care of the ArrayController. The only remaining issue is refactoring the ObjectController.

In the templates we have lot of code that looks like the following:
{{#each runningModules itemController="module" as |module|}}
{{module-tab class="inline-block" module=module tagName='div'}}
{{/each}}
The same ObjectController is used in multiple places allowing the properties defined on the ObjectController to be used multiple times. This provides an advantage of code re-use.

What do you think is the best way to refactor the code in the ObjectController so that it can be used multiple times?

@RobbieTheWagner
Copy link
Member

Closing this as these controller types have been removed already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants