Skip to content

Instantly share code, notes, and snippets.

@3gwebtrain
Last active July 12, 2017 10:07
Show Gist options
  • Save 3gwebtrain/84bcfef66b20808e612844c49ede5cbe to your computer and use it in GitHub Desktop.
Save 3gwebtrain/84bcfef66b20808e612844c49ede5cbe to your computer and use it in GitHub Desktop.
Ember Class Extends
import Ember from 'ember';
import myObject from "../myObject";
myObject();
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from "ember";
export default function() {
const Light = Ember.Object.extend({
init() {
console.log("from init " + this.get("isOn"));
},
isOn: false,
age: null,
description: Ember.computed("isOn", "color", function() {
return "This " + this.get("isOn") + " light is set to " + this.get("color");
}),
fullDescription: Ember.computed('description', 'age', function() {
return this.get('description') + ' and the age is ' + this.get('age')
}),
aliasDescription: Ember.computed.alias('fullDescription'),
isOnChanged: Ember.observer('isOn', function() {
console.log('isOn value changed')
})
});
Light.reopen({
color: "yellow"
});
Light.reopenClass({
wattage: 80
});
const bulb = Light.create({
age: 22
});
bulb.set("isOn", true);
console.log(bulb.get('isOn'), bulb.get("color"));
console.log(bulb.get("aliasDescription"));
const common = Ember.Mixin.create({
property1: 'This is a mixin property',
edit: function() {
console.log('Starting to edit');
this.set('isEditing', true);
},
isEditing: false
});
const secondMixin = Ember.Mixin.create({
secondProperty: 'This is the second mixin property'
});
const obj = Ember.Object.extend(common,secondMixin, {
objprop: 'This is an Ember object property'
});
const object = obj.create();
//each iterator
const students = ['Erik', 'Jim', 'Shelly', 'Kate'];
const upperCaseStudent= students.map(function(item) {
return item.toUpperCase();
});
upperCaseStudent.forEach(function(item, index) {
console.log(`Student #${index+1}: ${item}`);
});
}
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment