Skip to content

Instantly share code, notes, and snippets.

View ghempton's full-sized avatar

Gordon L. Hempton ghempton

View GitHub Profile
@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 / 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 / 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 / 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-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 / 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');
// 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 / route.em
Created March 5, 2014 02:57
Example of using EPF child sessions at the route level
`import CurrentUserMixin from 'outreach/core/current_user_mixin'`
class Route extends Em.Route with CurrentUserMixin
beforeModel: (transition) ->
parentRoute = if transition.state.handlerInfos.length > 1
transition.state.handlerInfos[transition.state.handlerInfos.length - 2].handler
else
null
@setupSession(parentRoute)
@ghempton
ghempton / gist:9882197
Created March 30, 2014 23:58
EPF Adapter URL API
Adapter.map(function() {
this.resources('post', {path: '/blog-posts/:post_id'}, function() {
this.resources('comments'); // assumes has-many called 'comments' and inverse called 'post'
this.resource('owner', {type: 'user'});
});
});
@ghempton
ghempton / gist:11389007
Created April 29, 2014 01:55
Epf Route
`import CurrentUserMixin from 'outreach/core/current_user_mixin'`
`import Model from 'outreach/core/model'`
class Route extends Em.Route with CurrentUserMixin
+computed
title: ->
'Outreach'
enter: ->