Created
October 25, 2013 09:03
-
-
Save mlippens/7151796 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#foo.coffee | |
root = exports ? this | |
define = root.app.define._define | |
define 'foo',['contracts-js'],(C)-> | |
exports = | |
hello: (x)-> x*x | |
foo: (x)-> x*x*x | |
exports.hello.__contract__ = C.fun(C.Num,C.Num) | |
exports.foo.__contract__ = C.fun(C.Num,C.Num) | |
exports | |
#bar.coffee | |
root = exports ? this | |
define = root.app.define._define | |
define 'bar',['foo'],(foo)-> | |
lol = ()-> "foo" | |
console.log foo.hello(3) | |
console.log foo.hello("foo") | |
#define.coffee | |
root = exports ? this | |
root.app = root.app || {} | |
define = ()-> | |
__namespace__ = root.app | |
C = root['contracts-js'] | |
_guard = (dep,server,client)-> | |
guarded = {} | |
for prop of dep | |
if dep.hasOwnProperty(prop) && dep[prop].hasOwnProperty('__contract__') | |
do (contract = dep[prop]['__contract__']) -> | |
delete dep[prop].__contract__ | |
guarded[prop] = C.guard(contract, dep[prop], server, client) | |
guarded | |
_define: (name, deps, callback)-> | |
guarded = [] | |
for dep in deps | |
if dep == 'contracts-js' | |
guarded.push(root['contracts-js']) | |
else | |
dependencyObject = __namespace__[dep] | |
guarded.push(_guard(dependencyObject,dep,name)) | |
__namespace__[name] = callback.apply(null, guarded) | |
root.app.define = define() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment