Some thoughts and ideas on best practices building Ember apps after 2 years building and maintaining 6+ apps. This is less about the obvious best practices, like use ember-cli, and more along the lines of when to use what technique. As with every best practice there are exceptions to every rule.
This file contains 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
machine: | |
node: | |
version: 0.12.0 | |
dependencies: | |
pre: | |
- export PATH=/usr/local/phantomjs-2.0.0/bin:$PATH | |
- npm config set spin false | |
- npm install -g npm@^2 | |
- npm install -g bower |
This file contains 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
// Array literal (= []) is faster than Array constructor (new Array()) | |
// http://jsperf.com/new-array-vs-literal/15 | |
var array = []; | |
// Object literal (={}) is faster than Object constructor (new Object()) | |
// http://jsperf.com/new-array-vs-literal/26 | |
var obj = {}; | |
// property === undefined is faster than hasOwnProperty(property) | |
// http://jsperf.com/hasownproperty-vs-in-vs-undefined/17 |
This file contains 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
// http://stevenbenner.com/2010/03/javascript-regex-trick-parse-a-query-string-into-an-object/ | |
// JavaScript regex trick: Parse a query string into an object | |
var queryString = {}; | |
anchor.href.replace( | |
new RegExp("([^?=&]+)(=([^&]*))?", "g"), | |
function($0, $1, $2, $3) { queryString[$1] = $3; } | |
); | |
// Usage |
This file contains 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', | |
vehicle: '', | |
vehicles: [1,2,3], | |
}); |
This file contains 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
App.StorageService = Ember.Object.extend({ | |
persistence: window.localStorage, | |
namespace: 'ember-storage-service', | |
init: function() { | |
var callback = this._handleStorageEvent.bind(this); | |
$(window).on('storage', callback); | |
}, | |
The Ember router is getting number of enhancements that will greatly enhance its power, reliability, predictability, and ability to handle asynchronous loading logic (so many abilities), particularly when used in conjunction with promises, though the API is friendly enough that a deep understanding of promises is not required for the simpler use cases.
- see https://gist.github.com/machty/5723945 for the latest API (unlikely to change from now on)
- latest Ember build: https://machty.s3.amazonaws.com/ember/ember-async-routing-10.js
This file contains 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
git branch -m old_branch new_branch # Rename branch locally | |
git push origin :old_branch # Delete the old branch | |
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote |
-
Other
- http://emberjs.jsbin.com/rwjblue/251/edit?html,js,output - Opening a window and communicate with it.
- http://emberjs.jsbin.com/rwjblue/55/edit - Using liquid-fire animations in globals mode.
- http://emberjs.jsbin.com/rwjblue/151/edit?js,output - Modify computed dependent keys after initialization.
- http://emberjs.jsbin.com/rwjblue/299/edit?js,output - simplified version of ic-ajax
- http://emberjs.jsbin.com/rwjblue/337/edit?html,js,output - Detect if Mixin was mixed into a Class
-
POJO's
- http://emberjs.jsbin.com/rwjblue/253/edit?js,output - Defining computed properties on a POJO.
NewerOlder