Last active
February 21, 2017 12:13
-
-
Save tobiasWenger/5ed7c167f51d1532dcc08ddf0b271771 to your computer and use it in GitHub Desktop.
computed.sort vs. sortBy
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'; | |
| import Performance from '../performance'; | |
| export default Ember.Component.extend(Performance, { | |
| dataSorting: ['string'], | |
| dataSorted: Ember.computed.sort('data', 'dataSorting') | |
| }); |
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'; | |
| import Performance from '../performance'; | |
| export default Ember.Component.extend(Performance, { | |
| dataSorted: Ember.computed('data', function() { | |
| return this.get('data').sortBy('string'); | |
| }) | |
| }); |
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.Controller.extend({ | |
| appName: 'Ember Twiddle', | |
| data1: Ember.computed(function() { | |
| // create array with id and random string | |
| let data = []; | |
| for (let i = 0; i < 2000; i++) { | |
| const randomString = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5); | |
| data.push({id: i, string: randomString}); | |
| } | |
| return data; | |
| }), | |
| data2: Ember.computed(function() { | |
| // create array with id and random string | |
| let data = []; | |
| for (let i = 0; i < 2000; i++) { | |
| const randomString = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5); | |
| data.push({id: i, string: randomString}); | |
| } | |
| return data; | |
| }) | |
| }); |
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.Mixin.create({ | |
| tStart: 0, | |
| tEnd: 0, | |
| deltaT: Ember.computed('tStart', 'tEnd', function() { | |
| const { tStart, tEnd } = this.getProperties('tStart', 'tEnd'); | |
| return Math.round((tEnd - tStart)*100)/100; | |
| }), | |
| init() { | |
| this.set('tStart', performance.now()); | |
| this._super(...arguments); | |
| }, | |
| didInsertElement() { | |
| this._super(...arguments); | |
| this.set('tEnd', performance.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
| { | |
| "version": "0.11.0", | |
| "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.10.2", | |
| "ember-data": "2.11.0", | |
| "ember-template-compiler": "2.10.2", | |
| "ember-testing": "2.10.2" | |
| }, | |
| "addons": {} | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment