@alidcastano wrote:
Ember, from what I've read, is moving away from controllers in favor of components. But the documentation from what I could find doesn't really describe how to perform similar functionality without a controller. What would be the correct way to do this?
As an example: I'm making a notetaking app. I need to create a new notebook (or note) before the logic can be handled by a component.
So if I were using a controller to create the notebook, this code works:
export default Ember.Route.extend({ model: function() { return Ember.RSVP.hash({ .... notebooks: this.store.findAll('notebook') }); } }); export default Ember.Controller.extend({ defaultNbName: Ember.computed('notebooks', function() { let notebooks = this.get('model.notebooks'); let defaultName = 'New Notebook'; let count = 0; // append id to notebook name based on existing default names notebooks.forEach(function(nb){ let name = nb.get('name').substring(0, defaultName.length); if (name === 'New Notebook') count++; }); return defaultName + ' ' + count; }), defaultNb: Ember.computed('defaultNbName', function() { let nbName = this.get('defaultNbName'); return { name: nbName, createdAt: new Date(), notes: [] } }), actions: { createNotebook() { let nb = this.get('defaultNb'); let newNb = this.get('store').createRecord('notebook', nb); newNb.save().then(() => { this.transitionToRoute('notebook', newNb.id); }); } } });
But without a controller I'm unsure of how to proceed. Using the example, what would be the correct way to create a notebook for the corresponding component to use?
Posts: 2
Participants: 2