Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View ghempton's full-sized avatar

Gordon L. Hempton ghempton

View GitHub Profile
### Keybase proof
I hereby claim:
* I am ghempton on github.
* I am gordon (https://keybase.io/gordon) on keybase.
* I have a public key whose fingerprint is D4FB AED6 9E30 D434 AC3D 17E3 E406 8EA9 1729 1FD0
To claim this, I am signing this object:
// dynamically creating classes + computed properties
// result of ajax request, these are the fields and their dependencies
var fields = {'name': {'firstName', 'lastName'}};
var mixin = {};
for(var name in fields) {
@ghempton
ghempton / gist:4481055
Created January 8, 2013 04:04
Bug in new router. This test belongs in basic_test.js
test("Grandparent route context change", function() {
expect(0);
Ember.TEMPLATES.application = compile("{{outlet}}");
Ember.TEMPLATES.posts = compile("{{outlet}}");
Ember.TEMPLATES.post = compile("{{outlet}}");
Ember.TEMPLATES.show = compile("showing");
Ember.TEMPLATES.edit = compile("editing");
Router.map(function(match) {
match("/").to('index');
@ghempton
ghempton / ember-analytics.js
Created October 3, 2012 16:00
Drop in addition of analytics to Ember.js applications
Ember.Route.reopen({
enter: function(router) {
this._super(router);
if(this.get('isLeafRoute')) {
var path = this.absoluteRoute(router);
mixpanel.track('page viewed', {'page name' : document.title, 'url' : path});
_gaq.push(['_trackPageview', path]);
}
}
});
@ghempton
ghempton / async-routing-example.md
Created July 20, 2012 17:43
Async Routing Example

Example of the Need for Async Routing

App.Profile = DS.Model.extend({

});

App.User = DS.Model.extend({
  profile: DS.belongsTo(App.Profile)
@ghempton
ghempton / ember-controllers.md
Created July 18, 2012 21:16
Ember.js Controller Brainstorm

Ember.js Controller Brainstorm

Currently, there are several awkward points to Ember.js controllers. Namely:

  1. Passing controllers around to view's not instantiated by the routing system is hard.
  2. Non-singleton controllers are very difficult to manage (e.g. #each where each view has it's own controller).
  3. Sharing data between controllers is difficult.

Solution for 1 and 2: Controllers are lazily created by views

@ghempton
ghempton / safeClone.jquery.js.coffee
Created March 11, 2012 21:36
Small jQuery extension to clone elements without Ember/Metamorph metadata
# Small extension to create a clone of the element without
# metamorph binding tags and ember metadata
$.fn.extend
safeClone: ->
clone = $(@).clone()
# remove content bindings
clone.find('script[id^=metamorph]').remove()
@ghempton
ghempton / bound_helper.js
Created March 11, 2012 20:55
Ember Bound Handlebars Helper Utility
// This file contains utilities for creating bound helpers
// For reference: https://github.com/wagenet/ember.js/blob/ac66dcb8a1cbe91d736074441f853e0da474ee6e/packages/ember-handlebars/lib/views/bound_property_view.js
Ember.Handlebars.BoundHelperView = Ember.View.extend(Ember._Metamorph, {
context: null,
options: null,
property: null,
// paths of the property that are also observed
propertyPaths: [],
@ghempton
ghempton / react-link.js
Created November 26, 2014 17:54
React Link Helper
/**
Attempting to create a subclass of `Model` that supports
CP's and Ember.Observable.
*/
function EmberModel() {
Model.apply(this, arguments);
return CoreObject.apply(this);
}
var PrototypeMixin = Model.prototype;