Skip to content

Instantly share code, notes, and snippets.

View ghempton's full-sized avatar

Gordon L. Hempton ghempton

View GitHub Profile
@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: ->
@ghempton
ghempton / gist:11389065
Created April 29, 2014 02:00
Transactional Route
`import Route from 'outreach/core/route'`
# Route which manages a transaction on it's content.
# E.g. when the route is exited, the transaction will
# be rolled back
class TransactionalRoute extends Route
resolveSession: (parentSession) ->
@session = parentSession.newSession()
/**
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;
@ghempton
ghempton / react-link.js
Created November 26, 2014 17:54
React Link Helper
@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)