Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining custom Ember.Object in Ember-CLI

Question Revised: 04/30/2015

I would like to define a new Ember.Object.extend() somewhere in my Ember CLI project, so that I can make new object instances from it using a line like myObject.create()

Is it correct to store these in a directory like app/custom-objects? and then i can do something like import myObject from './custom-objects/my-object'

Is an initializer required to register the object into ember, before I can import it?

Is my assumption here correct?

like image 946
Grapho Avatar asked Jun 25 '14 20:06

Grapho


1 Answers

Initializer is not required.

You could define myObject:

//app/custom-objects/my-object.js
import Ember from 'ember';

export default Ember.Object.extend({
   name: 'DefaultName'
});

and then you could import it anywhere:

//app/pods/parent/children/controller.js
import Ember from 'ember';
import MyObject from '../../../custom-objects/my-object'

export default Ember.Controller.extend({
  //...
  myObj: MyObject.create({name: 'SuperName'}),
});

//app/pods/parent/children/template.hbs
name: {{myObj.name}} {{!--  => SuperName --}}
like image 99
artych Avatar answered Oct 07 '22 17:10

artych