Skip to content

Instantly share code, notes, and snippets.

View unscriptable's full-sized avatar
🏔️

John Hann unscriptable

🏔️
View GitHub Profile
@unscriptable
unscriptable / _fast-curl-boot.md
Created November 29, 2012 04:52
fast ways to boot apps with curl

There are a couple of things that bug me about RequireJS's data-main method of single-script loading:

<script src="js/requirejs/require.js" data-main="app/main.js"></script>
  1. the built file (bundle) must be named "require.js". WAT.
  2. it just seems backwards.
  3. data-main does not follow w3c recommendations since it's not name-spaced.
@unscriptable
unscriptable / AMD-factory-with-require.js
Created November 20, 2012 15:11
Simple AMD/node boilerplate. These aren't quite "normal" AMD and aren't "pure" CJS, but work in AMD loaders and node-like environments (like RingoJS).
// Typical AMD factory that returns a value, but uses an r-value (sync) require(),
// rather than a long, awkward dependency list.
// You cannot use module.exports or exports to declare the module:
(function (define){
define(function (require) {
"use strict";
var mod = require('pkb/modA');
return {
@unscriptable
unscriptable / README.md
Created November 16, 2012 14:30
curl.js (0.7.2) + backbone (0.9.2)

Here's one way to use curl.js with backbone

@unscriptable
unscriptable / umd.js
Created September 13, 2012 14:02
cjs umd
(function (define) {
define(function (require, exports, module) {
return 'foo';
});
}(
typeof define == 'function' && define.amd
? define
: function (factory) { factory(require, exports, module); }
@unscriptable
unscriptable / module-id.js
Created July 17, 2012 20:26
how to local-require
define(function (require, exports, module) {
return {
component: { module: './something' },
$module: module // has absolute id of spec (as well as other future goodies)
};
});
@unscriptable
unscriptable / _spec.js
Created April 5, 2012 02:43
wire plugin to create functions without violating JSON
define({
myFunc: {
expr: {
body: 'alert(e.target.textContent);',
params: ['e']
}
},
body: {
@unscriptable
unscriptable / DisableItemWhileUnresolved.js
Created March 21, 2012 01:21
event hub with strategies
define(function () {
var undef;
/**
* This strategy will disable a data item during REST operations.
* This strategy only makes sense in a pessimistic network.
* We need to integrate promises into the EventHub in order for this
* strategy to work. Alternatively, we could have item states of
* 'adding', 'removing', 'updating', but that feels brutish.
*/
// this is a test module
define(['curl/tdd/createContext', 'require'], function (createContext, require) {
// supply a require (optional) if your module ids are relative
var context = createContext(require);
context.setup(function (require, define /*, complete*/) {
// define all of your mocks and stubs
define('mock1', function () {});
@unscriptable
unscriptable / cola.transform.expression.js
Created March 3, 2012 19:51
wire and/or cola function to allow an arbitrary expression to be evaluated
/** MIT License (c) copyright B Cavalier & J Hann */
(function (define, globalEval) {
define(function () {
"use strict";
/**
* Creates a function that can be used to evaluate arbitrary expressions
* on a data item.
* @param options {Object}
@unscriptable
unscriptable / MethodSpy.js
Created February 28, 2012 22:16
spy on a method
function MethodSpy (method, context) {
var count, orig, spy;
count = 0;
orig = context[method];
context[method] = function () {
count++;
return orig.apply(context, arguments);
};