ember.jsember.js-view

Code replication in creating reusable view/component in ember.js


I have to create a feed reader which can be used in multiple places in an ember app.

I decided to use either a 'view' or a 'component' in this case. one concern is in both the cases i have to keep the data out side of 'view' or 'component'. i have to trigger the controller to request the latest data, controller updates the data stored in model. problem with this approach is fetch and updating the model code should be replicated in all the place where feed reader is used. Is there any way to solve this issue?


Solution

  • If the code can be made generic, create a mixin and then you can add that mixin to the controller.

    http://emberjs.com/api/classes/Ember.Mixin.html