This file contains 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
// Simple, tiny, dumb module definitions for Browser JavaScript. | |
// | |
// What it does: | |
// | |
// * Tiny enough to include anywhere. Intended as a shim for delivering | |
// browser builds of your library to folks who don't want to use script loaders. | |
// * Exports modules to `__modules__`, a namespace on the global object. | |
// This is an improvement over typical browser code, which pollutes the | |
// global object. | |
// * Prettier and more robust than the |
This file contains 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
function uid() { | |
// Generate a unique and non-colliding id. | |
return Math.random().toString(36).slice(2); | |
} | |
// Create unique, non-colliding ID namespace. | |
var __id__ = uid(); | |
function idOf(thing) { | |
return (thing && typeof(thing) === ('object' || 'function')) ? |
This file contains 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
var STATE_FILTERS = [ | |
function clampIndex(state, old, update) { | |
return extend(state, { | |
// Validate and sanitize properties. | |
index: clamp(state.index, 0, state.units - 1) | |
}); | |
}, | |
function calculateOffset(state, old, update) { | |
return extend(state, { | |
// Create calculated properties. |
This file contains 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
var reducible = require("reducible/reducible"); | |
var isReduced = require("reducible/is-reduced"); | |
function fps(desiredFps) { | |
// Create a stream of times to use as an event loop with | |
// https://github.com/Gozala/coreduction/blob/master/coreduction.js | |
// Number -> Reducible[Float time, Float time, ...] | |
// Convert seconds to milliseconds. | |
var msPerFrame = 1000 / desiredFps |
This file contains 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
var nil = 'indicating a nil value'; | |
function reducePredicatePair(reduction, pair) { | |
// If no reduction has yet been found and the predicate | |
// matches, run the assocated function. | |
if(reduction[0] === nil && pair[0].apply(null, reduction[1])) { | |
reduction[0] = pair[1].apply(null, reduction[1]); | |
} | |
return reduction; | |
} |
This file contains 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
// Accumulators | |
// ============================================================================= | |
// | |
// A tiny library for reactive programming that offers blazing fast generic | |
// collection manipulation, asyncronous flow control and the ability to | |
// represent infinitely large collections. | |
// | |
// Copyright Gordon Brander, 2013. Released under the terms of the [MIT license](http://opensource.org/licenses/MIT). | |
// | |
// Background: |
This file contains 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
// https://en.wikipedia.org/wiki/Linked_list | |
// https://blog.jcoglan.com/2007/07/23/writing-a-linked-list-in-javascript/ | |
// Reducible prototype for linked list node. | |
var __node__ = { | |
reduce: function reduceNodes(reducer, initial) { | |
var node = this; | |
var accumulated = initial; | |
do { | |
accumulated = reducer(accumulated, node); |
This file contains 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
// Enumerate over an object's own keys/values, accumulating a value. | |
// `initial` defines the initial value for the accumulation. Reference is an | |
// optional additional argument that make a common case -- comparing 2 | |
// objects -- easy and more efficient. | |
function enumerate(object, next, initial, reference) { | |
var accumulated = initial; | |
for (var key in object) | |
// Test for own keys with `hasOwnProperty` instead of `Object.keys` to | |
// avoid garbage creation. | |
// |
This file contains 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
// Reduce any arraylike object. | |
function reduceIndexed(indexed, next, initial) { | |
var accumulated = initial; | |
for (var i = 0; i < indexed.length; i += 1) | |
accumulated = next(accumulated, indexed[i]); | |
return accumulated; | |
} |
This file contains 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
(function(exports) { | |
var modules = {} | |
var factories = {} | |
// Require a module by id. | |
function require(id) { | |
if (!(id in factories)) throw Error(id + ' module is not defined') | |
if (!(id in modules)) { | |
modules[id] = {} | |
factories[id](require, modules[id]) |