myartsev
myartsev

Reputation: 1232

Ember add-ons: what is the recommended way to handle input data?

When writing a (public) ember add-on; what is the recommended format for input data coming from the main ember app? Do you expect ember-data objects, or a simpler data model such as an array for example?

If the add-on accepts ember data objects; any modifications to this data can be persisted to the backend easily, but I'm certain that not everyone uses ember-data. If you don't use ember-data, converting a data model into ember-data's formats is madness.

On the other hand, if the add-on accepts an array (for example) as the input data, then the main ember app using ember-data has to extract the data into this array format for the add-on to use.

I haven't seen any guidance in the Ember docs or elsewhere in the web that I could find.

Upvotes: 0

Views: 43

Answers (2)

Lux
Lux

Reputation: 18240

I think the best Idea is to always use Ember.get('prop') in favor of obj.get('prop') or obj.prop. This notation will work for both, ember objects with CPs, including ember-data objects, and plain JS objects.

The beauty about ember objects and ember arrays is that they are normal JS objects/arrays, just with a bit extra.

Hoever I wouldn't rely on a object being an ember object, but if you use Ember.get in favor of obj.get your code will always work.

Upvotes: 1

Daniel
Daniel

Reputation: 18680

If your addon is mainly providing components - then you could stick to KISS convention and keep your components as stupid as possible. For example - instead of passing whole model to component it's better to pass single property etc.

See KISS principle.

Smart and Dumb components article from React, but Ember also relies on components.

Upvotes: 0

Related Questions