Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@michael-brade
michael-brade / components.js
Created September 25, 2016 21:11
fixed extendComponent()
function extendComponent(constructor) {
// Don't do anything if the constructor already extends Component
if (constructor.prototype instanceof Component)
return;
// Otherwise, add an instance of Component to its prototype chain
var c = constructor.prototype;
for (var p = Object.getPrototypeOf(c); p !== Object.prototype && p !== Function.prototype; p = Object.getPrototypeOf(c)) {
c = p;
}
@michael-brade
michael-brade / 1-controller-slow.ls
Last active October 9, 2015 23:26
DerbyJS: lesson about not using controller functions to get model data
# a simple function, but this will make real-time updates impossible
# it also causes DerbyJS to create new components with every keystroke
# get all subitems in item.attr -- and dereference them if needed
subitems: (item, attr) ->
data = item[attr.id]
return [] if not data
if not attr.multi
data = [data]