Skip to content

Instantly share code, notes, and snippets.

View unscriptable's full-sized avatar
🏔️

John Hann unscriptable

🏔️
View GitHub Profile
@unscriptable
unscriptable / dojoParse
Created May 16, 2011 19:56
aop-ish way to detect when dojo.parser.parse is called
define(['dojo/parser, wire/Deferred'], function (parser, Promise) {
var orig = parser.parse,
promise = new Promise();
parser.parse = function (node) {
orig.apply(parser, arguments);
promise.resolve();
};
return promise;
@unscriptable
unscriptable / AMD module list.md
Created May 26, 2011 15:25
List of AMD-compliant modules in the wild

A List of actively-supported, reusable, open-source, AMD-compliant modules in the wild. Let me know if you have another module to add to the list!

querySelectorAll (css3-based dom selector engine)

Promises / Deferreds

@unscriptable
unscriptable / first-syntax.js
Created May 30, 2011 03:00
Possible syntaxes for wire.js deferrals
wire({
// this is a normal module
// it is loaded, created, and initialized asap
staticModule: {
create: {
module: 'my/static/module',
args: {}
},
init: 'startMe'
},
@unscriptable
unscriptable / curl_config.js
Created October 18, 2011 21:29
example config to map an XHR implementation to a mock impl
global.curl = {
baseUrl: baseUrl,
paths: {
'li/ubox': '../../../../../applications/universal-inbox/src/main/webapp/li/ubox',
'li/schema': '../../../../../applications/universal-inbox/src/main/webapp/li/schema',
'li/referenceData': '../../../../../applications/universal-inbox/src/main/webapp/li/referenceData',
'data': '../../test/webapp/data',
/* this is the interesting line: */
'li/core/xhr': '../../test/webapp/mock/li/core/xhr-promise'
@unscriptable
unscriptable / bp1.js
Created November 9, 2011 03:04
boilerplate for CommonJS, AMD, plain old global hackfest
(function (myLib, define) {
//Set up myLib here.
myLib.add = function (a, b) { return a + b; };
define(myLib);
}.call(this,
typeof exports == 'object' ? exports : {},
typeof define == 'function' && define.amd ?
define :
@unscriptable
unscriptable / AMD-css-support.md
Created November 16, 2011 15:59
AMD css support
@unscriptable
unscriptable / ZZZ_MyView.js
Created November 23, 2011 11:05
cujo-ish view/widget
// MyView.js when concatenated together using cram.js
// cram.js needs two new features to make this work:
// 1. an option to NOT normalize module ids
// 2. an option to more easily exclude modules from the build (wire plugins, for instance)
define('./myView/controller', {
_onClick: function (e) {
this.rootNode.classList.toggle(this.states.selected);
}
});
@unscriptable
unscriptable / boilerplateAfter.js
Created November 26, 2011 14:55
AMD/Node module with dependencies
(function (define) {
define(['pkgA/modA', 'pkgB/mod2'], function (modA, mod2) {
// define and return module here
function myCtor () {}
myCtor.prototype = {
combine: function () { return modA.aMethod() + mod2.anotherMethod();
};
return myCtor;
@unscriptable
unscriptable / shim.js
Created December 6, 2011 12:58
Closure compiler is too smart for ES5 shims
// google closure compiler turns this:
function indexOf (item /*, fromIndex */) {
return find(this, item, arguments[1] /* fromIndex */, true);
}
// into this (notice the new function argument):
function q(a,c){b(this,a,c,!0)}
/*
Q: Why is this bad?
@unscriptable
unscriptable / cfg.js
Created December 9, 2011 02:43
possible syntax for curl.js package mappings
{
packages: {
pkgA: {
path: 'path/to/pkgA',
main: 'main/main-module-file',
lib: 'location/of/other/modules',
config: {
packages: {
// pkgC1.0 is declared at the top level
pkgC: { $ref: 'packages/pkgC1.0' },