I’d like to discuss the ideal design pattern/delegation of responsibilities when it comes to creating and persisting a new Ember Data model.
Specifically, what are the duties of the Route vs the duties of the Component when it comes to creating and persisting a new model.
Scenario: Im building a Shopping List app which allows you to view your shopping list and append items to the list.
I have a single Model called a
ShoppingListItem
- name # string
- quantity # int
and the following parts
ShoppingListRoute
ShoppingListTemplate
ShoppingListItemComponent
CreateShoppingListItemComponent
What I am not sure about is
- Should the
CreateShoppingListItemComponent
ever need to know about the Ember Data Store - Should Ember Data Models only be created by Routes?
- Should Ember Data Models only be persisted/saved by Routes?
- Should the
CreateShoppingListItemComponent
bubble up a newShoppingListItem
to the route action where it is saved? - Or should the
CreateShoppingListItemComponent
bubble up a plain old javascript dictionary of values up to a route action where it is converted into a newShoppingListItem
to be saved?
Is there an official stance here? I feel like I could achieve this in several ways but am sure there is a best practice.
Many thanks! Oli