Skip to content

Instantly share code, notes, and snippets.

@designeng
designeng / onBuildWrite.coffee
Created September 24, 2014 14:01
requirejs hook for additiional file processing
onBuildWrite: (moduleName, path, contents) ->
if path.match "/bower_components/"
pathFragments = path.split "/"
index = 0
libName = undefined
for fragment in pathFragments
if fragment is "bower_components"
libName = pathFragments[index + 1]
console.log "libName::::", libName
@designeng
designeng / Express-sockjs-server.js
Created July 17, 2014 19:23
Express-sockjs-server.js
var express = require('express');
var sockjs = require('sockjs');
var http = require('http');
// 1. Echo sockjs server
var sockjs_opts = {sockjs_url: "http://cdn.sockjs.org/sockjs-0.3.min.js"};
var connections = []
var sockjs_echo = sockjs.createServer(sockjs_opts);
define ->
class OrderInfoController
getSource: ->
source =
id: "1"
location: "Rome"
return source
# updating collection
@listCollection.forEach (item) =>
item.port = item.port + "__"
@listCollection.update item
define ->
class AutoCompleteController
# @injected
input: undefined
# @injected
listCollection: undefined
curId: 0
define [
"underscore"
"when"
], (_, When) ->
return (options) ->
extend = (componentDefinition, wire) ->
When.promise (resolve) ->
define ->
findNested = (obj, key, memo) ->
i = undefined
memo = [] if Object::toString.call(memo) isnt "[object Array]"
for i of obj
if Object::hasOwnProperty.call(obj, i)
if i is key
memo.push obj[i]
else findNested obj[i], key, memo if Object::toString.call(obj[i]) is "[object Object]"
memo
processRouteMap = (routes) ->
requirejs.config
nodeRequire: require
paths:
"routeMap" : __dirname + "/../../../app/js/" + "routeMap"
"requireConfig" : __dirname + "/../../../app/js/" + "requireConfig.js"
"text" : __dirname + "/../../../app/js/vendors/requirejs-text/text"
requirejs ["routeMap", "text!requireConfig"], (routeMap, requireConfig) ->
console.log "requireConfig", requireConfig
@designeng
designeng / Controller_and_declaration.coffee
Created November 6, 2013 14:28
Loading and resolving controller and component declaration with when.js "all" method
# blank method
callback = (resultClass) ->
# loading controllers directly instead of modules
require ["modules/" + name + "/" + name + "Controller", "modules/" + name + "/declaration"], (ControllerClass, declaration) =>
types = findNested(declaration.componentItems, "itemType")
console.log types
promises = []
@designeng
designeng / callbacks.coffee
Created October 10, 2013 13:56
cujo.js when, callbacks usage
sumInForeSeconds = (a, b, callback) ->
console.log "sumInFiveSeconds"
setTimeout(()=>
callback(a + b)
, 4000)
sumInFiveSeconds = (a, b, callback) ->
console.log "sumInFiveSeconds"
setTimeout(()=>
callback(a + b)