Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add readme

  • Loading branch information...
commit 3ad96c8125f4b28565890c2efe8184578258d224 1 parent e5468dd
@dominictarr authored
View
5 mad.js → amd.js
@@ -1,13 +1,12 @@
/*
- adds support for using ADM style moduels in node.
-
+ adds support for using AMD (CommonJS2.0) style modules in node.
*/
module.constructor.prototype.define = function (depends,initializer){
var self = this
var _id = module.filename
module.filename = self.filename
- this.exports = initializer.apply(this.exports,depends.map(require)) || this.exports
+ this.exports = initializer.apply(global,depends.map(require))
module.filename = _id
}
View
4 bundle.js
@@ -1,4 +1,4 @@
-require('mad')
+require('amd')
module.define(['fs','vm'],function (fs,vm){
var _fn = module.filename
@@ -7,7 +7,7 @@ module.define(['fs','vm'],function (fs,vm){
var _fn = module.filename
, path = [].shift.call(arguments)
, done = [].pop.call(arguments)
- , minify = [].pop.call(arguments)
+ , minify = ![].pop.call(arguments)
, filename = resolve(path), refs = {}, rCount = 1, funx = [], modules = {}
function resolve (req,filename){
View
3  examples/a.js
@@ -0,0 +1,3 @@
+module.define([],function A (){
+ return function (x){'!' + x + '!'}
+})
View
4 examples/ab.js
@@ -0,0 +1,4 @@
+
+module.define(['./a', './b'], function AB (a,b){
+ return function (x){return a(b(x))} //exports is returned.
+})
View
3  examples/b.js
@@ -0,0 +1,3 @@
+module.define([],function B (){
+ return function (x){'?' + x + '?'}
+})
View
56 readme.markdown
@@ -1 +1,57 @@
#a superlightweight module loader for node and the browser.
+
+The objective of AMD is to create a the simplest possible
+node/browser module loader. Instead of trying to do something
+clever and force node modules into the browser, instead it's
+better to change our problem behaviour to make the hard problem into a easy one.
+
+AMD forces you to declare all your dependencies up front,
+and not require anything new after that point.
+
+It's not unreasonable, but suddenly loading modules is easy.
+
+##AMD modules:
+
+ * work in browser and node
+ * can be required by normal node modules, with no funny business.
+ * does not add any overhead to the modules - unlike other node-browser-module systems!
+
+###the old way:
+
+ //ab.js
+ var a = require('./a')
+ , b = require('./b')
+
+ exports.ab = function (x){return a(b(x))}
+
+###the NEW way:
+
+ //ab.js - amd style
+ require('amd')
+ module.define(['./a', './b'], function AB (a,b){
+
+ return function (x){return a(b(x))} //exports is returned.
+ })
+
+then do `$ amd ab.js`:
+
+amd will load the modules, get thier dependencies, topologicially sort them,
+and stringify them, pluging dependencies into the correct places!
+with very little overhead!
+
+ (function (M){
+ M[1] =
+ (function A(){
+ return function (x){'!' + x + '!'}
+ })();
+
+ M[2] =
+ (function B(){
+ return function (x){'?' + x + '?'}
+ })();
+
+ return (function AB(a,b){
+ return function (x){return a(b(x))} //exports is returned.
+ })(M[1],M[2]);
+
+ })({});
View
2  test/bundle.asynct.js
@@ -1,5 +1,5 @@
require('amd')
-var bundle = require('mad/bundle')
+var bundle = require('amd/bundle')
exports ['test'] = function (test){
Please sign in to comment.
Something went wrong with that request. Please try again.