Skip to content

Instantly share code, notes, and snippets.

View unscriptable's full-sized avatar
🏔️

John Hann unscriptable

🏔️
View GitHub Profile
@unscriptable
unscriptable / issue53.html
Created January 28, 2012 17:14
reproduce curl.js issue 53
<!DOCTYPE HTML>
<html>
<head>
<title>issue 53</title>
<script src="../src/curl.js" type="text/javascript"></script>
<script type="text/javascript">
curl({
@unscriptable
unscriptable / HttpError.js
Created January 5, 2012 15:39
Example "subclass" of Error object
// AMD module wrapper.
define(function () {
function HttpError (msg, code) {
var ex;
msg = msg || 'Unknown HTTP error';
ex = new Error(msg); // not all browsers let us inherit, so we do it this way
ex.code = code;
ex.name = 'HttpError'; // thx @cjno! (http://twitter.com/cjno/status/154959746582056960)
@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' },
@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 / 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 / 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 / AMD-css-support.md
Created November 16, 2011 15:59
AMD css support
@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 / 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 / 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'
},