Last active
June 29, 2017 17:41
-
-
Save buschtoens/9cac388ebb81e6b5deba605555424518 to your computer and use it in GitHub Desktop.
Array Rendering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
didInsertElement() { | |
this._super(...arguments); | |
this.set('timestamp', Date.now()); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
function randomIntFromInterval(min, max) { | |
return Math.floor(Math.random() * (max - min + 1) + min); | |
} | |
export default Ember.Controller.extend({ | |
list: [], | |
firstTen: Ember.computed('list.[]', function() { | |
return this.get('list').slice(0, 10); | |
}), | |
actions: { | |
pushElement() { | |
const list = this.get('list'); | |
const length = list.get('length'); | |
list.pushObject({ label: `Element #${length}` }); | |
}, | |
unshiftElement() { | |
const list = this.get('list'); | |
const length = list.get('length'); | |
list.unshiftObject({ label: `Element #${length}` }); | |
}, | |
insertRandomly() { | |
const list = this.get('list'); | |
const length = list.get('length'); | |
list.insertAt(randomIntFromInterval(0, length), { label: `Element #${length}` }); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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