ember.js - Where should view/template-specific data go? -
my main controller contains array of companies, lots of details.
i want provide several different views slice , summarize data. calculations required summarize data sufficiently complex need have place store them. should i
- add data manipulation methods each view object, or
- create new controller each view, , add data manipulation methods controller?
the getting started portion of docs adds number of remaining todos to controller, makes me think should create separate controllers each view.
as quick follow-up: if go #2, should create many controllers extend original companiescontroller, don't have reload data?
add data manipulation methods each view object
please don't! business logic better suited controllers.
or create new controller each view, , add data manipulation methods controller?
sort of, if calculations doing same each controller go mixin, this:
app.calculationbase = ember.mixin.create({ doheavycalculations: function() { ... return results; } ... }); and mix other controllers like:
app.mycontroller = ember.objectcontroller.extend(app.calculationbase, { // here can call this.doheavycalculations() }); app.myothercontroller = ember.arraycontroller.extend(app.calculationbase, { // here can call this.doheavycalculations() }); but depending on how setup looks like, create itemcontroller baked mixin or not.
for example, assuming in templates looping on companiescontroller content this:
{{#each company in model}} {{company}} {{/each}} then itemcontroller approach instantiate 1 separate companycontroller each company item.
app.companiescontroller = ember.arraycontroller.extend({ itemcontroller: 'company' }); app.companycontroller = ember.objectcontroller.extend({ doheavycalculations: function() { ... return results; } ... }); hope helps.
Comments
Post a Comment