Skip to content

Instantly share code, notes, and snippets.

var Deferred = require('shared/deferred').Deferred;
var Repository = require('shared/repository').Repository;
...
var matchersForFilter = function(properties) {
var attributes = util.keys(properties);
var attributesFilters = util.values(properties);
var arraysWithAttributeAndAttributesFilters = util.zip(attributes,
attributesFilters);
var arrayOfMatchersForAttribute =
util.map(arraysWithAttributeAndAttributesFilters, matchersForAttribute);
var matchers = util.flatten(arrayOfMatchersForAttribute, true);
@gmoeck
gmoeck / example.js
Created June 12, 2012 16:29
Extremely Late binding
/* Imagine that you have a publish/subscribe system where you want a publisher to publish messages to a set of subscribers. There are two ways that you can specify the message to send, with a function to call on the object, and with a string.*/
//Functional subscription (Essentially a partially applied function)
publisher.addListener('someEvent', subscriber.someResult, subscriber);
//This ends up having code that looks something like this:
addListener: function(eventName, functionToCall, subscriber) {
this._events[eventName].push({functionToCall: functionToCall, context: subscriber});
},
...
invoke: function(eventName, data) {
class SomeController < ApplicationController
...
def update
ui = SomeViewAdapter.new
domain = SomeDomain.new(ui)
translator = SomeRailsAdapter.new(domain)
translator.some_action(params)
#some processing based upon ui values in order to know what view to render, etc
end
class CommentsController < ApplicationController
def create
translator.translate params
end
private
def translator
CommentRequestTranslator.new(processor)
class SomeService
def initialize(some_dependency)
@some_dependency = some_dependency
end
def some_event(value)
@some_dependency.another_event(value.increase_value)
end
end