Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4830

You probably don't need to wrap in Ember.Object

$
0
0

@ef4 wrote:

I have seen several posts lately where people share code that does things like:

this.set(‘recipientList’, Ember.Object.create(response)).

And rather than hijack those threads, I’m starting a new one to point out: you almost certainly don’t need that Ember.Object.create.

Ember works fine with Plain Old Javascript Objects (POJOs). If you already have a POJO, you can just use the POJO.

The only rule you need to follow to make sure Ember can keep track of your data changing is that you use set to change it. For example, this template:

The value is {{pojo.outside.inside.value}}

Will always render fine and stay up to date even if you implement the component like this:

import { set } from '@ember/object';
import Component from '@ember/component';
export default Component.extend({
  init() {
    this._super();
    this.set('pojo', { outside: { inside: { value: 'a' } } });
  },
  actions: {
     changeIt() {
        set(this.pojo.outside.inside, 'value', 'b');
     }
  }
});

When should you wrap in Ember.Object? Only when you actually want to extend Ember.Object to use a feature like computed properties. If you aren’t extending and you’re just calling Ember.Object.create(...), you almost certainly don’t need to.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4830

Trending Articles