Skip to content

Instantly share code, notes, and snippets.

@hden
Last active September 13, 2021 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save hden/5080423 to your computer and use it in GitHub Desktop.
Save hden/5080423 to your computer and use it in GitHub Desktop.
D3 realtime visulization
(function(){var require = function (file, cwd) {
var resolved = require.resolve(file, cwd || '/');
var mod = require.modules[resolved];
if (!mod) throw new Error(
'Failed to resolve module ' + file + ', tried ' + resolved
);
var cached = require.cache[resolved];
var res = cached? cached.exports : mod();
return res;
};
require.paths = [];
require.modules = {};
require.cache = {};
require.extensions = [".js",".coffee",".json"];
require._core = {
'assert': true,
'events': true,
'fs': true,
'path': true,
'vm': true
};
require.resolve = (function () {
return function (x, cwd) {
if (!cwd) cwd = '/';
if (require._core[x]) return x;
var path = require.modules.path();
cwd = path.resolve('/', cwd);
var y = cwd || '/';
if (x.match(/^(?:\.\.?\/|\/)/)) {
var m = loadAsFileSync(path.resolve(y, x))
|| loadAsDirectorySync(path.resolve(y, x));
if (m) return m;
}
var n = loadNodeModulesSync(x, y);
if (n) return n;
throw new Error("Cannot find module '" + x + "'");
function loadAsFileSync (x) {
x = path.normalize(x);
if (require.modules[x]) {
return x;
}
for (var i = 0; i < require.extensions.length; i++) {
var ext = require.extensions[i];
if (require.modules[x + ext]) return x + ext;
}
}
function loadAsDirectorySync (x) {
x = x.replace(/\/+$/, '');
var pkgfile = path.normalize(x + '/package.json');
if (require.modules[pkgfile]) {
var pkg = require.modules[pkgfile]();
var b = pkg.browserify;
if (typeof b === 'object' && b.main) {
var m = loadAsFileSync(path.resolve(x, b.main));
if (m) return m;
}
else if (typeof b === 'string') {
var m = loadAsFileSync(path.resolve(x, b));
if (m) return m;
}
else if (pkg.main) {
var m = loadAsFileSync(path.resolve(x, pkg.main));
if (m) return m;
}
}
return loadAsFileSync(x + '/index');
}
function loadNodeModulesSync (x, start) {
var dirs = nodeModulesPathsSync(start);
for (var i = 0; i < dirs.length; i++) {
var dir = dirs[i];
var m = loadAsFileSync(dir + '/' + x);
if (m) return m;
var n = loadAsDirectorySync(dir + '/' + x);
if (n) return n;
}
var m = loadAsFileSync(x);
if (m) return m;
}
function nodeModulesPathsSync (start) {
var parts;
if (start === '/') parts = [ '' ];
else parts = path.normalize(start).split('/');
var dirs = [];
for (var i = parts.length - 1; i >= 0; i--) {
if (parts[i] === 'node_modules') continue;
var dir = parts.slice(0, i + 1).join('/') + '/node_modules';
dirs.push(dir);
}
return dirs;
}
};
})();
require.alias = function (from, to) {
var path = require.modules.path();
var res = null;
try {
res = require.resolve(from + '/package.json', '/');
}
catch (err) {
res = require.resolve(from, '/');
}
var basedir = path.dirname(res);
var keys = (Object.keys || function (obj) {
var res = [];
for (var key in obj) res.push(key);
return res;
})(require.modules);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (key.slice(0, basedir.length + 1) === basedir + '/') {
var f = key.slice(basedir.length);
require.modules[to + f] = require.modules[basedir + f];
}
else if (key === basedir) {
require.modules[to] = require.modules[basedir];
}
}
};
(function () {
var process = {};
var global = typeof window !== 'undefined' ? window : {};
var definedProcess = false;
require.define = function (filename, fn) {
if (!definedProcess && require.modules.__browserify_process) {
process = require.modules.__browserify_process();
definedProcess = true;
}
var dirname = require._core[filename]
? ''
: require.modules.path().dirname(filename)
;
var require_ = function (file) {
var requiredModule = require(file, dirname);
var cached = require.cache[require.resolve(file, dirname)];
if (cached && cached.parent === null) {
cached.parent = module_;
}
return requiredModule;
};
require_.resolve = function (name) {
return require.resolve(name, dirname);
};
require_.modules = require.modules;
require_.define = require.define;
require_.cache = require.cache;
var module_ = {
id : filename,
filename: filename,
exports : {},
loaded : false,
parent: null
};
require.modules[filename] = function () {
require.cache[filename] = module_;
fn.call(
module_.exports,
require_,
module_,
module_.exports,
dirname,
filename,
process,
global
);
module_.loaded = true;
return module_.exports;
};
};
})();
require.define("path",function(require,module,exports,__dirname,__filename,process,global){function filter (xs, fn) {
var res = [];
for (var i = 0; i < xs.length; i++) {
if (fn(xs[i], i, xs)) res.push(xs[i]);
}
return res;
}
// resolves . and .. elements in a path array with directory names there
// must be no slashes, empty elements, or device names (c:\) in the array
// (so also no leading and trailing slashes - it does not distinguish
// relative and absolute paths)
function normalizeArray(parts, allowAboveRoot) {
// if the path tries to go above the root, `up` ends up > 0
var up = 0;
for (var i = parts.length; i >= 0; i--) {
var last = parts[i];
if (last == '.') {
parts.splice(i, 1);
} else if (last === '..') {
parts.splice(i, 1);
up++;
} else if (up) {
parts.splice(i, 1);
up--;
}
}
// if the path is allowed to go above the root, restore leading ..s
if (allowAboveRoot) {
for (; up--; up) {
parts.unshift('..');
}
}
return parts;
}
// Regex to split a filename into [*, dir, basename, ext]
// posix version
var splitPathRe = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;
// path.resolve([from ...], to)
// posix version
exports.resolve = function() {
var resolvedPath = '',
resolvedAbsolute = false;
for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) {
var path = (i >= 0)
? arguments[i]
: process.cwd();
// Skip empty and invalid entries
if (typeof path !== 'string' || !path) {
continue;
}
resolvedPath = path + '/' + resolvedPath;
resolvedAbsolute = path.charAt(0) === '/';
}
// At this point the path should be resolved to a full absolute path, but
// handle relative paths to be safe (might happen when process.cwd() fails)
// Normalize the path
resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
return !!p;
}), !resolvedAbsolute).join('/');
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
};
// path.normalize(path)
// posix version
exports.normalize = function(path) {
var isAbsolute = path.charAt(0) === '/',
trailingSlash = path.slice(-1) === '/';
// Normalize the path
path = normalizeArray(filter(path.split('/'), function(p) {
return !!p;
}), !isAbsolute).join('/');
if (!path && !isAbsolute) {
path = '.';
}
if (path && trailingSlash) {
path += '/';
}
return (isAbsolute ? '/' : '') + path;
};
// posix version
exports.join = function() {
var paths = Array.prototype.slice.call(arguments, 0);
return exports.normalize(filter(paths, function(p, index) {
return p && typeof p === 'string';
}).join('/'));
};
exports.dirname = function(path) {
var dir = splitPathRe.exec(path)[1] || '';
var isWindows = false;
if (!dir) {
// No dirname
return '.';
} else if (dir.length === 1 ||
(isWindows && dir.length <= 3 && dir.charAt(1) === ':')) {
// It is just a slash or a drive letter with a slash
return dir;
} else {
// It is a full dirname, strip trailing slash
return dir.substring(0, dir.length - 1);
}
};
exports.basename = function(path, ext) {
var f = splitPathRe.exec(path)[2] || '';
// TODO: make this comparison case-insensitive on windows?
if (ext && f.substr(-1 * ext.length) === ext) {
f = f.substr(0, f.length - ext.length);
}
return f;
};
exports.extname = function(path) {
return splitPathRe.exec(path)[3] || '';
};
exports.relative = function(from, to) {
from = exports.resolve(from).substr(1);
to = exports.resolve(to).substr(1);
function trim(arr) {
var start = 0;
for (; start < arr.length; start++) {
if (arr[start] !== '') break;
}
var end = arr.length - 1;
for (; end >= 0; end--) {
if (arr[end] !== '') break;
}
if (start > end) return [];
return arr.slice(start, end - start + 1);
}
var fromParts = trim(from.split('/'));
var toParts = trim(to.split('/'));
var length = Math.min(fromParts.length, toParts.length);
var samePartsLength = length;
for (var i = 0; i < length; i++) {
if (fromParts[i] !== toParts[i]) {
samePartsLength = i;
break;
}
}
var outputParts = [];
for (var i = samePartsLength; i < fromParts.length; i++) {
outputParts.push('..');
}
outputParts = outputParts.concat(toParts.slice(samePartsLength));
return outputParts.join('/');
};
});
require.define("__browserify_process",function(require,module,exports,__dirname,__filename,process,global){var process = module.exports = {};
process.nextTick = (function () {
var canSetImmediate = typeof window !== 'undefined'
&& window.setImmediate;
var canPost = typeof window !== 'undefined'
&& window.postMessage && window.addEventListener
;
if (canSetImmediate) {
return function (f) { return window.setImmediate(f) };
}
if (canPost) {
var queue = [];
window.addEventListener('message', function (ev) {
if (ev.source === window && ev.data === 'browserify-tick') {
ev.stopPropagation();
if (queue.length > 0) {
var fn = queue.shift();
fn();
}
}
}, true);
return function nextTick(fn) {
queue.push(fn);
window.postMessage('browserify-tick', '*');
};
}
return function nextTick(fn) {
setTimeout(fn, 0);
};
})();
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.binding = function (name) {
if (name === 'evals') return (require)('vm')
else throw new Error('No such module. (Possibly not yet loaded)')
};
(function () {
var cwd = '/';
var path;
process.cwd = function () { return cwd };
process.chdir = function (dir) {
if (!path) path = require('path');
cwd = path.resolve(dir, cwd);
};
})();
});
require.define("/spec/lib/jasmine.js",function(require,module,exports,__dirname,__filename,process,global){var isCommonJS = true;
/**
* Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.
*
* @namespace
*/
var jasmine = {};
if (isCommonJS) exports.jasmine = jasmine;
/**
* @private
*/
jasmine.unimplementedMethod_ = function() {
throw new Error("unimplemented method");
};
/**
* Use <code>jasmine.undefined</code> instead of <code>undefined</code>, since <code>undefined</code> is just
* a plain old variable and may be redefined by somebody else.
*
* @private
*/
jasmine.undefined = jasmine.___undefined___;
/**
* Show diagnostic messages in the console if set to true
*
*/
jasmine.VERBOSE = false;
/**
* Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed.
*
*/
jasmine.DEFAULT_UPDATE_INTERVAL = 250;
/**
* Maximum levels of nesting that will be included when an object is pretty-printed
*/
jasmine.MAX_PRETTY_PRINT_DEPTH = 40;
/**
* Default timeout interval in milliseconds for waitsFor() blocks.
*/
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
/**
* By default exceptions thrown in the context of a test are caught by jasmine so that it can run the remaining tests in the suite.
* Set to false to let the exception bubble up in the browser.
*
*/
jasmine.CATCH_EXCEPTIONS = true;
jasmine.getGlobal = function() {
function getGlobal() {
return this;
}
return getGlobal();
};
/**
* Allows for bound functions to be compared. Internal use only.
*
* @ignore
* @private
* @param base {Object} bound 'this' for the function
* @param name {Function} function to find
*/
jasmine.bindOriginal_ = function(base, name) {
var original = base[name];
if (original.apply) {
return function() {
return original.apply(base, arguments);
};
} else {
// IE support
return jasmine.getGlobal()[name];
}
};
jasmine.setTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'setTimeout');
jasmine.clearTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearTimeout');
jasmine.setInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'setInterval');
jasmine.clearInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearInterval');
jasmine.MessageResult = function(values) {
this.type = 'log';
this.values = values;
this.trace = new Error(); // todo: test better
};
jasmine.MessageResult.prototype.toString = function() {
var text = "";
for (var i = 0; i < this.values.length; i++) {
if (i > 0) text += " ";
if (jasmine.isString_(this.values[i])) {
text += this.values[i];
} else {
text += jasmine.pp(this.values[i]);
}
}
return text;
};
jasmine.ExpectationResult = function(params) {
this.type = 'expect';
this.matcherName = params.matcherName;
this.passed_ = params.passed;
this.expected = params.expected;
this.actual = params.actual;
this.message = this.passed_ ? 'Passed.' : params.message;
var trace = (params.trace || new Error(this.message));
this.trace = this.passed_ ? '' : trace;
};
jasmine.ExpectationResult.prototype.toString = function () {
return this.message;
};
jasmine.ExpectationResult.prototype.passed = function () {
return this.passed_;
};
/**
* Getter for the Jasmine environment. Ensures one gets created
*/
jasmine.getEnv = function() {
var env = jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env();
return env;
};
/**
* @ignore
* @private
* @param value
* @returns {Boolean}
*/
jasmine.isArray_ = function(value) {
return jasmine.isA_("Array", value);
};
/**
* @ignore
* @private
* @param value
* @returns {Boolean}
*/
jasmine.isString_ = function(value) {
return jasmine.isA_("String", value);
};
/**
* @ignore
* @private
* @param value
* @returns {Boolean}
*/
jasmine.isNumber_ = function(value) {
return jasmine.isA_("Number", value);
};
/**
* @ignore
* @private
* @param {String} typeName
* @param value
* @returns {Boolean}
*/
jasmine.isA_ = function(typeName, value) {
return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
};
/**
* Pretty printer for expecations. Takes any object and turns it into a human-readable string.
*
* @param value {Object} an object to be outputted
* @returns {String}
*/
jasmine.pp = function(value) {
var stringPrettyPrinter = new jasmine.StringPrettyPrinter();
stringPrettyPrinter.format(value);
return stringPrettyPrinter.string;
};
/**
* Returns true if the object is a DOM Node.
*
* @param {Object} obj object to check
* @returns {Boolean}
*/
jasmine.isDomNode = function(obj) {
return obj.nodeType > 0;
};
/**
* Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter.
*
* @example
* // don't care about which function is passed in, as long as it's a function
* expect(mySpy).toHaveBeenCalledWith(jasmine.any(Function));
*
* @param {Class} clazz
* @returns matchable object of the type clazz
*/
jasmine.any = function(clazz) {
return new jasmine.Matchers.Any(clazz);
};
/**
* Returns a matchable subset of a JSON object. For use in expectations when you don't care about all of the
* attributes on the object.
*
* @example
* // don't care about any other attributes than foo.
* expect(mySpy).toHaveBeenCalledWith(jasmine.objectContaining({foo: "bar"});
*
* @param sample {Object} sample
* @returns matchable object for the sample
*/
jasmine.objectContaining = function (sample) {
return new jasmine.Matchers.ObjectContaining(sample);
};
/**
* Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks.
*
* Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine
* expectation syntax. Spies can be checked if they were called or not and what the calling params were.
*
* A Spy has the following fields: wasCalled, callCount, mostRecentCall, and argsForCall (see docs).
*
* Spies are torn down at the end of every spec.
*
* Note: Do <b>not</b> call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj.
*
* @example
* // a stub
* var myStub = jasmine.createSpy('myStub'); // can be used anywhere
*
* // spy example
* var foo = {
* not: function(bool) { return !bool; }
* }
*
* // actual foo.not will not be called, execution stops
* spyOn(foo, 'not');
// foo.not spied upon, execution will continue to implementation
* spyOn(foo, 'not').andCallThrough();
*
* // fake example
* var foo = {
* not: function(bool) { return !bool; }
* }
*
* // foo.not(val) will return val
* spyOn(foo, 'not').andCallFake(function(value) {return value;});
*
* // mock example
* foo.not(7 == 7);
* expect(foo.not).toHaveBeenCalled();
* expect(foo.not).toHaveBeenCalledWith(true);
*
* @constructor
* @see spyOn, jasmine.createSpy, jasmine.createSpyObj
* @param {String} name
*/
jasmine.Spy = function(name) {
/**
* The name of the spy, if provided.
*/
this.identity = name || 'unknown';
/**
* Is this Object a spy?
*/
this.isSpy = true;
/**
* The actual function this spy stubs.
*/
this.plan = function() {
};
/**
* Tracking of the most recent call to the spy.
* @example
* var mySpy = jasmine.createSpy('foo');
* mySpy(1, 2);
* mySpy.mostRecentCall.args = [1, 2];
*/
this.mostRecentCall = {};
/**
* Holds arguments for each call to the spy, indexed by call count
* @example
* var mySpy = jasmine.createSpy('foo');
* mySpy(1, 2);
* mySpy(7, 8);
* mySpy.mostRecentCall.args = [7, 8];
* mySpy.argsForCall[0] = [1, 2];
* mySpy.argsForCall[1] = [7, 8];
*/
this.argsForCall = [];
this.calls = [];
};
/**
* Tells a spy to call through to the actual implemenatation.
*
* @example
* var foo = {
* bar: function() { // do some stuff }
* }
*
* // defining a spy on an existing property: foo.bar
* spyOn(foo, 'bar').andCallThrough();
*/
jasmine.Spy.prototype.andCallThrough = function() {
this.plan = this.originalValue;
return this;
};
/**
* For setting the return value of a spy.
*
* @example
* // defining a spy from scratch: foo() returns 'baz'
* var foo = jasmine.createSpy('spy on foo').andReturn('baz');
*
* // defining a spy on an existing property: foo.bar() returns 'baz'
* spyOn(foo, 'bar').andReturn('baz');
*
* @param {Object} value
*/
jasmine.Spy.prototype.andReturn = function(value) {
this.plan = function() {
return value;
};
return this;
};
/**
* For throwing an exception when a spy is called.
*
* @example
* // defining a spy from scratch: foo() throws an exception w/ message 'ouch'
* var foo = jasmine.createSpy('spy on foo').andThrow('baz');
*
* // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch'
* spyOn(foo, 'bar').andThrow('baz');
*
* @param {String} exceptionMsg
*/
jasmine.Spy.prototype.andThrow = function(exceptionMsg) {
this.plan = function() {
throw exceptionMsg;
};
return this;
};
/**
* Calls an alternate implementation when a spy is called.
*
* @example
* var baz = function() {
* // do some stuff, return something
* }
* // defining a spy from scratch: foo() calls the function baz
* var foo = jasmine.createSpy('spy on foo').andCall(baz);
*
* // defining a spy on an existing property: foo.bar() calls an anonymnous function
* spyOn(foo, 'bar').andCall(function() { return 'baz';} );
*
* @param {Function} fakeFunc
*/
jasmine.Spy.prototype.andCallFake = function(fakeFunc) {
this.plan = fakeFunc;
return this;
};
/**
* Resets all of a spy's the tracking variables so that it can be used again.
*
* @example
* spyOn(foo, 'bar');
*
* foo.bar();
*
* expect(foo.bar.callCount).toEqual(1);
*
* foo.bar.reset();
*
* expect(foo.bar.callCount).toEqual(0);
*/
jasmine.Spy.prototype.reset = function() {
this.wasCalled = false;
this.callCount = 0;
this.argsForCall = [];
this.calls = [];
this.mostRecentCall = {};
};
jasmine.createSpy = function(name) {
var spyObj = function() {
spyObj.wasCalled = true;
spyObj.callCount++;
var args = jasmine.util.argsToArray(arguments);
spyObj.mostRecentCall.object = this;
spyObj.mostRecentCall.args = args;
spyObj.argsForCall.push(args);
spyObj.calls.push({object: this, args: args});
return spyObj.plan.apply(this, arguments);
};
var spy = new jasmine.Spy(name);
for (var prop in spy) {
spyObj[prop] = spy[prop];
}
spyObj.reset();
return spyObj;
};
/**
* Determines whether an object is a spy.
*
* @param {jasmine.Spy|Object} putativeSpy
* @returns {Boolean}
*/
jasmine.isSpy = function(putativeSpy) {
return putativeSpy && putativeSpy.isSpy;
};
/**
* Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something
* large in one call.
*
* @param {String} baseName name of spy class
* @param {Array} methodNames array of names of methods to make spies
*/
jasmine.createSpyObj = function(baseName, methodNames) {
if (!jasmine.isArray_(methodNames) || methodNames.length === 0) {
throw new Error('createSpyObj requires a non-empty array of method names to create spies for');
}
var obj = {};
for (var i = 0; i < methodNames.length; i++) {
obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]);
}
return obj;
};
/**
* All parameters are pretty-printed and concatenated together, then written to the current spec's output.
*
* Be careful not to leave calls to <code>jasmine.log</code> in production code.
*/
jasmine.log = function() {
var spec = jasmine.getEnv().currentSpec;
spec.log.apply(spec, arguments);
};
/**
* Function that installs a spy on an existing object's method name. Used within a Spec to create a spy.
*
* @example
* // spy example
* var foo = {
* not: function(bool) { return !bool; }
* }
* spyOn(foo, 'not'); // actual foo.not will not be called, execution stops
*
* @see jasmine.createSpy
* @param obj
* @param methodName
* @return {jasmine.Spy} a Jasmine spy that can be chained with all spy methods
*/
var spyOn = function(obj, methodName) {
return jasmine.getEnv().currentSpec.spyOn(obj, methodName);
};
if (isCommonJS) exports.spyOn = spyOn;
/**
* Creates a Jasmine spec that will be added to the current suite.
*
* // TODO: pending tests
*
* @example
* it('should be true', function() {
* expect(true).toEqual(true);
* });
*
* @param {String} desc description of this specification
* @param {Function} func defines the preconditions and expectations of the spec
*/
var it = function(desc, func) {
return jasmine.getEnv().it(desc, func);
};
if (isCommonJS) exports.it = it;
/**
* Creates a <em>disabled</em> Jasmine spec.
*
* A convenience method that allows existing specs to be disabled temporarily during development.
*
* @param {String} desc description of this specification
* @param {Function} func defines the preconditions and expectations of the spec
*/
var xit = function(desc, func) {
return jasmine.getEnv().xit(desc, func);
};
if (isCommonJS) exports.xit = xit;
/**
* Starts a chain for a Jasmine expectation.
*
* It is passed an Object that is the actual value and should chain to one of the many
* jasmine.Matchers functions.
*
* @param {Object} actual Actual value to test against and expected value
* @return {jasmine.Matchers}
*/
var expect = function(actual) {
return jasmine.getEnv().currentSpec.expect(actual);
};
if (isCommonJS) exports.expect = expect;
/**
* Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs.
*
* @param {Function} func Function that defines part of a jasmine spec.
*/
var runs = function(func) {
jasmine.getEnv().currentSpec.runs(func);
};
if (isCommonJS) exports.runs = runs;
/**
* Waits a fixed time period before moving to the next block.
*
* @deprecated Use waitsFor() instead
* @param {Number} timeout milliseconds to wait
*/
var waits = function(timeout) {
jasmine.getEnv().currentSpec.waits(timeout);
};
if (isCommonJS) exports.waits = waits;
/**
* Waits for the latchFunction to return true before proceeding to the next block.
*
* @param {Function} latchFunction
* @param {String} optional_timeoutMessage
* @param {Number} optional_timeout
*/
var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments);
};
if (isCommonJS) exports.waitsFor = waitsFor;
/**
* A function that is called before each spec in a suite.
*
* Used for spec setup, including validating assumptions.
*
* @param {Function} beforeEachFunction
*/
var beforeEach = function(beforeEachFunction) {
jasmine.getEnv().beforeEach(beforeEachFunction);
};
if (isCommonJS) exports.beforeEach = beforeEach;
/**
* A function that is called after each spec in a suite.
*
* Used for restoring any state that is hijacked during spec execution.
*
* @param {Function} afterEachFunction
*/
var afterEach = function(afterEachFunction) {
jasmine.getEnv().afterEach(afterEachFunction);
};
if (isCommonJS) exports.afterEach = afterEach;
/**
* Defines a suite of specifications.
*
* Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared
* are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization
* of setup in some tests.
*
* @example
* // TODO: a simple suite
*
* // TODO: a simple suite with a nested describe block
*
* @param {String} description A string, usually the class under test.
* @param {Function} specDefinitions function that defines several specs.
*/
var describe = function(description, specDefinitions) {
return jasmine.getEnv().describe(description, specDefinitions);
};
if (isCommonJS) exports.describe = describe;
/**
* Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development.
*
* @param {String} description A string, usually the class under test.
* @param {Function} specDefinitions function that defines several specs.
*/
var xdescribe = function(description, specDefinitions) {
return jasmine.getEnv().xdescribe(description, specDefinitions);
};
if (isCommonJS) exports.xdescribe = xdescribe;
// Provide the XMLHttpRequest class for IE 5.x-6.x:
jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() {
function tryIt(f) {
try {
return f();
} catch(e) {
}
return null;
}
var xhr = tryIt(function() {
return new ActiveXObject("Msxml2.XMLHTTP.6.0");
}) ||
tryIt(function() {
return new ActiveXObject("Msxml2.XMLHTTP.3.0");
}) ||
tryIt(function() {
return new ActiveXObject("Msxml2.XMLHTTP");
}) ||
tryIt(function() {
return new ActiveXObject("Microsoft.XMLHTTP");
});
if (!xhr) throw new Error("This browser does not support XMLHttpRequest.");
return xhr;
} : XMLHttpRequest;
/**
* @namespace
*/
jasmine.util = {};
/**
* Declare that a child class inherit it's prototype from the parent class.
*
* @private
* @param {Function} childClass
* @param {Function} parentClass
*/
jasmine.util.inherit = function(childClass, parentClass) {
/**
* @private
*/
var subclass = function() {
};
subclass.prototype = parentClass.prototype;
childClass.prototype = new subclass();
};
jasmine.util.formatException = function(e) {
var lineNumber;
if (e.line) {
lineNumber = e.line;
}
else if (e.lineNumber) {
lineNumber = e.lineNumber;
}
var file;
if (e.sourceURL) {
file = e.sourceURL;
}
else if (e.fileName) {
file = e.fileName;
}
var message = (e.name && e.message) ? (e.name + ': ' + e.message) : e.toString();
if (file && lineNumber) {
message += ' in ' + file + ' (line ' + lineNumber + ')';
}
return message;
};
jasmine.util.htmlEscape = function(str) {
if (!str) return str;
return str.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
};
jasmine.util.argsToArray = function(args) {
var arrayOfArgs = [];
for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]);
return arrayOfArgs;
};
jasmine.util.extend = function(destination, source) {
for (var property in source) destination[property] = source[property];
return destination;
};
/**
* Environment for Jasmine
*
* @constructor
*/
jasmine.Env = function() {
this.currentSpec = null;
this.currentSuite = null;
this.currentRunner_ = new jasmine.Runner(this);
this.reporter = new jasmine.MultiReporter();
this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL;
this.defaultTimeoutInterval = jasmine.DEFAULT_TIMEOUT_INTERVAL;
this.lastUpdate = 0;
this.specFilter = function() {
return true;
};
this.nextSpecId_ = 0;
this.nextSuiteId_ = 0;
this.equalityTesters_ = [];
// wrap matchers
this.matchersClass = function() {
jasmine.Matchers.apply(this, arguments);
};
jasmine.util.inherit(this.matchersClass, jasmine.Matchers);
jasmine.Matchers.wrapInto_(jasmine.Matchers.prototype, this.matchersClass);
};
jasmine.Env.prototype.setTimeout = jasmine.setTimeout;
jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout;
jasmine.Env.prototype.setInterval = jasmine.setInterval;
jasmine.Env.prototype.clearInterval = jasmine.clearInterval;
/**
* @returns an object containing jasmine version build info, if set.
*/
jasmine.Env.prototype.version = function () {
if (jasmine.version_) {
return jasmine.version_;
} else {
throw new Error('Version not set');
}
};
/**
* @returns string containing jasmine version build info, if set.
*/
jasmine.Env.prototype.versionString = function() {
if (!jasmine.version_) {
return "version unknown";
}
var version = this.version();
var versionString = version.major + "." + version.minor + "." + version.build;
if (version.release_candidate) {
versionString += ".rc" + version.release_candidate;
}
versionString += " revision " + version.revision;
return versionString;
};
/**
* @returns a sequential integer starting at 0
*/
jasmine.Env.prototype.nextSpecId = function () {
return this.nextSpecId_++;
};
/**
* @returns a sequential integer starting at 0
*/
jasmine.Env.prototype.nextSuiteId = function () {
return this.nextSuiteId_++;
};
/**
* Register a reporter to receive status updates from Jasmine.
* @param {jasmine.Reporter} reporter An object which will receive status updates.
*/
jasmine.Env.prototype.addReporter = function(reporter) {
this.reporter.addReporter(reporter);
};
jasmine.Env.prototype.execute = function() {
this.currentRunner_.execute();
};
jasmine.Env.prototype.describe = function(description, specDefinitions) {
var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite);
var parentSuite = this.currentSuite;
if (parentSuite) {
parentSuite.add(suite);
} else {
this.currentRunner_.add(suite);
}
this.currentSuite = suite;
var declarationError = null;
try {
specDefinitions.call(suite);
} catch(e) {
declarationError = e;
}
if (declarationError) {
this.it("encountered a declaration exception", function() {
throw declarationError;
});
}
this.currentSuite = parentSuite;
return suite;
};
jasmine.Env.prototype.beforeEach = function(beforeEachFunction) {
if (this.currentSuite) {
this.currentSuite.beforeEach(beforeEachFunction);
} else {
this.currentRunner_.beforeEach(beforeEachFunction);
}
};
jasmine.Env.prototype.currentRunner = function () {
return this.currentRunner_;
};
jasmine.Env.prototype.afterEach = function(afterEachFunction) {
if (this.currentSuite) {
this.currentSuite.afterEach(afterEachFunction);
} else {
this.currentRunner_.afterEach(afterEachFunction);
}
};
jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) {
return {
execute: function() {
}
};
};
jasmine.Env.prototype.it = function(description, func) {
var spec = new jasmine.Spec(this, this.currentSuite, description);
this.currentSuite.add(spec);
this.currentSpec = spec;
if (func) {
spec.runs(func);
}
return spec;
};
jasmine.Env.prototype.xit = function(desc, func) {
return {
id: this.nextSpecId(),
runs: function() {
}
};
};
jasmine.Env.prototype.compareRegExps_ = function(a, b, mismatchKeys, mismatchValues) {
if (a.source != b.source)
mismatchValues.push("expected pattern /" + b.source + "/ is not equal to the pattern /" + a.source + "/");
if (a.ignoreCase != b.ignoreCase)
mismatchValues.push("expected modifier i was" + (b.ignoreCase ? " " : " not ") + "set and does not equal the origin modifier");
if (a.global != b.global)
mismatchValues.push("expected modifier g was" + (b.global ? " " : " not ") + "set and does not equal the origin modifier");
if (a.multiline != b.multiline)
mismatchValues.push("expected modifier m was" + (b.multiline ? " " : " not ") + "set and does not equal the origin modifier");
if (a.sticky != b.sticky)
mismatchValues.push("expected modifier y was" + (b.sticky ? " " : " not ") + "set and does not equal the origin modifier");
return (mismatchValues.length === 0);
};
jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) {
if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) {
return true;
}
a.__Jasmine_been_here_before__ = b;
b.__Jasmine_been_here_before__ = a;
var hasKey = function(obj, keyName) {
return obj !== null && obj[keyName] !== jasmine.undefined;
};
for (var property in b) {
if (!hasKey(a, property) && hasKey(b, property)) {
mismatchKeys.push("expected has key '" + property + "', but missing from actual.");
}
}
for (property in a) {
if (!hasKey(b, property) && hasKey(a, property)) {
mismatchKeys.push("expected missing key '" + property + "', but present in actual.");
}
}
for (property in b) {
if (property == '__Jasmine_been_here_before__') continue;
if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) {
mismatchValues.push("'" + property + "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual.");
}
}
if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) {
mismatchValues.push("arrays were not the same length");
}
delete a.__Jasmine_been_here_before__;
delete b.__Jasmine_been_here_before__;
return (mismatchKeys.length === 0 && mismatchValues.length === 0);
};
jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
mismatchKeys = mismatchKeys || [];
mismatchValues = mismatchValues || [];
for (var i = 0; i < this.equalityTesters_.length; i++) {
var equalityTester = this.equalityTesters_[i];
var result = equalityTester(a, b, this, mismatchKeys, mismatchValues);
if (result !== jasmine.undefined) return result;
}
if (a === b) return true;
if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) {
return (a == jasmine.undefined && b == jasmine.undefined);
}
if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) {
return a === b;
}
if (a instanceof Date && b instanceof Date) {
return a.getTime() == b.getTime();
}
if (a.jasmineMatches) {
return a.jasmineMatches(b);
}
if (b.jasmineMatches) {
return b.jasmineMatches(a);
}
if (a instanceof jasmine.Matchers.ObjectContaining) {
return a.matches(b);
}
if (b instanceof jasmine.Matchers.ObjectContaining) {
return b.matches(a);
}
if (jasmine.isString_(a) && jasmine.isString_(b)) {
return (a == b);
}
if (jasmine.isNumber_(a) && jasmine.isNumber_(b)) {
return (a == b);
}
if (a instanceof RegExp && b instanceof RegExp) {
return this.compareRegExps_(a, b, mismatchKeys, mismatchValues);
}
if (typeof a === "object" && typeof b === "object") {
return this.compareObjects_(a, b, mismatchKeys, mismatchValues);
}
//Straight check
return (a === b);
};
jasmine.Env.prototype.contains_ = function(haystack, needle) {
if (jasmine.isArray_(haystack)) {
for (var i = 0; i < haystack.length; i++) {
if (this.equals_(haystack[i], needle)) return true;
}
return false;
}
return haystack.indexOf(needle) >= 0;
};
jasmine.Env.prototype.addEqualityTester = function(equalityTester) {
this.equalityTesters_.push(equalityTester);
};
/** No-op base class for Jasmine reporters.
*
* @constructor
*/
jasmine.Reporter = function() {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.reportRunnerStarting = function(runner) {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.reportRunnerResults = function(runner) {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.reportSuiteResults = function(suite) {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.reportSpecStarting = function(spec) {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.reportSpecResults = function(spec) {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.log = function(str) {
};
/**
* Blocks are functions with executable code that make up a spec.
*
* @constructor
* @param {jasmine.Env} env
* @param {Function} func
* @param {jasmine.Spec} spec
*/
jasmine.Block = function(env, func, spec) {
this.env = env;
this.func = func;
this.spec = spec;
};
jasmine.Block.prototype.execute = function(onComplete) {
if (!jasmine.CATCH_EXCEPTIONS) {
this.func.apply(this.spec);
}
else {
try {
this.func.apply(this.spec);
} catch (e) {
this.spec.fail(e);
}
}
onComplete();
};
/** JavaScript API reporter.
*
* @constructor
*/
jasmine.JsApiReporter = function() {
this.started = false;
this.finished = false;
this.suites_ = [];
this.results_ = {};
};
jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) {
this.started = true;
var suites = runner.topLevelSuites();
for (var i = 0; i < suites.length; i++) {
var suite = suites[i];
this.suites_.push(this.summarize_(suite));
}
};
jasmine.JsApiReporter.prototype.suites = function() {
return this.suites_;
};
jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) {
var isSuite = suiteOrSpec instanceof jasmine.Suite;
var summary = {
id: suiteOrSpec.id,
name: suiteOrSpec.description,
type: isSuite ? 'suite' : 'spec',
children: []
};
if (isSuite) {
var children = suiteOrSpec.children();
for (var i = 0; i < children.length; i++) {
summary.children.push(this.summarize_(children[i]));
}
}
return summary;
};
jasmine.JsApiReporter.prototype.results = function() {
return this.results_;
};
jasmine.JsApiReporter.prototype.resultsForSpec = function(specId) {
return this.results_[specId];
};
//noinspection JSUnusedLocalSymbols
jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) {
this.finished = true;
};
//noinspection JSUnusedLocalSymbols
jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) {
};
//noinspection JSUnusedLocalSymbols
jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) {
this.results_[spec.id] = {
messages: spec.results().getItems(),
result: spec.results().failedCount > 0 ? "failed" : "passed"
};
};
//noinspection JSUnusedLocalSymbols
jasmine.JsApiReporter.prototype.log = function(str) {
};
jasmine.JsApiReporter.prototype.resultsForSpecs = function(specIds){
var results = {};
for (var i = 0; i < specIds.length; i++) {
var specId = specIds[i];
results[specId] = this.summarizeResult_(this.results_[specId]);
}
return results;
};
jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){
var summaryMessages = [];
var messagesLength = result.messages.length;
for (var messageIndex = 0; messageIndex < messagesLength; messageIndex++) {
var resultMessage = result.messages[messageIndex];
summaryMessages.push({
text: resultMessage.type == 'log' ? resultMessage.toString() : jasmine.undefined,
passed: resultMessage.passed ? resultMessage.passed() : true,
type: resultMessage.type,
message: resultMessage.message,
trace: {
stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : jasmine.undefined
}
});
}
return {
result : result.result,
messages : summaryMessages
};
};
/**
* @constructor
* @param {jasmine.Env} env
* @param actual
* @param {jasmine.Spec} spec
*/
jasmine.Matchers = function(env, actual, spec, opt_isNot) {
this.env = env;
this.actual = actual;
this.spec = spec;
this.isNot = opt_isNot || false;
this.reportWasCalled_ = false;
};
// todo: @deprecated as of Jasmine 0.11, remove soon [xw]
jasmine.Matchers.pp = function(str) {
throw new Error("jasmine.Matchers.pp() is no longer supported, please use jasmine.pp() instead!");
};
// todo: @deprecated Deprecated as of Jasmine 0.10. Rewrite your custom matchers to return true or false. [xw]
jasmine.Matchers.prototype.report = function(result, failing_message, details) {
throw new Error("As of jasmine 0.11, custom matchers must be implemented differently -- please see jasmine docs");
};
jasmine.Matchers.wrapInto_ = function(prototype, matchersClass) {
for (var methodName in prototype) {
if (methodName == 'report') continue;
var orig = prototype[methodName];
matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig);
}
};
jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
return function() {
var matcherArgs = jasmine.util.argsToArray(arguments);
var result = matcherFunction.apply(this, arguments);
if (this.isNot) {
result = !result;
}
if (this.reportWasCalled_) return result;
var message;
if (!result) {
if (this.message) {
message = this.message.apply(this, arguments);
if (jasmine.isArray_(message)) {
message = message[this.isNot ? 1 : 0];
}
} else {
var englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); });
message = "Expected " + jasmine.pp(this.actual) + (this.isNot ? " not " : " ") + englishyPredicate;
if (matcherArgs.length > 0) {
for (var i = 0; i < matcherArgs.length; i++) {
if (i > 0) message += ",";
message += " " + jasmine.pp(matcherArgs[i]);
}
}
message += ".";
}
}
var expectationResult = new jasmine.ExpectationResult({
matcherName: matcherName,
passed: result,
expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0],
actual: this.actual,
message: message
});
this.spec.addMatcherResult(expectationResult);
return jasmine.undefined;
};
};
/**
* toBe: compares the actual to the expected using ===
* @param expected
*/
jasmine.Matchers.prototype.toBe = function(expected) {
return this.actual === expected;
};
/**
* toNotBe: compares the actual to the expected using !==
* @param expected
* @deprecated as of 1.0. Use not.toBe() instead.
*/
jasmine.Matchers.prototype.toNotBe = function(expected) {
return this.actual !== expected;
};
/**
* toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc.
*
* @param expected
*/
jasmine.Matchers.prototype.toEqual = function(expected) {
return this.env.equals_(this.actual, expected);
};
/**
* toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual
* @param expected
* @deprecated as of 1.0. Use not.toEqual() instead.
*/
jasmine.Matchers.prototype.toNotEqual = function(expected) {
return !this.env.equals_(this.actual, expected);
};
/**
* Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes
* a pattern or a String.
*
* @param expected
*/
jasmine.Matchers.prototype.toMatch = function(expected) {
return new RegExp(expected).test(this.actual);
};
/**
* Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch
* @param expected
* @deprecated as of 1.0. Use not.toMatch() instead.
*/
jasmine.Matchers.prototype.toNotMatch = function(expected) {
return !(new RegExp(expected).test(this.actual));
};
/**
* Matcher that compares the actual to jasmine.undefined.
*/
jasmine.Matchers.prototype.toBeDefined = function() {
return (this.actual !== jasmine.undefined);
};
/**
* Matcher that compares the actual to jasmine.undefined.
*/
jasmine.Matchers.prototype.toBeUndefined = function() {
return (this.actual === jasmine.undefined);
};
/**
* Matcher that compares the actual to null.
*/
jasmine.Matchers.prototype.toBeNull = function() {
return (this.actual === null);
};
/**
* Matcher that compares the actual to NaN.
*/
jasmine.Matchers.prototype.toBeNaN = function() {
this.message = function() {
return [ "Expected " + jasmine.pp(this.actual) + " to be NaN." ];
};
return (this.actual !== this.actual);
};
/**
* Matcher that boolean not-nots the actual.
*/
jasmine.Matchers.prototype.toBeTruthy = function() {
return !!this.actual;
};
/**
* Matcher that boolean nots the actual.
*/
jasmine.Matchers.prototype.toBeFalsy = function() {
return !this.actual;
};
/**
* Matcher that checks to see if the actual, a Jasmine spy, was called.
*/
jasmine.Matchers.prototype.toHaveBeenCalled = function() {
if (arguments.length > 0) {
throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith');
}
if (!jasmine.isSpy(this.actual)) {
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
}
this.message = function() {
return [
"Expected spy " + this.actual.identity + " to have been called.",
"Expected spy " + this.actual.identity + " not to have been called."
];
};
return this.actual.wasCalled;
};
/** @deprecated Use expect(xxx).toHaveBeenCalled() instead */
jasmine.Matchers.prototype.wasCalled = jasmine.Matchers.prototype.toHaveBeenCalled;
/**
* Matcher that checks to see if the actual, a Jasmine spy, was not called.
*
* @deprecated Use expect(xxx).not.toHaveBeenCalled() instead
*/
jasmine.Matchers.prototype.wasNotCalled = function() {
if (arguments.length > 0) {
throw new Error('wasNotCalled does not take arguments');
}
if (!jasmine.isSpy(this.actual)) {
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
}
this.message = function() {
return [
"Expected spy " + this.actual.identity + " to not have been called.",
"Expected spy " + this.actual.identity + " to have been called."
];
};
return !this.actual.wasCalled;
};
/**
* Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters.
*
* @example
*
*/
jasmine.Matchers.prototype.toHaveBeenCalledWith = function() {
var expectedArgs = jasmine.util.argsToArray(arguments);
if (!jasmine.isSpy(this.actual)) {
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
}
this.message = function() {
var invertedMessage = "Expected spy " + this.actual.identity + " not to have been called with " + jasmine.pp(expectedArgs) + " but it was.";
var positiveMessage = "";
if (this.actual.callCount === 0) {
positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.";
} else {
positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but actual calls were " + jasmine.pp(this.actual.argsForCall).replace(/^\[ | \]$/g, '')
}
return [positiveMessage, invertedMessage];
};
return this.env.contains_(this.actual.argsForCall, expectedArgs);
};
/** @deprecated Use expect(xxx).toHaveBeenCalledWith() instead */
jasmine.Matchers.prototype.wasCalledWith = jasmine.Matchers.prototype.toHaveBeenCalledWith;
/** @deprecated Use expect(xxx).not.toHaveBeenCalledWith() instead */
jasmine.Matchers.prototype.wasNotCalledWith = function() {
var expectedArgs = jasmine.util.argsToArray(arguments);
if (!jasmine.isSpy(this.actual)) {
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
}
this.message = function() {
return [
"Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was",
"Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was"
];
};
return !this.env.contains_(this.actual.argsForCall, expectedArgs);
};
/**
* Matcher that checks that the expected item is an element in the actual Array.
*
* @param {Object} expected
*/
jasmine.Matchers.prototype.toContain = function(expected) {
return this.env.contains_(this.actual, expected);
};
/**
* Matcher that checks that the expected item is NOT an element in the actual Array.
*
* @param {Object} expected
* @deprecated as of 1.0. Use not.toContain() instead.
*/
jasmine.Matchers.prototype.toNotContain = function(expected) {
return !this.env.contains_(this.actual, expected);
};
jasmine.Matchers.prototype.toBeLessThan = function(expected) {
return this.actual < expected;
};
jasmine.Matchers.prototype.toBeGreaterThan = function(expected) {
return this.actual > expected;
};
/**
* Matcher that checks that the expected item is equal to the actual item
* up to a given level of decimal precision (default 2).
*
* @param {Number} expected
* @param {Number} precision, as number of decimal places
*/
jasmine.Matchers.prototype.toBeCloseTo = function(expected, precision) {
if (!(precision === 0)) {
precision = precision || 2;
}
return Math.abs(expected - this.actual) < (Math.pow(10, -precision) / 2);
};
/**
* Matcher that checks that the expected exception was thrown by the actual.
*
* @param {String} [expected]
*/
jasmine.Matchers.prototype.toThrow = function(expected) {
var result = false;
var exception;
if (typeof this.actual != 'function') {
throw new Error('Actual is not a function');
}
try {
this.actual();
} catch (e) {
exception = e;
}
if (exception) {
result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected));
}
var not = this.isNot ? "not " : "";
this.message = function() {
if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
return ["Expected function " + not + "to throw", expected ? expected.message || expected : "an exception", ", but it threw", exception.message || exception].join(' ');
} else {
return "Expected function to throw an exception.";
}
};
return result;
};
jasmine.Matchers.Any = function(expectedClass) {
this.expectedClass = expectedClass;
};
jasmine.Matchers.Any.prototype.jasmineMatches = function(other) {
if (this.expectedClass == String) {
return typeof other == 'string' || other instanceof String;
}
if (this.expectedClass == Number) {
return typeof other == 'number' || other instanceof Number;
}
if (this.expectedClass == Function) {
return typeof other == 'function' || other instanceof Function;
}
if (this.expectedClass == Object) {
return typeof other == 'object';
}
return other instanceof this.expectedClass;
};
jasmine.Matchers.Any.prototype.jasmineToString = function() {
return '<jasmine.any(' + this.expectedClass + ')>';
};
jasmine.Matchers.ObjectContaining = function (sample) {
this.sample = sample;
};
jasmine.Matchers.ObjectContaining.prototype.jasmineMatches = function(other, mismatchKeys, mismatchValues) {
mismatchKeys = mismatchKeys || [];
mismatchValues = mismatchValues || [];
var env = jasmine.getEnv();
var hasKey = function(obj, keyName) {
return obj != null && obj[keyName] !== jasmine.undefined;
};
for (var property in this.sample) {
if (!hasKey(other, property) && hasKey(this.sample, property)) {
mismatchKeys.push("expected has key '" + property + "', but missing from actual.");
}
else if (!env.equals_(this.sample[property], other[property], mismatchKeys, mismatchValues)) {
mismatchValues.push("'" + property + "' was '" + (other[property] ? jasmine.util.htmlEscape(other[property].toString()) : other[property]) + "' in expected, but was '" + (this.sample[property] ? jasmine.util.htmlEscape(this.sample[property].toString()) : this.sample[property]) + "' in actual.");
}
}
return (mismatchKeys.length === 0 && mismatchValues.length === 0);
};
jasmine.Matchers.ObjectContaining.prototype.jasmineToString = function () {
return "<jasmine.objectContaining(" + jasmine.pp(this.sample) + ")>";
};
// Mock setTimeout, clearTimeout
// Contributed by Pivotal Computer Systems, www.pivotalsf.com
jasmine.FakeTimer = function() {
this.reset();
var self = this;
self.setTimeout = function(funcToCall, millis) {
self.timeoutsMade++;
self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false);
return self.timeoutsMade;
};
self.setInterval = function(funcToCall, millis) {
self.timeoutsMade++;
self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true);
return self.timeoutsMade;
};
self.clearTimeout = function(timeoutKey) {
self.scheduledFunctions[timeoutKey] = jasmine.undefined;
};
self.clearInterval = function(timeoutKey) {
self.scheduledFunctions[timeoutKey] = jasmine.undefined;
};
};
jasmine.FakeTimer.prototype.reset = function() {
this.timeoutsMade = 0;
this.scheduledFunctions = {};
this.nowMillis = 0;
};
jasmine.FakeTimer.prototype.tick = function(millis) {
var oldMillis = this.nowMillis;
var newMillis = oldMillis + millis;
this.runFunctionsWithinRange(oldMillis, newMillis);
this.nowMillis = newMillis;
};
jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) {
var scheduledFunc;
var funcsToRun = [];
for (var timeoutKey in this.scheduledFunctions) {
scheduledFunc = this.scheduledFunctions[timeoutKey];
if (scheduledFunc != jasmine.undefined &&
scheduledFunc.runAtMillis >= oldMillis &&
scheduledFunc.runAtMillis <= nowMillis) {
funcsToRun.push(scheduledFunc);
this.scheduledFunctions[timeoutKey] = jasmine.undefined;
}
}
if (funcsToRun.length > 0) {
funcsToRun.sort(function(a, b) {
return a.runAtMillis - b.runAtMillis;
});
for (var i = 0; i < funcsToRun.length; ++i) {
try {
var funcToRun = funcsToRun[i];
this.nowMillis = funcToRun.runAtMillis;
funcToRun.funcToCall();
if (funcToRun.recurring) {
this.scheduleFunction(funcToRun.timeoutKey,
funcToRun.funcToCall,
funcToRun.millis,
true);
}
} catch(e) {
}
}
this.runFunctionsWithinRange(oldMillis, nowMillis);
}
};
jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) {
this.scheduledFunctions[timeoutKey] = {
runAtMillis: this.nowMillis + millis,
funcToCall: funcToCall,
recurring: recurring,
timeoutKey: timeoutKey,
millis: millis
};
};
/**
* @namespace
*/
jasmine.Clock = {
defaultFakeTimer: new jasmine.FakeTimer(),
reset: function() {
jasmine.Clock.assertInstalled();
jasmine.Clock.defaultFakeTimer.reset();
},
tick: function(millis) {
jasmine.Clock.assertInstalled();
jasmine.Clock.defaultFakeTimer.tick(millis);
},
runFunctionsWithinRange: function(oldMillis, nowMillis) {
jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis);
},
scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) {
jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring);
},
useMock: function() {
if (!jasmine.Clock.isInstalled()) {
var spec = jasmine.getEnv().currentSpec;
spec.after(jasmine.Clock.uninstallMock);
jasmine.Clock.installMock();
}
},
installMock: function() {
jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer;
},
uninstallMock: function() {
jasmine.Clock.assertInstalled();
jasmine.Clock.installed = jasmine.Clock.real;
},
real: {
setTimeout: jasmine.getGlobal().setTimeout,
clearTimeout: jasmine.getGlobal().clearTimeout,
setInterval: jasmine.getGlobal().setInterval,
clearInterval: jasmine.getGlobal().clearInterval
},
assertInstalled: function() {
if (!jasmine.Clock.isInstalled()) {
throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()");
}
},
isInstalled: function() {
return jasmine.Clock.installed == jasmine.Clock.defaultFakeTimer;
},
installed: null
};
jasmine.Clock.installed = jasmine.Clock.real;
//else for IE support
jasmine.getGlobal().setTimeout = function(funcToCall, millis) {
if (jasmine.Clock.installed.setTimeout.apply) {
return jasmine.Clock.installed.setTimeout.apply(this, arguments);
} else {
return jasmine.Clock.installed.setTimeout(funcToCall, millis);
}
};
jasmine.getGlobal().setInterval = function(funcToCall, millis) {
if (jasmine.Clock.installed.setInterval.apply) {
return jasmine.Clock.installed.setInterval.apply(this, arguments);
} else {
return jasmine.Clock.installed.setInterval(funcToCall, millis);
}
};
jasmine.getGlobal().clearTimeout = function(timeoutKey) {
if (jasmine.Clock.installed.clearTimeout.apply) {
return jasmine.Clock.installed.clearTimeout.apply(this, arguments);
} else {
return jasmine.Clock.installed.clearTimeout(timeoutKey);
}
};
jasmine.getGlobal().clearInterval = function(timeoutKey) {
if (jasmine.Clock.installed.clearTimeout.apply) {
return jasmine.Clock.installed.clearInterval.apply(this, arguments);
} else {
return jasmine.Clock.installed.clearInterval(timeoutKey);
}
};
/**
* @constructor
*/
jasmine.MultiReporter = function() {
this.subReporters_ = [];
};
jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter);
jasmine.MultiReporter.prototype.addReporter = function(reporter) {
this.subReporters_.push(reporter);
};
(function() {
var functionNames = [
"reportRunnerStarting",
"reportRunnerResults",
"reportSuiteResults",
"reportSpecStarting",
"reportSpecResults",
"log"
];
for (var i = 0; i < functionNames.length; i++) {
var functionName = functionNames[i];
jasmine.MultiReporter.prototype[functionName] = (function(functionName) {
return function() {
for (var j = 0; j < this.subReporters_.length; j++) {
var subReporter = this.subReporters_[j];
if (subReporter[functionName]) {
subReporter[functionName].apply(subReporter, arguments);
}
}
};
})(functionName);
}
})();
/**
* Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults
*
* @constructor
*/
jasmine.NestedResults = function() {
/**
* The total count of results
*/
this.totalCount = 0;
/**
* Number of passed results
*/
this.passedCount = 0;
/**
* Number of failed results
*/
this.failedCount = 0;
/**
* Was this suite/spec skipped?
*/
this.skipped = false;
/**
* @ignore
*/
this.items_ = [];
};
/**
* Roll up the result counts.
*
* @param result
*/
jasmine.NestedResults.prototype.rollupCounts = function(result) {
this.totalCount += result.totalCount;
this.passedCount += result.passedCount;
this.failedCount += result.failedCount;
};
/**
* Adds a log message.
* @param values Array of message parts which will be concatenated later.
*/
jasmine.NestedResults.prototype.log = function(values) {
this.items_.push(new jasmine.MessageResult(values));
};
/**
* Getter for the results: message & results.
*/
jasmine.NestedResults.prototype.getItems = function() {
return this.items_;
};
/**
* Adds a result, tracking counts (total, passed, & failed)
* @param {jasmine.ExpectationResult|jasmine.NestedResults} result
*/
jasmine.NestedResults.prototype.addResult = function(result) {
if (result.type != 'log') {
if (result.items_) {
this.rollupCounts(result);
} else {
this.totalCount++;
if (result.passed()) {
this.passedCount++;
} else {
this.failedCount++;
}
}
}
this.items_.push(result);
};
/**
* @returns {Boolean} True if <b>everything</b> below passed
*/
jasmine.NestedResults.prototype.passed = function() {
return this.passedCount === this.totalCount;
};
/**
* Base class for pretty printing for expectation results.
*/
jasmine.PrettyPrinter = function() {
this.ppNestLevel_ = 0;
};
/**
* Formats a value in a nice, human-readable string.
*
* @param value
*/
jasmine.PrettyPrinter.prototype.format = function(value) {
this.ppNestLevel_++;
try {
if (value === jasmine.undefined) {
this.emitScalar('undefined');
} else if (value === null) {
this.emitScalar('null');
} else if (value === jasmine.getGlobal()) {
this.emitScalar('<global>');
} else if (value.jasmineToString) {
this.emitScalar(value.jasmineToString());
} else if (typeof value === 'string') {
this.emitString(value);
} else if (jasmine.isSpy(value)) {
this.emitScalar("spy on " + value.identity);
} else if (value instanceof RegExp) {
this.emitScalar(value.toString());
} else if (typeof value === 'function') {
this.emitScalar('Function');
} else if (typeof value.nodeType === 'number') {
this.emitScalar('HTMLNode');
} else if (value instanceof Date) {
this.emitScalar('Date(' + value + ')');
} else if (value.__Jasmine_been_here_before__) {
this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>');
} else if (jasmine.isArray_(value) || typeof value == 'object') {
value.__Jasmine_been_here_before__ = true;
if (jasmine.isArray_(value)) {
this.emitArray(value);
} else {
this.emitObject(value);
}
delete value.__Jasmine_been_here_before__;
} else {
this.emitScalar(value.toString());
}
} finally {
this.ppNestLevel_--;
}
};
jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) {
for (var property in obj) {
if (!obj.hasOwnProperty(property)) continue;
if (property == '__Jasmine_been_here_before__') continue;
fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) !== jasmine.undefined &&
obj.__lookupGetter__(property) !== null) : false);
}
};
jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_;
jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_;
jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_;
jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_;
jasmine.StringPrettyPrinter = function() {
jasmine.PrettyPrinter.call(this);
this.string = '';
};
jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter);
jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) {
this.append(value);
};
jasmine.StringPrettyPrinter.prototype.emitString = function(value) {
this.append("'" + value + "'");
};
jasmine.StringPrettyPrinter.prototype.emitArray = function(array) {
if (this.ppNestLevel_ > jasmine.MAX_PRETTY_PRINT_DEPTH) {
this.append("Array");
return;
}
this.append('[ ');
for (var i = 0; i < array.length; i++) {
if (i > 0) {
this.append(', ');
}
this.format(array[i]);
}
this.append(' ]');
};
jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) {
if (this.ppNestLevel_ > jasmine.MAX_PRETTY_PRINT_DEPTH) {
this.append("Object");
return;
}
var self = this;
this.append('{ ');
var first = true;
this.iterateObject(obj, function(property, isGetter) {
if (first) {
first = false;
} else {
self.append(', ');
}
self.append(property);
self.append(' : ');
if (isGetter) {
self.append('<getter>');
} else {
self.format(obj[property]);
}
});
this.append(' }');
};
jasmine.StringPrettyPrinter.prototype.append = function(value) {
this.string += value;
};
jasmine.Queue = function(env) {
this.env = env;
// parallel to blocks. each true value in this array means the block will
// get executed even if we abort
this.ensured = [];
this.blocks = [];
this.running = false;
this.index = 0;
this.offset = 0;
this.abort = false;
};
jasmine.Queue.prototype.addBefore = function(block, ensure) {
if (ensure === jasmine.undefined) {
ensure = false;
}
this.blocks.unshift(block);
this.ensured.unshift(ensure);
};
jasmine.Queue.prototype.add = function(block, ensure) {
if (ensure === jasmine.undefined) {
ensure = false;
}
this.blocks.push(block);
this.ensured.push(ensure);
};
jasmine.Queue.prototype.insertNext = function(block, ensure) {
if (ensure === jasmine.undefined) {
ensure = false;
}
this.ensured.splice((this.index + this.offset + 1), 0, ensure);
this.blocks.splice((this.index + this.offset + 1), 0, block);
this.offset++;
};
jasmine.Queue.prototype.start = function(onComplete) {
this.running = true;
this.onComplete = onComplete;
this.next_();
};
jasmine.Queue.prototype.isRunning = function() {
return this.running;
};
jasmine.Queue.LOOP_DONT_RECURSE = true;
jasmine.Queue.prototype.next_ = function() {
var self = this;
var goAgain = true;
while (goAgain) {
goAgain = false;
if (self.index < self.blocks.length && !(this.abort && !this.ensured[self.index])) {
var calledSynchronously = true;
var completedSynchronously = false;
var onComplete = function () {
if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) {
completedSynchronously = true;
return;
}
if (self.blocks[self.index].abort) {
self.abort = true;
}
self.offset = 0;
self.index++;
var now = new Date().getTime();
if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) {
self.env.lastUpdate = now;
self.env.setTimeout(function() {
self.next_();
}, 0);
} else {
if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) {
goAgain = true;
} else {
self.next_();
}
}
};
self.blocks[self.index].execute(onComplete);
calledSynchronously = false;
if (completedSynchronously) {
onComplete();
}
} else {
self.running = false;
if (self.onComplete) {
self.onComplete();
}
}
}
};
jasmine.Queue.prototype.results = function() {
var results = new jasmine.NestedResults();
for (var i = 0; i < this.blocks.length; i++) {
if (this.blocks[i].results) {
results.addResult(this.blocks[i].results());
}
}
return results;
};
/**
* Runner
*
* @constructor
* @param {jasmine.Env} env
*/
jasmine.Runner = function(env) {
var self = this;
self.env = env;
self.queue = new jasmine.Queue(env);
self.before_ = [];
self.after_ = [];
self.suites_ = [];
};
jasmine.Runner.prototype.execute = function() {
var self = this;
if (self.env.reporter.reportRunnerStarting) {
self.env.reporter.reportRunnerStarting(this);
}
self.queue.start(function () {
self.finishCallback();
});
};
jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) {
beforeEachFunction.typeName = 'beforeEach';
this.before_.splice(0,0,beforeEachFunction);
};
jasmine.Runner.prototype.afterEach = function(afterEachFunction) {
afterEachFunction.typeName = 'afterEach';
this.after_.splice(0,0,afterEachFunction);
};
jasmine.Runner.prototype.finishCallback = function() {
this.env.reporter.reportRunnerResults(this);
};
jasmine.Runner.prototype.addSuite = function(suite) {
this.suites_.push(suite);
};
jasmine.Runner.prototype.add = function(block) {
if (block instanceof jasmine.Suite) {
this.addSuite(block);
}
this.queue.add(block);
};
jasmine.Runner.prototype.specs = function () {
var suites = this.suites();
var specs = [];
for (var i = 0; i < suites.length; i++) {
specs = specs.concat(suites[i].specs());
}
return specs;
};
jasmine.Runner.prototype.suites = function() {
return this.suites_;
};
jasmine.Runner.prototype.topLevelSuites = function() {
var topLevelSuites = [];
for (var i = 0; i < this.suites_.length; i++) {
if (!this.suites_[i].parentSuite) {
topLevelSuites.push(this.suites_[i]);
}
}
return topLevelSuites;
};
jasmine.Runner.prototype.results = function() {
return this.queue.results();
};
/**
* Internal representation of a Jasmine specification, or test.
*
* @constructor
* @param {jasmine.Env} env
* @param {jasmine.Suite} suite
* @param {String} description
*/
jasmine.Spec = function(env, suite, description) {
if (!env) {
throw new Error('jasmine.Env() required');
}
if (!suite) {
throw new Error('jasmine.Suite() required');
}
var spec = this;
spec.id = env.nextSpecId ? env.nextSpecId() : null;
spec.env = env;
spec.suite = suite;
spec.description = description;
spec.queue = new jasmine.Queue(env);
spec.afterCallbacks = [];
spec.spies_ = [];
spec.results_ = new jasmine.NestedResults();
spec.results_.description = description;
spec.matchersClass = null;
};
jasmine.Spec.prototype.getFullName = function() {
return this.suite.getFullName() + ' ' + this.description + '.';
};
jasmine.Spec.prototype.results = function() {
return this.results_;
};
/**
* All parameters are pretty-printed and concatenated together, then written to the spec's output.
*
* Be careful not to leave calls to <code>jasmine.log</code> in production code.
*/
jasmine.Spec.prototype.log = function() {
return this.results_.log(arguments);
};
jasmine.Spec.prototype.runs = function (func) {
var block = new jasmine.Block(this.env, func, this);
this.addToQueue(block);
return this;
};
jasmine.Spec.prototype.addToQueue = function (block) {
if (this.queue.isRunning()) {
this.queue.insertNext(block);
} else {
this.queue.add(block);
}
};
/**
* @param {jasmine.ExpectationResult} result
*/
jasmine.Spec.prototype.addMatcherResult = function(result) {
this.results_.addResult(result);
};
jasmine.Spec.prototype.expect = function(actual) {
var positive = new (this.getMatchersClass_())(this.env, actual, this);
positive.not = new (this.getMatchersClass_())(this.env, actual, this, true);
return positive;
};
/**
* Waits a fixed time period before moving to the next block.
*
* @deprecated Use waitsFor() instead
* @param {Number} timeout milliseconds to wait
*/
jasmine.Spec.prototype.waits = function(timeout) {
var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this);
this.addToQueue(waitsFunc);
return this;
};
/**
* Waits for the latchFunction to return true before proceeding to the next block.
*
* @param {Function} latchFunction
* @param {String} optional_timeoutMessage
* @param {Number} optional_timeout
*/
jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
var latchFunction_ = null;
var optional_timeoutMessage_ = null;
var optional_timeout_ = null;
for (var i = 0; i < arguments.length; i++) {
var arg = arguments[i];
switch (typeof arg) {
case 'function':
latchFunction_ = arg;
break;
case 'string':
optional_timeoutMessage_ = arg;
break;
case 'number':
optional_timeout_ = arg;
break;
}
}
var waitsForFunc = new jasmine.WaitsForBlock(this.env, optional_timeout_, latchFunction_, optional_timeoutMessage_, this);
this.addToQueue(waitsForFunc);
return this;
};
jasmine.Spec.prototype.fail = function (e) {
var expectationResult = new jasmine.ExpectationResult({
passed: false,
message: e ? jasmine.util.formatException(e) : 'Exception',
trace: { stack: e.stack }
});
this.results_.addResult(expectationResult);
};
jasmine.Spec.prototype.getMatchersClass_ = function() {
return this.matchersClass || this.env.matchersClass;
};
jasmine.Spec.prototype.addMatchers = function(matchersPrototype) {
var parent = this.getMatchersClass_();
var newMatchersClass = function() {
parent.apply(this, arguments);
};
jasmine.util.inherit(newMatchersClass, parent);
jasmine.Matchers.wrapInto_(matchersPrototype, newMatchersClass);
this.matchersClass = newMatchersClass;
};
jasmine.Spec.prototype.finishCallback = function() {
this.env.reporter.reportSpecResults(this);
};
jasmine.Spec.prototype.finish = function(onComplete) {
this.removeAllSpies();
this.finishCallback();
if (onComplete) {
onComplete();
}
};
jasmine.Spec.prototype.after = function(doAfter) {
if (this.queue.isRunning()) {
this.queue.add(new jasmine.Block(this.env, doAfter, this), true);
} else {
this.afterCallbacks.unshift(doAfter);
}
};
jasmine.Spec.prototype.execute = function(onComplete) {
var spec = this;
if (!spec.env.specFilter(spec)) {
spec.results_.skipped = true;
spec.finish(onComplete);
return;
}
this.env.reporter.reportSpecStarting(this);
spec.env.currentSpec = spec;
spec.addBeforesAndAftersToQueue();
spec.queue.start(function () {
spec.finish(onComplete);
});
};
jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() {
var runner = this.env.currentRunner();
var i;
for (var suite = this.suite; suite; suite = suite.parentSuite) {
for (i = 0; i < suite.before_.length; i++) {
this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this));
}
}
for (i = 0; i < runner.before_.length; i++) {
this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this));
}
for (i = 0; i < this.afterCallbacks.length; i++) {
this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this), true);
}
for (suite = this.suite; suite; suite = suite.parentSuite) {
for (i = 0; i < suite.after_.length; i++) {
this.queue.add(new jasmine.Block(this.env, suite.after_[i], this), true);
}
}
for (i = 0; i < runner.after_.length; i++) {
this.queue.add(new jasmine.Block(this.env, runner.after_[i], this), true);
}
};
jasmine.Spec.prototype.explodes = function() {
throw 'explodes function should not have been called';
};
jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) {
if (obj == jasmine.undefined) {
throw "spyOn could not find an object to spy upon for " + methodName + "()";
}
if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) {
throw methodName + '() method does not exist';
}
if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) {
throw new Error(methodName + ' has already been spied upon');
}
var spyObj = jasmine.createSpy(methodName);
this.spies_.push(spyObj);
spyObj.baseObj = obj;
spyObj.methodName = methodName;
spyObj.originalValue = obj[methodName];
obj[methodName] = spyObj;
return spyObj;
};
jasmine.Spec.prototype.removeAllSpies = function() {
for (var i = 0; i < this.spies_.length; i++) {
var spy = this.spies_[i];
spy.baseObj[spy.methodName] = spy.originalValue;
}
this.spies_ = [];
};
/**
* Internal representation of a Jasmine suite.
*
* @constructor
* @param {jasmine.Env} env
* @param {String} description
* @param {Function} specDefinitions
* @param {jasmine.Suite} parentSuite
*/
jasmine.Suite = function(env, description, specDefinitions, parentSuite) {
var self = this;
self.id = env.nextSuiteId ? env.nextSuiteId() : null;
self.description = description;
self.queue = new jasmine.Queue(env);
self.parentSuite = parentSuite;
self.env = env;
self.before_ = [];
self.after_ = [];
self.children_ = [];
self.suites_ = [];
self.specs_ = [];
};
jasmine.Suite.prototype.getFullName = function() {
var fullName = this.description;
for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) {
fullName = parentSuite.description + ' ' + fullName;
}
return fullName;
};
jasmine.Suite.prototype.finish = function(onComplete) {
this.env.reporter.reportSuiteResults(this);
this.finished = true;
if (typeof(onComplete) == 'function') {
onComplete();
}
};
jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) {
beforeEachFunction.typeName = 'beforeEach';
this.before_.unshift(beforeEachFunction);
};
jasmine.Suite.prototype.afterEach = function(afterEachFunction) {
afterEachFunction.typeName = 'afterEach';
this.after_.unshift(afterEachFunction);
};
jasmine.Suite.prototype.results = function() {
return this.queue.results();
};
jasmine.Suite.prototype.add = function(suiteOrSpec) {
this.children_.push(suiteOrSpec);
if (suiteOrSpec instanceof jasmine.Suite) {
this.suites_.push(suiteOrSpec);
this.env.currentRunner().addSuite(suiteOrSpec);
} else {
this.specs_.push(suiteOrSpec);
}
this.queue.add(suiteOrSpec);
};
jasmine.Suite.prototype.specs = function() {
return this.specs_;
};
jasmine.Suite.prototype.suites = function() {
return this.suites_;
};
jasmine.Suite.prototype.children = function() {
return this.children_;
};
jasmine.Suite.prototype.execute = function(onComplete) {
var self = this;
this.queue.start(function () {
self.finish(onComplete);
});
};
jasmine.WaitsBlock = function(env, timeout, spec) {
this.timeout = timeout;
jasmine.Block.call(this, env, null, spec);
};
jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block);
jasmine.WaitsBlock.prototype.execute = function (onComplete) {
if (jasmine.VERBOSE) {
this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...');
}
this.env.setTimeout(function () {
onComplete();
}, this.timeout);
};
/**
* A block which waits for some condition to become true, with timeout.
*
* @constructor
* @extends jasmine.Block
* @param {jasmine.Env} env The Jasmine environment.
* @param {Number} timeout The maximum time in milliseconds to wait for the condition to become true.
* @param {Function} latchFunction A function which returns true when the desired condition has been met.
* @param {String} message The message to display if the desired condition hasn't been met within the given time period.
* @param {jasmine.Spec} spec The Jasmine spec.
*/
jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) {
this.timeout = timeout || env.defaultTimeoutInterval;
this.latchFunction = latchFunction;
this.message = message;
this.totalTimeSpentWaitingForLatch = 0;
jasmine.Block.call(this, env, null, spec);
};
jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10;
jasmine.WaitsForBlock.prototype.execute = function(onComplete) {
if (jasmine.VERBOSE) {
this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen'));
}
var latchFunctionResult;
try {
latchFunctionResult = this.latchFunction.apply(this.spec);
} catch (e) {
this.spec.fail(e);
onComplete();
return;
}
if (latchFunctionResult) {
onComplete();
} else if (this.totalTimeSpentWaitingForLatch >= this.timeout) {
var message = 'timed out after ' + this.timeout + ' msec waiting for ' + (this.message || 'something to happen');
this.spec.fail({
name: 'timeout',
message: message
});
this.abort = true;
onComplete();
} else {
this.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
var self = this;
this.env.setTimeout(function() {
self.execute(onComplete);
}, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
}
};
jasmine.version_= {
"major": 1,
"minor": 3,
"build": 1,
"revision": 1354556913
};
});
require.define("/spec/lib/jasmine-html.js",function(require,module,exports,__dirname,__filename,process,global){jasmine.HtmlReporterHelpers = {};
jasmine.HtmlReporterHelpers.createDom = function(type, attrs, childrenVarArgs) {
var el = document.createElement(type);
for (var i = 2; i < arguments.length; i++) {
var child = arguments[i];
if (typeof child === 'string') {
el.appendChild(document.createTextNode(child));
} else {
if (child) {
el.appendChild(child);
}
}
}
for (var attr in attrs) {
if (attr == "className") {
el[attr] = attrs[attr];
} else {
el.setAttribute(attr, attrs[attr]);
}
}
return el;
};
jasmine.HtmlReporterHelpers.getSpecStatus = function(child) {
var results = child.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.skipped) {
status = 'skipped';
}
return status;
};
jasmine.HtmlReporterHelpers.appendToSummary = function(child, childElement) {
var parentDiv = this.dom.summary;
var parentSuite = (typeof child.parentSuite == 'undefined') ? 'suite' : 'parentSuite';
var parent = child[parentSuite];
if (parent) {
if (typeof this.views.suites[parent.id] == 'undefined') {
this.views.suites[parent.id] = new jasmine.HtmlReporter.SuiteView(parent, this.dom, this.views);
}
parentDiv = this.views.suites[parent.id].element;
}
parentDiv.appendChild(childElement);
};
jasmine.HtmlReporterHelpers.addHelpers = function(ctor) {
for(var fn in jasmine.HtmlReporterHelpers) {
ctor.prototype[fn] = jasmine.HtmlReporterHelpers[fn];
}
};
jasmine.HtmlReporter = function(_doc) {
var self = this;
var doc = _doc || window.document;
var reporterView;
var dom = {};
// Jasmine Reporter Public Interface
self.logRunningSpecs = false;
self.reportRunnerStarting = function(runner) {
var specs = runner.specs() || [];
if (specs.length == 0) {
return;
}
createReporterDom(runner.env.versionString());
doc.body.appendChild(dom.reporter);
setExceptionHandling();
reporterView = new jasmine.HtmlReporter.ReporterView(dom);
reporterView.addSpecs(specs, self.specFilter);
};
self.reportRunnerResults = function(runner) {
reporterView && reporterView.complete();
};
self.reportSuiteResults = function(suite) {
reporterView.suiteComplete(suite);
};
self.reportSpecStarting = function(spec) {
if (self.logRunningSpecs) {
self.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
}
};
self.reportSpecResults = function(spec) {
reporterView.specComplete(spec);
};
self.log = function() {
var console = jasmine.getGlobal().console;
if (console && console.log) {
if (console.log.apply) {
console.log.apply(console, arguments);
} else {
console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
}
}
};
self.specFilter = function(spec) {
if (!focusedSpecName()) {
return true;
}
return spec.getFullName().indexOf(focusedSpecName()) === 0;
};
return self;
function focusedSpecName() {
var specName;
(function memoizeFocusedSpec() {
if (specName) {
return;
}
var paramMap = [];
var params = jasmine.HtmlReporter.parameters(doc);
for (var i = 0; i < params.length; i++) {
var p = params[i].split('=');
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
}
specName = paramMap.spec;
})();
return specName;
}
function createReporterDom(version) {
dom.reporter = self.createDom('div', { id: 'HTMLReporter', className: 'jasmine_reporter' },
dom.banner = self.createDom('div', { className: 'banner' },
self.createDom('span', { className: 'title' }, "Jasmine "),
self.createDom('span', { className: 'version' }, version)),
dom.symbolSummary = self.createDom('ul', {className: 'symbolSummary'}),
dom.alert = self.createDom('div', {className: 'alert'},
self.createDom('span', { className: 'exceptions' },
self.createDom('label', { className: 'label', 'for': 'no_try_catch' }, 'No try/catch'),
self.createDom('input', { id: 'no_try_catch', type: 'checkbox' }))),
dom.results = self.createDom('div', {className: 'results'},
dom.summary = self.createDom('div', { className: 'summary' }),
dom.details = self.createDom('div', { id: 'details' }))
);
}
function noTryCatch() {
return window.location.search.match(/catch=false/);
}
function searchWithCatch() {
var params = jasmine.HtmlReporter.parameters(window.document);
var removed = false;
var i = 0;
while (!removed && i < params.length) {
if (params[i].match(/catch=/)) {
params.splice(i, 1);
removed = true;
}
i++;
}
if (jasmine.CATCH_EXCEPTIONS) {
params.push("catch=false");
}
return params.join("&");
}
function setExceptionHandling() {
var chxCatch = document.getElementById('no_try_catch');
if (noTryCatch()) {
chxCatch.setAttribute('checked', true);
jasmine.CATCH_EXCEPTIONS = false;
}
chxCatch.onclick = function() {
window.location.search = searchWithCatch();
};
}
};
jasmine.HtmlReporter.parameters = function(doc) {
var paramStr = doc.location.search.substring(1);
var params = [];
if (paramStr.length > 0) {
params = paramStr.split('&');
}
return params;
}
jasmine.HtmlReporter.sectionLink = function(sectionName) {
var link = '?';
var params = [];
if (sectionName) {
params.push('spec=' + encodeURIComponent(sectionName));
}
if (!jasmine.CATCH_EXCEPTIONS) {
params.push("catch=false");
}
if (params.length > 0) {
link += params.join("&");
}
return link;
};
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter);
jasmine.HtmlReporter.ReporterView = function(dom) {
this.startedAt = new Date();
this.runningSpecCount = 0;
this.completeSpecCount = 0;
this.passedCount = 0;
this.failedCount = 0;
this.skippedCount = 0;
this.createResultsMenu = function() {
this.resultsMenu = this.createDom('span', {className: 'resultsMenu bar'},
this.summaryMenuItem = this.createDom('a', {className: 'summaryMenuItem', href: "#"}, '0 specs'),
' | ',
this.detailsMenuItem = this.createDom('a', {className: 'detailsMenuItem', href: "#"}, '0 failing'));
this.summaryMenuItem.onclick = function() {
dom.reporter.className = dom.reporter.className.replace(/ showDetails/g, '');
};
this.detailsMenuItem.onclick = function() {
showDetails();
};
};
this.addSpecs = function(specs, specFilter) {
this.totalSpecCount = specs.length;
this.views = {
specs: {},
suites: {}
};
for (var i = 0; i < specs.length; i++) {
var spec = specs[i];
this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom, this.views);
if (specFilter(spec)) {
this.runningSpecCount++;
}
}
};
this.specComplete = function(spec) {
this.completeSpecCount++;
if (isUndefined(this.views.specs[spec.id])) {
this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom);
}
var specView = this.views.specs[spec.id];
switch (specView.status()) {
case 'passed':
this.passedCount++;
break;
case 'failed':
this.failedCount++;
break;
case 'skipped':
this.skippedCount++;
break;
}
specView.refresh();
this.refresh();
};
this.suiteComplete = function(suite) {
var suiteView = this.views.suites[suite.id];
if (isUndefined(suiteView)) {
return;
}
suiteView.refresh();
};
this.refresh = function() {
if (isUndefined(this.resultsMenu)) {
this.createResultsMenu();
}
// currently running UI
if (isUndefined(this.runningAlert)) {
this.runningAlert = this.createDom('a', { href: jasmine.HtmlReporter.sectionLink(), className: "runningAlert bar" });
dom.alert.appendChild(this.runningAlert);
}
this.runningAlert.innerHTML = "Running " + this.completeSpecCount + " of " + specPluralizedFor(this.totalSpecCount);
// skipped specs UI
if (isUndefined(this.skippedAlert)) {
this.skippedAlert = this.createDom('a', { href: jasmine.HtmlReporter.sectionLink(), className: "skippedAlert bar" });
}
this.skippedAlert.innerHTML = "Skipping " + this.skippedCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
if (this.skippedCount === 1 && isDefined(dom.alert)) {
dom.alert.appendChild(this.skippedAlert);
}
// passing specs UI
if (isUndefined(this.passedAlert)) {
this.passedAlert = this.createDom('span', { href: jasmine.HtmlReporter.sectionLink(), className: "passingAlert bar" });
}
this.passedAlert.innerHTML = "Passing " + specPluralizedFor(this.passedCount);
// failing specs UI
if (isUndefined(this.failedAlert)) {
this.failedAlert = this.createDom('span', {href: "?", className: "failingAlert bar"});
}
this.failedAlert.innerHTML = "Failing " + specPluralizedFor(this.failedCount);
if (this.failedCount === 1 && isDefined(dom.alert)) {
dom.alert.appendChild(this.failedAlert);
dom.alert.appendChild(this.resultsMenu);
}
// summary info
this.summaryMenuItem.innerHTML = "" + specPluralizedFor(this.runningSpecCount);
this.detailsMenuItem.innerHTML = "" + this.failedCount + " failing";
};
this.complete = function() {
dom.alert.removeChild(this.runningAlert);
this.skippedAlert.innerHTML = "Ran " + this.runningSpecCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
if (this.failedCount === 0) {
dom.alert.appendChild(this.createDom('span', {className: 'passingAlert bar'}, "Passing " + specPluralizedFor(this.passedCount)));
} else {
showDetails();
}
dom.banner.appendChild(this.createDom('span', {className: 'duration'}, "finished in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s"));
};
return this;
function showDetails() {
if (dom.reporter.className.search(/showDetails/) === -1) {
dom.reporter.className += " showDetails";
}
}
function isUndefined(obj) {
return typeof obj === 'undefined';
}
function isDefined(obj) {
return !isUndefined(obj);
}
function specPluralizedFor(count) {
var str = count + " spec";
if (count > 1) {
str += "s"
}
return str;
}
};
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.ReporterView);
jasmine.HtmlReporter.SpecView = function(spec, dom, views) {
this.spec = spec;
this.dom = dom;
this.views = views;
this.symbol = this.createDom('li', { className: 'pending' });
this.dom.symbolSummary.appendChild(this.symbol);
this.summary = this.createDom('div', { className: 'specSummary' },
this.createDom('a', {
className: 'description',
href: jasmine.HtmlReporter.sectionLink(this.spec.getFullName()),
title: this.spec.getFullName()
}, this.spec.description)
);
this.detail = this.createDom('div', { className: 'specDetail' },
this.createDom('a', {
className: 'description',
href: '?spec=' + encodeURIComponent(this.spec.getFullName()),
title: this.spec.getFullName()
}, this.spec.getFullName())
);
};
jasmine.HtmlReporter.SpecView.prototype.status = function() {
return this.getSpecStatus(this.spec);
};
jasmine.HtmlReporter.SpecView.prototype.refresh = function() {
this.symbol.className = this.status();
switch (this.status()) {
case 'skipped':
break;
case 'passed':
this.appendSummaryToSuiteDiv();
break;
case 'failed':
this.appendSummaryToSuiteDiv();
this.appendFailureDetail();
break;
}
};
jasmine.HtmlReporter.SpecView.prototype.appendSummaryToSuiteDiv = function() {
this.summary.className += ' ' + this.status();
this.appendToSummary(this.spec, this.summary);
};
jasmine.HtmlReporter.SpecView.prototype.appendFailureDetail = function() {
this.detail.className += ' ' + this.status();
var resultItems = this.spec.results().getItems();
var messagesDiv = this.createDom('div', { className: 'messages' });
for (var i = 0; i < resultItems.length; i++) {
var result = resultItems[i];
if (result.type == 'log') {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
} else if (result.type == 'expect' && result.passed && !result.passed()) {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
if (result.trace.stack) {
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
}
}
}
if (messagesDiv.childNodes.length > 0) {
this.detail.appendChild(messagesDiv);
this.dom.details.appendChild(this.detail);
}
};
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SpecView);jasmine.HtmlReporter.SuiteView = function(suite, dom, views) {
this.suite = suite;
this.dom = dom;
this.views = views;
this.element = this.createDom('div', { className: 'suite' },
this.createDom('a', { className: 'description', href: jasmine.HtmlReporter.sectionLink(this.suite.getFullName()) }, this.suite.description)
);
this.appendToSummary(this.suite, this.element);
};
jasmine.HtmlReporter.SuiteView.prototype.status = function() {
return this.getSpecStatus(this.suite);
};
jasmine.HtmlReporter.SuiteView.prototype.refresh = function() {
this.element.className += " " + this.status();
};
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SuiteView);
/* @deprecated Use jasmine.HtmlReporter instead
*/
jasmine.TrivialReporter = function(doc) {
this.document = doc || document;
this.suiteDivs = {};
this.logRunningSpecs = false;
};
jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
var el = document.createElement(type);
for (var i = 2; i < arguments.length; i++) {
var child = arguments[i];
if (typeof child === 'string') {
el.appendChild(document.createTextNode(child));
} else {
if (child) { el.appendChild(child); }
}
}
for (var attr in attrs) {
if (attr == "className") {
el[attr] = attrs[attr];
} else {
el.setAttribute(attr, attrs[attr]);
}
}
return el;
};
jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
var showPassed, showSkipped;
this.outerDiv = this.createDom('div', { id: 'TrivialReporter', className: 'jasmine_reporter' },
this.createDom('div', { className: 'banner' },
this.createDom('div', { className: 'logo' },
this.createDom('span', { className: 'title' }, "Jasmine"),
this.createDom('span', { className: 'version' }, runner.env.versionString())),
this.createDom('div', { className: 'options' },
"Show ",
showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
)
),
this.runnerDiv = this.createDom('div', { className: 'runner running' },
this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
);
this.document.body.appendChild(this.outerDiv);
var suites = runner.suites();
for (var i = 0; i < suites.length; i++) {
var suite = suites[i];
var suiteDiv = this.createDom('div', { className: 'suite' },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
this.suiteDivs[suite.id] = suiteDiv;
var parentDiv = this.outerDiv;
if (suite.parentSuite) {
parentDiv = this.suiteDivs[suite.parentSuite.id];
}
parentDiv.appendChild(suiteDiv);
}
this.startedAt = new Date();
var self = this;
showPassed.onclick = function(evt) {
if (showPassed.checked) {
self.outerDiv.className += ' show-passed';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
}
};
showSkipped.onclick = function(evt) {
if (showSkipped.checked) {
self.outerDiv.className += ' show-skipped';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
}
};
};
jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
var results = runner.results();
var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
this.runnerDiv.setAttribute("class", className);
//do it twice for IE
this.runnerDiv.setAttribute("className", className);
var specs = runner.specs();
var specCount = 0;
for (var i = 0; i < specs.length; i++) {
if (this.specFilter(specs[i])) {
specCount++;
}
}
var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
};
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
var results = suite.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.totalCount === 0) { // todo: change this to check results.skipped
status = 'skipped';
}
this.suiteDivs[suite.id].className += " " + status;
};
jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
if (this.logRunningSpecs) {
this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
}
};
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
var results = spec.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.skipped) {
status = 'skipped';
}
var specDiv = this.createDom('div', { className: 'spec ' + status },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
this.createDom('a', {
className: 'description',
href: '?spec=' + encodeURIComponent(spec.getFullName()),
title: spec.getFullName()
}, spec.description));
var resultItems = results.getItems();
var messagesDiv = this.createDom('div', { className: 'messages' });
for (var i = 0; i < resultItems.length; i++) {
var result = resultItems[i];
if (result.type == 'log') {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
} else if (result.type == 'expect' && result.passed && !result.passed()) {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
if (result.trace.stack) {
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
}
}
}
if (messagesDiv.childNodes.length > 0) {
specDiv.appendChild(messagesDiv);
}
this.suiteDivs[spec.suite.id].appendChild(specDiv);
};
jasmine.TrivialReporter.prototype.log = function() {
var console = jasmine.getGlobal().console;
if (console && console.log) {
if (console.log.apply) {
console.log.apply(console, arguments);
} else {
console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
}
}
};
jasmine.TrivialReporter.prototype.getLocation = function() {
return this.document.location;
};
jasmine.TrivialReporter.prototype.specFilter = function(spec) {
var paramMap = {};
var params = this.getLocation().search.substring(1).split('&');
for (var i = 0; i < params.length; i++) {
var p = params[i].split('=');
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
}
if (!paramMap.spec) {
return true;
}
return spec.getFullName().indexOf(paramMap.spec) === 0;
};
});
require.define("/spec/lib/jasmine.tap_reporter.js",function(require,module,exports,__dirname,__filename,process,global){(function() {
if (! jasmine) {
throw new Exception("jasmine library does not exist in global namespace!");
}
/**
* TAP (http://en.wikipedia.org/wiki/Test_Anything_Protocol) reporter.
* outputs spec results to the console.
*
* Heavily inspired by ConsoleReporter found at:
* https://github.com/larrymyers/jasmine-reporters/
*
* Usage:
*
* jasmine.getEnv().addReporter(new jasmine.TapReporter());
* jasmine.getEnv().execute();
*/
var TapReporter = function() {
this.started = false;
this.finished = false;
};
TapReporter.prototype = {
reportRunnerStarting: function(runner) {
this.started = true;
this.start_time = (new Date()).getTime();
this.executed_specs = 0;
this.passed_specs = 0;
this.executed_asserts = 0;
this.passed_asserts = 0;
// should have at least 1 spec, otherwise it's considered a failure
this.log('1..'+ Math.max(runner.specs().length, 1));
},
reportSpecStarting: function(spec) {
this.executed_specs++;
},
reportSpecResults: function(spec) {
var resultText = "not ok";
var errorMessage = '';
var results = spec.results();
var passed = results.passed();
this.passed_asserts += results.passedCount;
this.executed_asserts += results.totalCount;
if (passed) {
this.passed_specs++;
resultText = "ok";
} else {
var items = results.getItems();
var i = 0;
var expectationResult, stackMessage;
while (expectationResult = items[i++]) {
if (expectationResult.trace) {
stackMessage = expectationResult.trace.stack? expectationResult.trace.stack : expectationResult.message;
errorMessage += '\n '+ stackMessage;
}
}
}
this.log(resultText +" "+ (spec.id + 1) +" - "+ spec.suite.description +" : "+ spec.description + errorMessage);
},
reportRunnerResults: function(runner) {
var dur = (new Date()).getTime() - this.start_time;
var failed = this.executed_specs - this.passed_specs;
var spec_str = this.executed_specs + (this.executed_specs === 1 ? " spec, " : " specs, ");
var fail_str = failed + (failed === 1 ? " failure in " : " failures in ");
var assert_str = this.executed_asserts + (this.executed_asserts === 1 ? " assertion, " : " assertions, ");
if (this.executed_asserts) {
this.log("# "+ spec_str + assert_str + fail_str + (dur/1000) + "s.");
} else {
this.log('not ok 1 - no asserts run.');
}
this.finished = true;
},
log: function(str) {
var console = jasmine.getGlobal().console;
if (console && console.log) {
console.log(str);
}
}
};
// export public
jasmine.TapReporter = TapReporter;
})();
});
require.define("/spec/SpecHelper.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
var Bacon, browser, hasValue, justValues, lastNonError, seqs, timeUnitMillisecs, toValue, toValues, verifyCleanup, verifyExhausted, verifyFinalState, verifySingleSubscriber, verifySwitching, _;
Bacon = (require("../src/Bacon")).Bacon;
_ = Bacon._;
browser = (typeof window) !== "undefined";
if (browser) {
console.log("in browser");
}
timeUnitMillisecs = browser ? 50 : 10;
this.t = function(time) {
return time * timeUnitMillisecs;
};
seqs = [];
this.error = function(msg) {
return new Bacon.Error(msg);
};
this.soon = function(f) {
return setTimeout(f, t(1));
};
this.series = function(interval, values) {
return Bacon.sequentially(t(interval), values);
};
this.repeat = function(interval, values) {
var source;
source = Bacon.repeatedly(t(interval), values);
seqs.push({
values: values,
source: source
});
return source;
};
this.atGivenTimes = function(timesAndValues) {
var streams, tv;
streams = (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = timesAndValues.length; _i < _len; _i++) {
tv = timesAndValues[_i];
_results.push(Bacon.later(t(tv[0]), tv[1]));
}
return _results;
})();
return Bacon.mergeAll(streams);
};
this.expectStreamTimings = function(src, expectedEventsAndTimings) {
var srcWithRelativeTime;
srcWithRelativeTime = function() {
var now, relativeTime, t0, withRelativeTime;
now = function() {
return new Date().getTime();
};
t0 = now();
relativeTime = function() {
return Math.floor((now() - t0 + 1) / timeUnitMillisecs);
};
withRelativeTime = function(x) {
return [relativeTime(), x];
};
return src().map(withRelativeTime);
};
return this.expectStreamEvents(srcWithRelativeTime, expectedEventsAndTimings);
};
this.expectStreamEvents = function(src, expectedEvents) {
runs(function() {
return verifySingleSubscriber(src(), expectedEvents);
});
return runs(function() {
return verifySwitching(src(), expectedEvents);
});
};
this.expectPropertyEvents = function(src, expectedEvents) {
var ended, events, events2, property, streamEnded;
expect(expectedEvents.length > 0).toEqual(true);
events = [];
events2 = [];
ended = false;
streamEnded = function() {
return ended;
};
property = src();
expect(property instanceof Bacon.Property).toEqual(true);
runs(function() {
return property.subscribe(function(event) {
if (event.isEnd()) {
return ended = true;
} else {
events.push(toValue(event));
if (event.hasValue()) {
return property.subscribe(function(event) {
if (event.isInitial()) {
events2.push(event.value());
}
return Bacon.noMore;
});
}
}
});
});
waitsFor(streamEnded, t(50));
return runs(function() {
expect(events).toEqual(toValues(expectedEvents));
expect(events2).toEqual(justValues(expectedEvents));
verifyFinalState(property, lastNonError(expectedEvents));
return verifyCleanup();
});
};
verifySingleSubscriber = function(src, expectedEvents) {
var ended, events, streamEnded;
expect(src instanceof Bacon.EventStream).toEqual(true);
events = [];
ended = false;
streamEnded = function() {
return ended;
};
runs(function() {
return src.subscribe(function(event) {
if (event.isEnd()) {
return ended = true;
} else {
expect(event instanceof Bacon.Initial).toEqual(false);
return events.push(toValue(event));
}
});
});
waitsFor(streamEnded, t(50));
return runs(function() {
expect(events).toEqual(toValues(expectedEvents));
verifyExhausted(src);
return verifyCleanup();
});
};
verifySwitching = function(src, expectedEvents) {
var ended, events, newSink, streamEnded;
events = [];
ended = false;
streamEnded = function() {
return ended;
};
newSink = function() {
return function(event) {
if (event.isEnd()) {
return ended = true;
} else {
expect(event instanceof Bacon.Initial).toEqual(false);
events.push(toValue(event));
src.subscribe(newSink());
return Bacon.noMore;
}
};
};
runs(function() {
return src.subscribe(newSink());
});
waitsFor(streamEnded, t(50));
return runs(function() {
expect(events).toEqual(toValues(expectedEvents));
verifyExhausted(src);
return verifyCleanup();
});
};
verifyExhausted = function(src) {
var events;
events = [];
src.subscribe(function(event) {
return events.push(event);
});
return expect(events[0].isEnd()).toEqual(true);
};
lastNonError = function(events) {
return _.last(_.filter((function(e) {
return toValue(e) !== "<error>";
}), events));
};
verifyFinalState = function(property, value) {
var events;
events = [];
property.subscribe(function(event) {
return events.push(event);
});
return expect(toValues(events)).toEqual(toValues([value, "<end>"]));
};
verifyCleanup = this.verifyCleanup = function() {
var seq, _i, _len;
for (_i = 0, _len = seqs.length; _i < _len; _i++) {
seq = seqs[_i];
expect(seq.source.hasSubscribers()).toEqual(false);
}
return seqs = [];
};
toValues = function(xs) {
var values, x, _i, _len;
values = [];
for (_i = 0, _len = xs.length; _i < _len; _i++) {
x = xs[_i];
values.push(toValue(x));
}
return values;
};
toValue = function(x) {
if ((x != null) && (x.isEvent != null)) {
if (x.isError()) {
return "<error>";
} else if (x.isEnd()) {
return "<end>";
} else {
return x.value();
}
} else {
return x;
}
};
justValues = function(xs) {
return _.filter(hasValue, xs);
};
hasValue = function(x) {
return toValue(x) !== "<error>";
};
this.toValues = toValues;
}).call(this);
});
require.define("/src/Bacon.js",function(require,module,exports,__dirname,__filename,process,global){if (typeof _$jscoverage === 'undefined') _$jscoverage = {};
if ((typeof global !== 'undefined') && (typeof global._$jscoverage === 'undefined')) {
global._$jscoverage = _$jscoverage
} else if ((typeof window !== 'undefined') && (typeof window._$jscoverage === 'undefined')) {
window._$jscoverage = _$jscoverage
}
if (! _$jscoverage["Bacon.coffee"]) {
_$jscoverage["Bacon.coffee"] = [];
_$jscoverage["Bacon.coffee"][1] = 0;
_$jscoverage["Bacon.coffee"][2] = 0;
_$jscoverage["Bacon.coffee"][3] = 0;
_$jscoverage["Bacon.coffee"][4] = 0;
_$jscoverage["Bacon.coffee"][5] = 0;
_$jscoverage["Bacon.coffee"][6] = 0;
_$jscoverage["Bacon.coffee"][7] = 0;
_$jscoverage["Bacon.coffee"][8] = 0;
_$jscoverage["Bacon.coffee"][9] = 0;
_$jscoverage["Bacon.coffee"][10] = 0;
_$jscoverage["Bacon.coffee"][11] = 0;
_$jscoverage["Bacon.coffee"][12] = 0;
_$jscoverage["Bacon.coffee"][13] = 0;
_$jscoverage["Bacon.coffee"][15] = 0;
_$jscoverage["Bacon.coffee"][17] = 0;
_$jscoverage["Bacon.coffee"][18] = 0;
_$jscoverage["Bacon.coffee"][20] = 0;
_$jscoverage["Bacon.coffee"][21] = 0;
_$jscoverage["Bacon.coffee"][22] = 0;
_$jscoverage["Bacon.coffee"][23] = 0;
_$jscoverage["Bacon.coffee"][24] = 0;
_$jscoverage["Bacon.coffee"][25] = 0;
_$jscoverage["Bacon.coffee"][26] = 0;
_$jscoverage["Bacon.coffee"][27] = 0;
_$jscoverage["Bacon.coffee"][30] = 0;
_$jscoverage["Bacon.coffee"][32] = 0;
_$jscoverage["Bacon.coffee"][34] = 0;
_$jscoverage["Bacon.coffee"][35] = 0;
_$jscoverage["Bacon.coffee"][37] = 0;
_$jscoverage["Bacon.coffee"][38] = 0;
_$jscoverage["Bacon.coffee"][39] = 0;
_$jscoverage["Bacon.coffee"][40] = 0;
_$jscoverage["Bacon.coffee"][41] = 0;
_$jscoverage["Bacon.coffee"][42] = 0;
_$jscoverage["Bacon.coffee"][43] = 0;
_$jscoverage["Bacon.coffee"][45] = 0;
_$jscoverage["Bacon.coffee"][46] = 0;
_$jscoverage["Bacon.coffee"][48] = 0;
_$jscoverage["Bacon.coffee"][49] = 0;
_$jscoverage["Bacon.coffee"][50] = 0;
_$jscoverage["Bacon.coffee"][51] = 0;
_$jscoverage["Bacon.coffee"][52] = 0;
_$jscoverage["Bacon.coffee"][53] = 0;
_$jscoverage["Bacon.coffee"][55] = 0;
_$jscoverage["Bacon.coffee"][56] = 0;
_$jscoverage["Bacon.coffee"][57] = 0;
_$jscoverage["Bacon.coffee"][58] = 0;
_$jscoverage["Bacon.coffee"][59] = 0;
_$jscoverage["Bacon.coffee"][60] = 0;
_$jscoverage["Bacon.coffee"][61] = 0;
_$jscoverage["Bacon.coffee"][62] = 0;
_$jscoverage["Bacon.coffee"][64] = 0;
_$jscoverage["Bacon.coffee"][65] = 0;
_$jscoverage["Bacon.coffee"][66] = 0;
_$jscoverage["Bacon.coffee"][67] = 0;
_$jscoverage["Bacon.coffee"][68] = 0;
_$jscoverage["Bacon.coffee"][69] = 0;
_$jscoverage["Bacon.coffee"][70] = 0;
_$jscoverage["Bacon.coffee"][71] = 0;
_$jscoverage["Bacon.coffee"][72] = 0;
_$jscoverage["Bacon.coffee"][73] = 0;
_$jscoverage["Bacon.coffee"][74] = 0;
_$jscoverage["Bacon.coffee"][75] = 0;
_$jscoverage["Bacon.coffee"][76] = 0;
_$jscoverage["Bacon.coffee"][93] = 0;
_$jscoverage["Bacon.coffee"][94] = 0;
_$jscoverage["Bacon.coffee"][95] = 0;
_$jscoverage["Bacon.coffee"][96] = 0;
_$jscoverage["Bacon.coffee"][97] = 0;
_$jscoverage["Bacon.coffee"][98] = 0;
_$jscoverage["Bacon.coffee"][100] = 0;
_$jscoverage["Bacon.coffee"][101] = 0;
_$jscoverage["Bacon.coffee"][102] = 0;
_$jscoverage["Bacon.coffee"][104] = 0;
_$jscoverage["Bacon.coffee"][105] = 0;
_$jscoverage["Bacon.coffee"][106] = 0;
_$jscoverage["Bacon.coffee"][108] = 0;
_$jscoverage["Bacon.coffee"][109] = 0;
_$jscoverage["Bacon.coffee"][110] = 0;
_$jscoverage["Bacon.coffee"][111] = 0;
_$jscoverage["Bacon.coffee"][113] = 0;
_$jscoverage["Bacon.coffee"][114] = 0;
_$jscoverage["Bacon.coffee"][116] = 0;
_$jscoverage["Bacon.coffee"][118] = 0;
_$jscoverage["Bacon.coffee"][120] = 0;
_$jscoverage["Bacon.coffee"][121] = 0;
_$jscoverage["Bacon.coffee"][123] = 0;
_$jscoverage["Bacon.coffee"][124] = 0;
_$jscoverage["Bacon.coffee"][125] = 0;
_$jscoverage["Bacon.coffee"][126] = 0;
_$jscoverage["Bacon.coffee"][127] = 0;
_$jscoverage["Bacon.coffee"][128] = 0;
_$jscoverage["Bacon.coffee"][130] = 0;
_$jscoverage["Bacon.coffee"][131] = 0;
_$jscoverage["Bacon.coffee"][132] = 0;
_$jscoverage["Bacon.coffee"][133] = 0;
_$jscoverage["Bacon.coffee"][134] = 0;
_$jscoverage["Bacon.coffee"][135] = 0;
_$jscoverage["Bacon.coffee"][137] = 0;
_$jscoverage["Bacon.coffee"][138] = 0;
_$jscoverage["Bacon.coffee"][140] = 0;
_$jscoverage["Bacon.coffee"][141] = 0;
_$jscoverage["Bacon.coffee"][142] = 0;
_$jscoverage["Bacon.coffee"][143] = 0;
_$jscoverage["Bacon.coffee"][144] = 0;
_$jscoverage["Bacon.coffee"][145] = 0;
_$jscoverage["Bacon.coffee"][146] = 0;
_$jscoverage["Bacon.coffee"][147] = 0;
_$jscoverage["Bacon.coffee"][149] = 0;
_$jscoverage["Bacon.coffee"][151] = 0;
_$jscoverage["Bacon.coffee"][152] = 0;
_$jscoverage["Bacon.coffee"][153] = 0;
_$jscoverage["Bacon.coffee"][155] = 0;
_$jscoverage["Bacon.coffee"][156] = 0;
_$jscoverage["Bacon.coffee"][157] = 0;
_$jscoverage["Bacon.coffee"][158] = 0;
_$jscoverage["Bacon.coffee"][159] = 0;
_$jscoverage["Bacon.coffee"][160] = 0;
_$jscoverage["Bacon.coffee"][161] = 0;
_$jscoverage["Bacon.coffee"][162] = 0;
_$jscoverage["Bacon.coffee"][163] = 0;
_$jscoverage["Bacon.coffee"][164] = 0;
_$jscoverage["Bacon.coffee"][165] = 0;
_$jscoverage["Bacon.coffee"][166] = 0;
_$jscoverage["Bacon.coffee"][167] = 0;
_$jscoverage["Bacon.coffee"][168] = 0;
_$jscoverage["Bacon.coffee"][169] = 0;
_$jscoverage["Bacon.coffee"][170] = 0;
_$jscoverage["Bacon.coffee"][171] = 0;
_$jscoverage["Bacon.coffee"][172] = 0;
_$jscoverage["Bacon.coffee"][173] = 0;
_$jscoverage["Bacon.coffee"][174] = 0;
_$jscoverage["Bacon.coffee"][175] = 0;
_$jscoverage["Bacon.coffee"][177] = 0;
_$jscoverage["Bacon.coffee"][178] = 0;
_$jscoverage["Bacon.coffee"][179] = 0;
_$jscoverage["Bacon.coffee"][180] = 0;
_$jscoverage["Bacon.coffee"][181] = 0;
_$jscoverage["Bacon.coffee"][182] = 0;
_$jscoverage["Bacon.coffee"][183] = 0;
_$jscoverage["Bacon.coffee"][184] = 0;
_$jscoverage["Bacon.coffee"][185] = 0;
_$jscoverage["Bacon.coffee"][186] = 0;
_$jscoverage["Bacon.coffee"][188] = 0;
_$jscoverage["Bacon.coffee"][189] = 0;
_$jscoverage["Bacon.coffee"][190] = 0;
_$jscoverage["Bacon.coffee"][191] = 0;
_$jscoverage["Bacon.coffee"][192] = 0;
_$jscoverage["Bacon.coffee"][193] = 0;
_$jscoverage["Bacon.coffee"][194] = 0;
_$jscoverage["Bacon.coffee"][195] = 0;
_$jscoverage["Bacon.coffee"][197] = 0;
_$jscoverage["Bacon.coffee"][198] = 0;
_$jscoverage["Bacon.coffee"][200] = 0;
_$jscoverage["Bacon.coffee"][201] = 0;
_$jscoverage["Bacon.coffee"][203] = 0;
_$jscoverage["Bacon.coffee"][204] = 0;
_$jscoverage["Bacon.coffee"][205] = 0;
_$jscoverage["Bacon.coffee"][206] = 0;
_$jscoverage["Bacon.coffee"][207] = 0;
_$jscoverage["Bacon.coffee"][208] = 0;
_$jscoverage["Bacon.coffee"][209] = 0;
_$jscoverage["Bacon.coffee"][210] = 0;
_$jscoverage["Bacon.coffee"][211] = 0;
_$jscoverage["Bacon.coffee"][213] = 0;
_$jscoverage["Bacon.coffee"][214] = 0;
_$jscoverage["Bacon.coffee"][215] = 0;
_$jscoverage["Bacon.coffee"][216] = 0;
_$jscoverage["Bacon.coffee"][217] = 0;
_$jscoverage["Bacon.coffee"][219] = 0;
_$jscoverage["Bacon.coffee"][220] = 0;
_$jscoverage["Bacon.coffee"][221] = 0;
_$jscoverage["Bacon.coffee"][222] = 0;
_$jscoverage["Bacon.coffee"][223] = 0;
_$jscoverage["Bacon.coffee"][225] = 0;
_$jscoverage["Bacon.coffee"][226] = 0;
_$jscoverage["Bacon.coffee"][227] = 0;
_$jscoverage["Bacon.coffee"][228] = 0;
_$jscoverage["Bacon.coffee"][229] = 0;
_$jscoverage["Bacon.coffee"][230] = 0;
_$jscoverage["Bacon.coffee"][232] = 0;
_$jscoverage["Bacon.coffee"][233] = 0;
_$jscoverage["Bacon.coffee"][234] = 0;
_$jscoverage["Bacon.coffee"][236] = 0;
_$jscoverage["Bacon.coffee"][237] = 0;
_$jscoverage["Bacon.coffee"][238] = 0;
_$jscoverage["Bacon.coffee"][240] = 0;
_$jscoverage["Bacon.coffee"][242] = 0;
_$jscoverage["Bacon.coffee"][243] = 0;
_$jscoverage["Bacon.coffee"][244] = 0;
_$jscoverage["Bacon.coffee"][246] = 0;
_$jscoverage["Bacon.coffee"][247] = 0;
_$jscoverage["Bacon.coffee"][248] = 0;
_$jscoverage["Bacon.coffee"][249] = 0;
_$jscoverage["Bacon.coffee"][251] = 0;
_$jscoverage["Bacon.coffee"][252] = 0;
_$jscoverage["Bacon.coffee"][253] = 0;
_$jscoverage["Bacon.coffee"][254] = 0;
_$jscoverage["Bacon.coffee"][256] = 0;
_$jscoverage["Bacon.coffee"][258] = 0;
_$jscoverage["Bacon.coffee"][259] = 0;
_$jscoverage["Bacon.coffee"][260] = 0;
_$jscoverage["Bacon.coffee"][261] = 0;
_$jscoverage["Bacon.coffee"][263] = 0;
_$jscoverage["Bacon.coffee"][264] = 0;
_$jscoverage["Bacon.coffee"][266] = 0;
_$jscoverage["Bacon.coffee"][267] = 0;
_$jscoverage["Bacon.coffee"][268] = 0;
_$jscoverage["Bacon.coffee"][269] = 0;
_$jscoverage["Bacon.coffee"][271] = 0;
_$jscoverage["Bacon.coffee"][273] = 0;
_$jscoverage["Bacon.coffee"][274] = 0;
_$jscoverage["Bacon.coffee"][275] = 0;
_$jscoverage["Bacon.coffee"][276] = 0;
_$jscoverage["Bacon.coffee"][277] = 0;
_$jscoverage["Bacon.coffee"][278] = 0;
_$jscoverage["Bacon.coffee"][279] = 0;
_$jscoverage["Bacon.coffee"][280] = 0;
_$jscoverage["Bacon.coffee"][282] = 0;
_$jscoverage["Bacon.coffee"][283] = 0;
_$jscoverage["Bacon.coffee"][285] = 0;
_$jscoverage["Bacon.coffee"][286] = 0;
_$jscoverage["Bacon.coffee"][287] = 0;
_$jscoverage["Bacon.coffee"][289] = 0;
_$jscoverage["Bacon.coffee"][290] = 0;
_$jscoverage["Bacon.coffee"][291] = 0;
_$jscoverage["Bacon.coffee"][292] = 0;
_$jscoverage["Bacon.coffee"][294] = 0;
_$jscoverage["Bacon.coffee"][296] = 0;
_$jscoverage["Bacon.coffee"][297] = 0;
_$jscoverage["Bacon.coffee"][298] = 0;
_$jscoverage["Bacon.coffee"][299] = 0;
_$jscoverage["Bacon.coffee"][301] = 0;
_$jscoverage["Bacon.coffee"][302] = 0;
_$jscoverage["Bacon.coffee"][303] = 0;
_$jscoverage["Bacon.coffee"][304] = 0;
_$jscoverage["Bacon.coffee"][305] = 0;
_$jscoverage["Bacon.coffee"][306] = 0;
_$jscoverage["Bacon.coffee"][307] = 0;
_$jscoverage["Bacon.coffee"][308] = 0;
_$jscoverage["Bacon.coffee"][309] = 0;
_$jscoverage["Bacon.coffee"][310] = 0;
_$jscoverage["Bacon.coffee"][311] = 0;
_$jscoverage["Bacon.coffee"][313] = 0;
_$jscoverage["Bacon.coffee"][314] = 0;
_$jscoverage["Bacon.coffee"][315] = 0;
_$jscoverage["Bacon.coffee"][316] = 0;
_$jscoverage["Bacon.coffee"][317] = 0;
_$jscoverage["Bacon.coffee"][318] = 0;
_$jscoverage["Bacon.coffee"][319] = 0;
_$jscoverage["Bacon.coffee"][320] = 0;
_$jscoverage["Bacon.coffee"][321] = 0;
_$jscoverage["Bacon.coffee"][323] = 0;
_$jscoverage["Bacon.coffee"][325] = 0;
_$jscoverage["Bacon.coffee"][326] = 0;
_$jscoverage["Bacon.coffee"][327] = 0;
_$jscoverage["Bacon.coffee"][328] = 0;
_$jscoverage["Bacon.coffee"][329] = 0;
_$jscoverage["Bacon.coffee"][330] = 0;
_$jscoverage["Bacon.coffee"][332] = 0;
_$jscoverage["Bacon.coffee"][333] = 0;
_$jscoverage["Bacon.coffee"][334] = 0;
_$jscoverage["Bacon.coffee"][335] = 0;
_$jscoverage["Bacon.coffee"][336] = 0;
_$jscoverage["Bacon.coffee"][337] = 0;
_$jscoverage["Bacon.coffee"][338] = 0;
_$jscoverage["Bacon.coffee"][340] = 0;
_$jscoverage["Bacon.coffee"][341] = 0;
_$jscoverage["Bacon.coffee"][342] = 0;
_$jscoverage["Bacon.coffee"][343] = 0;
_$jscoverage["Bacon.coffee"][344] = 0;
_$jscoverage["Bacon.coffee"][345] = 0;
_$jscoverage["Bacon.coffee"][347] = 0;
_$jscoverage["Bacon.coffee"][349] = 0;
_$jscoverage["Bacon.coffee"][351] = 0;
_$jscoverage["Bacon.coffee"][352] = 0;
_$jscoverage["Bacon.coffee"][353] = 0;
_$jscoverage["Bacon.coffee"][354] = 0;
_$jscoverage["Bacon.coffee"][355] = 0;
_$jscoverage["Bacon.coffee"][356] = 0;
_$jscoverage["Bacon.coffee"][357] = 0;
_$jscoverage["Bacon.coffee"][358] = 0;
_$jscoverage["Bacon.coffee"][359] = 0;
_$jscoverage["Bacon.coffee"][360] = 0;
_$jscoverage["Bacon.coffee"][361] = 0;
_$jscoverage["Bacon.coffee"][362] = 0;
_$jscoverage["Bacon.coffee"][363] = 0;
_$jscoverage["Bacon.coffee"][365] = 0;
_$jscoverage["Bacon.coffee"][366] = 0;
_$jscoverage["Bacon.coffee"][367] = 0;
_$jscoverage["Bacon.coffee"][368] = 0;
_$jscoverage["Bacon.coffee"][369] = 0;
_$jscoverage["Bacon.coffee"][370] = 0;
_$jscoverage["Bacon.coffee"][371] = 0;
_$jscoverage["Bacon.coffee"][372] = 0;
_$jscoverage["Bacon.coffee"][374] = 0;
_$jscoverage["Bacon.coffee"][375] = 0;
_$jscoverage["Bacon.coffee"][376] = 0;
_$jscoverage["Bacon.coffee"][378] = 0;
_$jscoverage["Bacon.coffee"][379] = 0;
_$jscoverage["Bacon.coffee"][380] = 0;
_$jscoverage["Bacon.coffee"][381] = 0;
_$jscoverage["Bacon.coffee"][382] = 0;
_$jscoverage["Bacon.coffee"][383] = 0;
_$jscoverage["Bacon.coffee"][384] = 0;
_$jscoverage["Bacon.coffee"][385] = 0;
_$jscoverage["Bacon.coffee"][386] = 0;
_$jscoverage["Bacon.coffee"][387] = 0;
_$jscoverage["Bacon.coffee"][390] = 0;
_$jscoverage["Bacon.coffee"][391] = 0;
_$jscoverage["Bacon.coffee"][392] = 0;
_$jscoverage["Bacon.coffee"][393] = 0;
_$jscoverage["Bacon.coffee"][394] = 0;
_$jscoverage["Bacon.coffee"][397] = 0;
_$jscoverage["Bacon.coffee"][398] = 0;
_$jscoverage["Bacon.coffee"][399] = 0;
_$jscoverage["Bacon.coffee"][400] = 0;
_$jscoverage["Bacon.coffee"][401] = 0;
_$jscoverage["Bacon.coffee"][402] = 0;
_$jscoverage["Bacon.coffee"][403] = 0;
_$jscoverage["Bacon.coffee"][404] = 0;
_$jscoverage["Bacon.coffee"][405] = 0;
_$jscoverage["Bacon.coffee"][406] = 0;
_$jscoverage["Bacon.coffee"][407] = 0;
_$jscoverage["Bacon.coffee"][408] = 0;
_$jscoverage["Bacon.coffee"][409] = 0;
_$jscoverage["Bacon.coffee"][410] = 0;
_$jscoverage["Bacon.coffee"][411] = 0;
_$jscoverage["Bacon.coffee"][412] = 0;
_$jscoverage["Bacon.coffee"][413] = 0;
_$jscoverage["Bacon.coffee"][415] = 0;
_$jscoverage["Bacon.coffee"][417] = 0;
_$jscoverage["Bacon.coffee"][418] = 0;
_$jscoverage["Bacon.coffee"][419] = 0;
_$jscoverage["Bacon.coffee"][420] = 0;
_$jscoverage["Bacon.coffee"][421] = 0;
_$jscoverage["Bacon.coffee"][422] = 0;
_$jscoverage["Bacon.coffee"][423] = 0;
_$jscoverage["Bacon.coffee"][424] = 0;
_$jscoverage["Bacon.coffee"][425] = 0;
_$jscoverage["Bacon.coffee"][426] = 0;
_$jscoverage["Bacon.coffee"][427] = 0;
_$jscoverage["Bacon.coffee"][429] = 0;
_$jscoverage["Bacon.coffee"][431] = 0;
_$jscoverage["Bacon.coffee"][432] = 0;
_$jscoverage["Bacon.coffee"][433] = 0;
_$jscoverage["Bacon.coffee"][434] = 0;
_$jscoverage["Bacon.coffee"][435] = 0;
_$jscoverage["Bacon.coffee"][436] = 0;
_$jscoverage["Bacon.coffee"][437] = 0;
_$jscoverage["Bacon.coffee"][438] = 0;
_$jscoverage["Bacon.coffee"][439] = 0;
_$jscoverage["Bacon.coffee"][441] = 0;
_$jscoverage["Bacon.coffee"][442] = 0;
_$jscoverage["Bacon.coffee"][443] = 0;
_$jscoverage["Bacon.coffee"][444] = 0;
_$jscoverage["Bacon.coffee"][446] = 0;
_$jscoverage["Bacon.coffee"][447] = 0;
_$jscoverage["Bacon.coffee"][449] = 0;
_$jscoverage["Bacon.coffee"][450] = 0;
_$jscoverage["Bacon.coffee"][452] = 0;
_$jscoverage["Bacon.coffee"][453] = 0;
_$jscoverage["Bacon.coffee"][454] = 0;
_$jscoverage["Bacon.coffee"][455] = 0;
_$jscoverage["Bacon.coffee"][456] = 0;
_$jscoverage["Bacon.coffee"][457] = 0;
_$jscoverage["Bacon.coffee"][458] = 0;
_$jscoverage["Bacon.coffee"][460] = 0;
_$jscoverage["Bacon.coffee"][461] = 0;
_$jscoverage["Bacon.coffee"][463] = 0;
_$jscoverage["Bacon.coffee"][465] = 0;
_$jscoverage["Bacon.coffee"][466] = 0;
_$jscoverage["Bacon.coffee"][467] = 0;
_$jscoverage["Bacon.coffee"][468] = 0;
_$jscoverage["Bacon.coffee"][470] = 0;
_$jscoverage["Bacon.coffee"][472] = 0;
_$jscoverage["Bacon.coffee"][473] = 0;
_$jscoverage["Bacon.coffee"][475] = 0;
_$jscoverage["Bacon.coffee"][476] = 0;
_$jscoverage["Bacon.coffee"][479] = 0;
_$jscoverage["Bacon.coffee"][482] = 0;
_$jscoverage["Bacon.coffee"][483] = 0;
_$jscoverage["Bacon.coffee"][486] = 0;
_$jscoverage["Bacon.coffee"][487] = 0;
_$jscoverage["Bacon.coffee"][489] = 0;
_$jscoverage["Bacon.coffee"][490] = 0;
_$jscoverage["Bacon.coffee"][495] = 0;
_$jscoverage["Bacon.coffee"][496] = 0;
_$jscoverage["Bacon.coffee"][497] = 0;
_$jscoverage["Bacon.coffee"][498] = 0;
_$jscoverage["Bacon.coffee"][499] = 0;
_$jscoverage["Bacon.coffee"][500] = 0;
_$jscoverage["Bacon.coffee"][502] = 0;
_$jscoverage["Bacon.coffee"][504] = 0;
_$jscoverage["Bacon.coffee"][506] = 0;
_$jscoverage["Bacon.coffee"][507] = 0;
_$jscoverage["Bacon.coffee"][508] = 0;
_$jscoverage["Bacon.coffee"][510] = 0;
_$jscoverage["Bacon.coffee"][511] = 0;
_$jscoverage["Bacon.coffee"][512] = 0;
_$jscoverage["Bacon.coffee"][513] = 0;
_$jscoverage["Bacon.coffee"][514] = 0;
_$jscoverage["Bacon.coffee"][515] = 0;
_$jscoverage["Bacon.coffee"][516] = 0;
_$jscoverage["Bacon.coffee"][517] = 0;
_$jscoverage["Bacon.coffee"][519] = 0;
_$jscoverage["Bacon.coffee"][520] = 0;
_$jscoverage["Bacon.coffee"][521] = 0;
_$jscoverage["Bacon.coffee"][523] = 0;
_$jscoverage["Bacon.coffee"][524] = 0;
_$jscoverage["Bacon.coffee"][525] = 0;
_$jscoverage["Bacon.coffee"][528] = 0;
_$jscoverage["Bacon.coffee"][529] = 0;
_$jscoverage["Bacon.coffee"][530] = 0;
_$jscoverage["Bacon.coffee"][531] = 0;
_$jscoverage["Bacon.coffee"][532] = 0;
_$jscoverage["Bacon.coffee"][533] = 0;
_$jscoverage["Bacon.coffee"][534] = 0;
_$jscoverage["Bacon.coffee"][535] = 0;
_$jscoverage["Bacon.coffee"][536] = 0;
_$jscoverage["Bacon.coffee"][537] = 0;
_$jscoverage["Bacon.coffee"][538] = 0;
_$jscoverage["Bacon.coffee"][539] = 0;
_$jscoverage["Bacon.coffee"][541] = 0;
_$jscoverage["Bacon.coffee"][543] = 0;
_$jscoverage["Bacon.coffee"][544] = 0;
_$jscoverage["Bacon.coffee"][545] = 0;
_$jscoverage["Bacon.coffee"][546] = 0;
_$jscoverage["Bacon.coffee"][547] = 0;
_$jscoverage["Bacon.coffee"][548] = 0;
_$jscoverage["Bacon.coffee"][551] = 0;
_$jscoverage["Bacon.coffee"][552] = 0;
_$jscoverage["Bacon.coffee"][554] = 0;
_$jscoverage["Bacon.coffee"][557] = 0;
_$jscoverage["Bacon.coffee"][558] = 0;
_$jscoverage["Bacon.coffee"][559] = 0;
_$jscoverage["Bacon.coffee"][560] = 0;
_$jscoverage["Bacon.coffee"][561] = 0;
_$jscoverage["Bacon.coffee"][563] = 0;
_$jscoverage["Bacon.coffee"][564] = 0;
_$jscoverage["Bacon.coffee"][567] = 0;
_$jscoverage["Bacon.coffee"][570] = 0;
_$jscoverage["Bacon.coffee"][573] = 0;
_$jscoverage["Bacon.coffee"][574] = 0;
_$jscoverage["Bacon.coffee"][575] = 0;
_$jscoverage["Bacon.coffee"][576] = 0;
_$jscoverage["Bacon.coffee"][577] = 0;
_$jscoverage["Bacon.coffee"][578] = 0;
_$jscoverage["Bacon.coffee"][580] = 0;
_$jscoverage["Bacon.coffee"][583] = 0;
_$jscoverage["Bacon.coffee"][584] = 0;
_$jscoverage["Bacon.coffee"][585] = 0;
_$jscoverage["Bacon.coffee"][587] = 0;
_$jscoverage["Bacon.coffee"][588] = 0;
_$jscoverage["Bacon.coffee"][589] = 0;
_$jscoverage["Bacon.coffee"][590] = 0;
_$jscoverage["Bacon.coffee"][591] = 0;
_$jscoverage["Bacon.coffee"][592] = 0;
_$jscoverage["Bacon.coffee"][593] = 0;
_$jscoverage["Bacon.coffee"][594] = 0;
_$jscoverage["Bacon.coffee"][595] = 0;
_$jscoverage["Bacon.coffee"][596] = 0;
_$jscoverage["Bacon.coffee"][597] = 0;
_$jscoverage["Bacon.coffee"][598] = 0;
_$jscoverage["Bacon.coffee"][599] = 0;
_$jscoverage["Bacon.coffee"][600] = 0;
_$jscoverage["Bacon.coffee"][601] = 0;
_$jscoverage["Bacon.coffee"][602] = 0;
_$jscoverage["Bacon.coffee"][603] = 0;
_$jscoverage["Bacon.coffee"][604] = 0;
_$jscoverage["Bacon.coffee"][605] = 0;
_$jscoverage["Bacon.coffee"][606] = 0;
_$jscoverage["Bacon.coffee"][607] = 0;
_$jscoverage["Bacon.coffee"][608] = 0;
_$jscoverage["Bacon.coffee"][609] = 0;
_$jscoverage["Bacon.coffee"][610] = 0;
_$jscoverage["Bacon.coffee"][611] = 0;
_$jscoverage["Bacon.coffee"][613] = 0;
_$jscoverage["Bacon.coffee"][614] = 0;
_$jscoverage["Bacon.coffee"][615] = 0;
_$jscoverage["Bacon.coffee"][617] = 0;
_$jscoverage["Bacon.coffee"][618] = 0;
_$jscoverage["Bacon.coffee"][619] = 0;
_$jscoverage["Bacon.coffee"][621] = 0;
_$jscoverage["Bacon.coffee"][623] = 0;
_$jscoverage["Bacon.coffee"][624] = 0;
_$jscoverage["Bacon.coffee"][625] = 0;
_$jscoverage["Bacon.coffee"][626] = 0;
_$jscoverage["Bacon.coffee"][628] = 0;
_$jscoverage["Bacon.coffee"][630] = 0;
_$jscoverage["Bacon.coffee"][631] = 0;
_$jscoverage["Bacon.coffee"][632] = 0;
_$jscoverage["Bacon.coffee"][633] = 0;
_$jscoverage["Bacon.coffee"][634] = 0;
_$jscoverage["Bacon.coffee"][635] = 0;
_$jscoverage["Bacon.coffee"][636] = 0;
_$jscoverage["Bacon.coffee"][637] = 0;
_$jscoverage["Bacon.coffee"][638] = 0;
_$jscoverage["Bacon.coffee"][639] = 0;
_$jscoverage["Bacon.coffee"][640] = 0;
_$jscoverage["Bacon.coffee"][641] = 0;
_$jscoverage["Bacon.coffee"][642] = 0;
_$jscoverage["Bacon.coffee"][644] = 0;
_$jscoverage["Bacon.coffee"][646] = 0;
_$jscoverage["Bacon.coffee"][647] = 0;
_$jscoverage["Bacon.coffee"][648] = 0;
_$jscoverage["Bacon.coffee"][650] = 0;
_$jscoverage["Bacon.coffee"][651] = 0;
_$jscoverage["Bacon.coffee"][652] = 0;
_$jscoverage["Bacon.coffee"][654] = 0;
_$jscoverage["Bacon.coffee"][655] = 0;
_$jscoverage["Bacon.coffee"][656] = 0;
_$jscoverage["Bacon.coffee"][657] = 0;
_$jscoverage["Bacon.coffee"][658] = 0;
_$jscoverage["Bacon.coffee"][659] = 0;
_$jscoverage["Bacon.coffee"][660] = 0;
_$jscoverage["Bacon.coffee"][661] = 0;
_$jscoverage["Bacon.coffee"][662] = 0;
_$jscoverage["Bacon.coffee"][663] = 0;
_$jscoverage["Bacon.coffee"][664] = 0;
_$jscoverage["Bacon.coffee"][666] = 0;
_$jscoverage["Bacon.coffee"][667] = 0;
_$jscoverage["Bacon.coffee"][668] = 0;
_$jscoverage["Bacon.coffee"][669] = 0;
_$jscoverage["Bacon.coffee"][670] = 0;
_$jscoverage["Bacon.coffee"][671] = 0;
_$jscoverage["Bacon.coffee"][672] = 0;
_$jscoverage["Bacon.coffee"][673] = 0;
_$jscoverage["Bacon.coffee"][674] = 0;
_$jscoverage["Bacon.coffee"][676] = 0;
_$jscoverage["Bacon.coffee"][677] = 0;
_$jscoverage["Bacon.coffee"][678] = 0;
_$jscoverage["Bacon.coffee"][679] = 0;
_$jscoverage["Bacon.coffee"][680] = 0;
_$jscoverage["Bacon.coffee"][681] = 0;
_$jscoverage["Bacon.coffee"][682] = 0;
_$jscoverage["Bacon.coffee"][683] = 0;
_$jscoverage["Bacon.coffee"][684] = 0;
_$jscoverage["Bacon.coffee"][685] = 0;
_$jscoverage["Bacon.coffee"][686] = 0;
_$jscoverage["Bacon.coffee"][687] = 0;
_$jscoverage["Bacon.coffee"][688] = 0;
_$jscoverage["Bacon.coffee"][689] = 0;
_$jscoverage["Bacon.coffee"][690] = 0;
_$jscoverage["Bacon.coffee"][691] = 0;
_$jscoverage["Bacon.coffee"][692] = 0;
_$jscoverage["Bacon.coffee"][693] = 0;
_$jscoverage["Bacon.coffee"][694] = 0;
_$jscoverage["Bacon.coffee"][695] = 0;
_$jscoverage["Bacon.coffee"][697] = 0;
_$jscoverage["Bacon.coffee"][698] = 0;
_$jscoverage["Bacon.coffee"][699] = 0;
_$jscoverage["Bacon.coffee"][700] = 0;
_$jscoverage["Bacon.coffee"][701] = 0;
_$jscoverage["Bacon.coffee"][702] = 0;
_$jscoverage["Bacon.coffee"][703] = 0;
_$jscoverage["Bacon.coffee"][704] = 0;
_$jscoverage["Bacon.coffee"][706] = 0;
_$jscoverage["Bacon.coffee"][707] = 0;
_$jscoverage["Bacon.coffee"][708] = 0;
_$jscoverage["Bacon.coffee"][709] = 0;
_$jscoverage["Bacon.coffee"][710] = 0;
_$jscoverage["Bacon.coffee"][711] = 0;
_$jscoverage["Bacon.coffee"][712] = 0;
_$jscoverage["Bacon.coffee"][713] = 0;
_$jscoverage["Bacon.coffee"][714] = 0;
_$jscoverage["Bacon.coffee"][715] = 0;
_$jscoverage["Bacon.coffee"][716] = 0;
_$jscoverage["Bacon.coffee"][718] = 0;
_$jscoverage["Bacon.coffee"][719] = 0;
_$jscoverage["Bacon.coffee"][720] = 0;
_$jscoverage["Bacon.coffee"][721] = 0;
_$jscoverage["Bacon.coffee"][722] = 0;
_$jscoverage["Bacon.coffee"][723] = 0;
_$jscoverage["Bacon.coffee"][724] = 0;
_$jscoverage["Bacon.coffee"][725] = 0;
_$jscoverage["Bacon.coffee"][727] = 0;
_$jscoverage["Bacon.coffee"][728] = 0;
_$jscoverage["Bacon.coffee"][729] = 0;
_$jscoverage["Bacon.coffee"][730] = 0;
_$jscoverage["Bacon.coffee"][731] = 0;
_$jscoverage["Bacon.coffee"][732] = 0;
_$jscoverage["Bacon.coffee"][733] = 0;
_$jscoverage["Bacon.coffee"][734] = 0;
_$jscoverage["Bacon.coffee"][735] = 0;
_$jscoverage["Bacon.coffee"][736] = 0;
_$jscoverage["Bacon.coffee"][737] = 0;
_$jscoverage["Bacon.coffee"][738] = 0;
_$jscoverage["Bacon.coffee"][739] = 0;
_$jscoverage["Bacon.coffee"][740] = 0;
_$jscoverage["Bacon.coffee"][741] = 0;
_$jscoverage["Bacon.coffee"][746] = 0;
_$jscoverage["Bacon.coffee"][747] = 0;
_$jscoverage["Bacon.coffee"][748] = 0;
_$jscoverage["Bacon.coffee"][749] = 0;
_$jscoverage["Bacon.coffee"][750] = 0;
_$jscoverage["Bacon.coffee"][752] = 0;
_$jscoverage["Bacon.coffee"][753] = 0;
_$jscoverage["Bacon.coffee"][755] = 0;
_$jscoverage["Bacon.coffee"][757] = 0;
_$jscoverage["Bacon.coffee"][758] = 0;
_$jscoverage["Bacon.coffee"][759] = 0;
_$jscoverage["Bacon.coffee"][760] = 0;
_$jscoverage["Bacon.coffee"][761] = 0;
_$jscoverage["Bacon.coffee"][762] = 0;
_$jscoverage["Bacon.coffee"][763] = 0;
_$jscoverage["Bacon.coffee"][764] = 0;
_$jscoverage["Bacon.coffee"][765] = 0;
_$jscoverage["Bacon.coffee"][767] = 0;
_$jscoverage["Bacon.coffee"][768] = 0;
_$jscoverage["Bacon.coffee"][769] = 0;
_$jscoverage["Bacon.coffee"][770] = 0;
_$jscoverage["Bacon.coffee"][771] = 0;
_$jscoverage["Bacon.coffee"][772] = 0;
_$jscoverage["Bacon.coffee"][773] = 0;
_$jscoverage["Bacon.coffee"][774] = 0;
_$jscoverage["Bacon.coffee"][775] = 0;
_$jscoverage["Bacon.coffee"][776] = 0;
_$jscoverage["Bacon.coffee"][777] = 0;
_$jscoverage["Bacon.coffee"][778] = 0;
_$jscoverage["Bacon.coffee"][779] = 0;
_$jscoverage["Bacon.coffee"][780] = 0;
_$jscoverage["Bacon.coffee"][781] = 0;
_$jscoverage["Bacon.coffee"][782] = 0;
_$jscoverage["Bacon.coffee"][783] = 0;
_$jscoverage["Bacon.coffee"][784] = 0;
_$jscoverage["Bacon.coffee"][785] = 0;
_$jscoverage["Bacon.coffee"][786] = 0;
_$jscoverage["Bacon.coffee"][787] = 0;
_$jscoverage["Bacon.coffee"][788] = 0;
_$jscoverage["Bacon.coffee"][789] = 0;
_$jscoverage["Bacon.coffee"][790] = 0;
_$jscoverage["Bacon.coffee"][791] = 0;
_$jscoverage["Bacon.coffee"][792] = 0;
_$jscoverage["Bacon.coffee"][793] = 0;
_$jscoverage["Bacon.coffee"][794] = 0;
_$jscoverage["Bacon.coffee"][795] = 0;
_$jscoverage["Bacon.coffee"][796] = 0;
_$jscoverage["Bacon.coffee"][797] = 0;
_$jscoverage["Bacon.coffee"][798] = 0;
_$jscoverage["Bacon.coffee"][799] = 0;
_$jscoverage["Bacon.coffee"][800] = 0;
_$jscoverage["Bacon.coffee"][801] = 0;
_$jscoverage["Bacon.coffee"][802] = 0;
_$jscoverage["Bacon.coffee"][803] = 0;
_$jscoverage["Bacon.coffee"][804] = 0;
_$jscoverage["Bacon.coffee"][806] = 0;
_$jscoverage["Bacon.coffee"][807] = 0;
_$jscoverage["Bacon.coffee"][808] = 0;
_$jscoverage["Bacon.coffee"][809] = 0;
_$jscoverage["Bacon.coffee"][811] = 0;
_$jscoverage["Bacon.coffee"][812] = 0;
_$jscoverage["Bacon.coffee"][814] = 0;
_$jscoverage["Bacon.coffee"][816] = 0;
_$jscoverage["Bacon.coffee"][818] = 0;
_$jscoverage["Bacon.coffee"][820] = 0;
_$jscoverage["Bacon.coffee"][822] = 0;
_$jscoverage["Bacon.coffee"][823] = 0;
_$jscoverage["Bacon.coffee"][824] = 0;
_$jscoverage["Bacon.coffee"][825] = 0;
_$jscoverage["Bacon.coffee"][828] = 0;
_$jscoverage["Bacon.coffee"][830] = 0;
_$jscoverage["Bacon.coffee"][831] = 0;
_$jscoverage["Bacon.coffee"][832] = 0;
_$jscoverage["Bacon.coffee"][833] = 0;
_$jscoverage["Bacon.coffee"][834] = 0;
_$jscoverage["Bacon.coffee"][835] = 0;
_$jscoverage["Bacon.coffee"][836] = 0;
_$jscoverage["Bacon.coffee"][837] = 0;
_$jscoverage["Bacon.coffee"][839] = 0;
_$jscoverage["Bacon.coffee"][840] = 0;
_$jscoverage["Bacon.coffee"][841] = 0;
_$jscoverage["Bacon.coffee"][842] = 0;
_$jscoverage["Bacon.coffee"][843] = 0;
_$jscoverage["Bacon.coffee"][844] = 0;
_$jscoverage["Bacon.coffee"][845] = 0;
_$jscoverage["Bacon.coffee"][846] = 0;
_$jscoverage["Bacon.coffee"][847] = 0;
_$jscoverage["Bacon.coffee"][848] = 0;
_$jscoverage["Bacon.coffee"][850] = 0;
_$jscoverage["Bacon.coffee"][851] = 0;
_$jscoverage["Bacon.coffee"][852] = 0;
_$jscoverage["Bacon.coffee"][853] = 0;
_$jscoverage["Bacon.coffee"][854] = 0;
_$jscoverage["Bacon.coffee"][855] = 0;
_$jscoverage["Bacon.coffee"][856] = 0;
_$jscoverage["Bacon.coffee"][857] = 0;
_$jscoverage["Bacon.coffee"][858] = 0;
_$jscoverage["Bacon.coffee"][860] = 0;
_$jscoverage["Bacon.coffee"][861] = 0;
_$jscoverage["Bacon.coffee"][862] = 0;
_$jscoverage["Bacon.coffee"][863] = 0;
_$jscoverage["Bacon.coffee"][864] = 0;
_$jscoverage["Bacon.coffee"][865] = 0;
_$jscoverage["Bacon.coffee"][866] = 0;
_$jscoverage["Bacon.coffee"][867] = 0;
_$jscoverage["Bacon.coffee"][868] = 0;
_$jscoverage["Bacon.coffee"][869] = 0;
_$jscoverage["Bacon.coffee"][870] = 0;
_$jscoverage["Bacon.coffee"][871] = 0;
_$jscoverage["Bacon.coffee"][872] = 0;
_$jscoverage["Bacon.coffee"][873] = 0;
_$jscoverage["Bacon.coffee"][874] = 0;
_$jscoverage["Bacon.coffee"][875] = 0;
_$jscoverage["Bacon.coffee"][876] = 0;
_$jscoverage["Bacon.coffee"][877] = 0;
_$jscoverage["Bacon.coffee"][878] = 0;
_$jscoverage["Bacon.coffee"][879] = 0;
_$jscoverage["Bacon.coffee"][880] = 0;
_$jscoverage["Bacon.coffee"][881] = 0;
_$jscoverage["Bacon.coffee"][882] = 0;
_$jscoverage["Bacon.coffee"][884] = 0;
_$jscoverage["Bacon.coffee"][886] = 0;
_$jscoverage["Bacon.coffee"][888] = 0;
_$jscoverage["Bacon.coffee"][889] = 0;
_$jscoverage["Bacon.coffee"][890] = 0;
_$jscoverage["Bacon.coffee"][891] = 0;
_$jscoverage["Bacon.coffee"][892] = 0;
_$jscoverage["Bacon.coffee"][893] = 0;
_$jscoverage["Bacon.coffee"][894] = 0;
_$jscoverage["Bacon.coffee"][895] = 0;
_$jscoverage["Bacon.coffee"][896] = 0;
_$jscoverage["Bacon.coffee"][897] = 0;
_$jscoverage["Bacon.coffee"][898] = 0;
_$jscoverage["Bacon.coffee"][899] = 0;
_$jscoverage["Bacon.coffee"][900] = 0;
_$jscoverage["Bacon.coffee"][901] = 0;
_$jscoverage["Bacon.coffee"][902] = 0;
_$jscoverage["Bacon.coffee"][904] = 0;
_$jscoverage["Bacon.coffee"][906] = 0;
_$jscoverage["Bacon.coffee"][907] = 0;
_$jscoverage["Bacon.coffee"][908] = 0;
_$jscoverage["Bacon.coffee"][909] = 0;
_$jscoverage["Bacon.coffee"][910] = 0;
_$jscoverage["Bacon.coffee"][912] = 0;
_$jscoverage["Bacon.coffee"][913] = 0;
_$jscoverage["Bacon.coffee"][914] = 0;
_$jscoverage["Bacon.coffee"][916] = 0;
_$jscoverage["Bacon.coffee"][917] = 0;
_$jscoverage["Bacon.coffee"][918] = 0;
_$jscoverage["Bacon.coffee"][919] = 0;
_$jscoverage["Bacon.coffee"][921] = 0;
_$jscoverage["Bacon.coffee"][923] = 0;
_$jscoverage["Bacon.coffee"][925] = 0;
_$jscoverage["Bacon.coffee"][926] = 0;
_$jscoverage["Bacon.coffee"][927] = 0;
_$jscoverage["Bacon.coffee"][928] = 0;
_$jscoverage["Bacon.coffee"][929] = 0;
_$jscoverage["Bacon.coffee"][931] = 0;
_$jscoverage["Bacon.coffee"][932] = 0;
_$jscoverage["Bacon.coffee"][933] = 0;
_$jscoverage["Bacon.coffee"][934] = 0;
_$jscoverage["Bacon.coffee"][936] = 0;
_$jscoverage["Bacon.coffee"][938] = 0;
_$jscoverage["Bacon.coffee"][939] = 0;
_$jscoverage["Bacon.coffee"][940] = 0;
_$jscoverage["Bacon.coffee"][941] = 0;
_$jscoverage["Bacon.coffee"][942] = 0;
_$jscoverage["Bacon.coffee"][943] = 0;
_$jscoverage["Bacon.coffee"][946] = 0;
var i, line, _i, _len, _ref;
_ref = _$jscoverage["Bacon.coffee"];
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
line = _ref[i];
_$jscoverage["Bacon.coffee"][i] = 1;
}
if (window.coverage == null) {
window.coverage = new Bacon.Bus();
}
_.observe(_$jscoverage["Bacon.coffee"], function(new_array, old_array) {
return window.coverage.push(new_array);
});
}
_$jscoverage["Bacon.coffee"].source = ["(this.jQuery || this.Zepto)?.fn.asEventStream = (eventName, selector, eventTransformer = _.id) ->", " if (isFunction(selector))", " eventTransformer = selector", " selector = null", " element = this", " new EventStream (sink) ->", " handler = (args...) ->", " reply = sink (next (eventTransformer args...))", " if (reply == Bacon.noMore)", " unbind()", " unbind = -> element.off(eventName, selector, handler)", " element.on(eventName, selector, handler)", " unbind", "", "Bacon = @Bacon = {}", "", "Bacon.fromPromise = (promise) ->", " new EventStream(", " (sink) ->", " onSuccess = (value) ->", " sink next(value)", " sink end()", " onError = (e) ->", " sink (new Error e)", " sink end()", " promise.then(onSuccess, onError)", " nop", " )", "", "Bacon.noMore = [\"<no-more>\"]", "", "Bacon.more = [\"<more>\"]", "", "Bacon.later = (delay, value) ->", " Bacon.sequentially(delay, [value])", "", "Bacon.sequentially = (delay, values) ->", " index = -1", " poll = ->", " index++", " valueEvent = toEvent values[index]", " if index < values.length - 1", " valueEvent", " else", " [valueEvent, end()]", " Bacon.fromPoll(delay, poll)", "", "Bacon.repeatedly = (delay, values) ->", " index = -1", " poll = ->", " index++", " toEvent values[index % values.length]", " Bacon.fromPoll(delay, poll)", "", "Bacon.fromCallback = (f, args...) -> ", " f = makeFunction(f, args)", " new EventStream (sink) ->", " handler = (value) ->", " sink next(value)", " sink end()", " f(handler)", " nop", "", "Bacon.fromPoll = (delay, poll) ->", " new EventStream (sink) ->", " id = undefined", " handler = ->", " events = _.toArray(poll())", " for event in events", " reply = sink event", " if (reply == Bacon.noMore or event.isEnd())", " unbind()", " unbind = -> ", " clearInterval id", " id = setInterval(handler, delay)", " unbind", "", "", "# Wrap DOM EventTarget or Node EventEmitter as EventStream", "#", "# target - EventTarget or EventEmitter, source of events", "# eventName - event name to bind", "#", "# Examples", "#", "# Bacon.fromEventTarget(document.body, \"click\")", "# # => EventStream", "#", "# Bacon.fromEventTarget (new EventEmitter(), \"data\")", "# # => EventStream", "#", "# Returns EventStream", "Bacon.fromEventTarget = (target, eventName, eventTransformer = _.id) ->", " new EventStream (sink) ->", " handler = (args...) ->", " reply = sink (next eventTransformer args...)", " if reply == Bacon.noMore", " unbind()", "", " if target.addEventListener", " unbind = -> target.removeEventListener(eventName, handler, false)", " target.addEventListener(eventName, handler, false)", " else", " unbind = -> target.removeListener(eventName, handler)", " target.addListener(eventName, handler)", " unbind", "", "Bacon.interval = (delay, value) ->", " value = {} unless value?", " poll = -> next(value)", " Bacon.fromPoll(delay, poll)", "", "Bacon.constant = (value) ->", " new Property(sendWrapped([value], initial))", "", "Bacon.never = -> Bacon.fromArray([])", "", "Bacon.once = (value) -> Bacon.fromArray([value])", "", "Bacon.fromArray = (values) ->", " new EventStream(sendWrapped(values, next))", "", "sendWrapped = (values, wrapper) ->", " (sink) ->", " for value in values", " sink (wrapper value)", " sink (end())", " nop", "", "Bacon.combineAll = (streams, f) ->", " assertArray streams", " stream = _.head streams", " for next in (_.tail streams)", " stream = f(stream, next)", " stream", "", "Bacon.mergeAll = (streams) ->", " Bacon.combineAll(streams, (s1, s2) -> s1.merge(s2))", "", "Bacon.combineAsArray = (streams, more...) ->", " if not (streams instanceof Array)", " streams = [streams].concat(more)", " if streams.length", " stream = (_.head streams).toProperty().map((x) -> [x])", " for next in (_.tail streams)", " stream = stream.combine(next, (xs, x) -> xs.concat([x]))", " stream", " else", " Bacon.constant([])", "", "Bacon.combineWith = (streams, f) ->", " Bacon.combineAll(streams, (s1, s2) ->", " s1.toProperty().combine(s2, f))", "", "Bacon.combineTemplate = (template) ->", " funcs = []", " streams = []", " current = (ctxStack) -> ctxStack[ctxStack.length - 1]", " setValue = (ctxStack, key, value) -> current(ctxStack)[key] = value", " applyStreamValue = (key, index) -> (ctxStack, values) -> setValue(ctxStack, key, values[index])", " constantValue = (key, value) -> (ctxStack, values) -> setValue(ctxStack, key, value)", " mkContext = (template) -> if template instanceof Array then [] else {}", " compile = (key, value) ->", " if (value instanceof Observable)", " streams.push(value)", " funcs.push(applyStreamValue(key, streams.length - 1))", " else if (typeof value == \"object\")", " pushContext = (key) -> (ctxStack, values) ->", " newContext = mkContext(value)", " setValue(ctxStack, key, newContext)", " ctxStack.push(newContext)", " popContext = (ctxStack, values) -> ctxStack.pop()", " funcs.push(pushContext(key))", " compileTemplate(value)", " funcs.push(popContext)", " else", " funcs.push(constantValue(key, value))", " compileTemplate = (template) -> _.each(template, compile)", " compileTemplate template", " combinator = (values) ->", " rootContext = mkContext(template)", " ctxStack = [rootContext]", " for f in funcs ", " f(ctxStack, values)", " rootContext", " Bacon.combineAsArray(streams).map(combinator)", "", "class Event", " isEvent: -> true", " isEnd: -> false", " isInitial: -> false", " isNext: -> false", " isError: -> false", " hasValue: -> false", " filter: (f) -> true", " getOriginalEvent: -> ", " if @sourceEvent? ", " @sourceEvent.getOriginalEvent() ", " else ", " this", " onDone : (listener) -> listener()", "", "class Next extends Event", " constructor: (value, sourceEvent) ->", " @value = if isFunction(value) then value else _.always(value)", " isNext: -> true", " hasValue: -> true", " fmap: (f) -> @apply(f(this.value()))", " apply: (value) -> next(value, @getOriginalEvent())", " filter: (f) -> f(@value())", " describe: -> @value()", "", "class Initial extends Next", " isInitial: -> true", " isNext: -> false", " apply: (value) -> initial(value, @getOriginalEvent())", " toNext: -> new Next(@value, @getOriginalEvent())", "", "class End extends Event", " isEnd: -> true", " fmap: -> this", " apply: -> this", " describe: -> \"<end>\"", "", "class Error extends Event", " constructor: (@error) ->", " isError: -> true", " fmap: -> this", " apply: -> this", " describe: -> \"<error> #{@error}\"", "", "class Observable", " constructor: ->", " @assign = @onValue", " onValue: (f, args...) -> ", " f = makeFunction(f, args)", " @subscribe (event) ->", " f event.value() if event.hasValue()", " onValues: (f) ->", " @onValue (args) -> f(args...)", " onError: (f, args...) -> ", " f = makeFunction(f, args)", " @subscribe (event) ->", " f event.error if event.isError()", " onEnd: (f, args...) -> ", " f = makeFunction(f, args)", " @subscribe (event) ->", " f() if event.isEnd()", " errors: -> @filter(-> false)", " filter: (f, args...) ->", " f = makeFunction(f, args)", " @withHandler (event) -> ", " if event.filter(f)", " @push event", " else", " Bacon.more", " takeWhile: (f, args...) ->", " f = makeFunction(f, args)", " @withHandler (event) -> ", " if event.filter(f)", " @push event", " else", " @push end()", " Bacon.noMore", " endOnError: ->", " @withHandler (event) ->", " if event.isError()", " @push event", " @push end()", " else", " @push event", " take: (count) ->", " assert \"take: count must >= 1\", (count>=1)", " @withHandler (event) ->", " if !event.hasValue()", " @push event", " else if (count == 1)", " @push event", " @push end()", " Bacon.noMore", " else", " count--", " @push event", " map: (f, args...) ->", " f = makeFunction(f, args)", " @withHandler (event) -> ", " @push event.fmap(f)", " mapError : (f, args...) ->", " f = makeFunction(f, args)", " @withHandler (event) ->", " if event.isError()", " @push next (f event.error)", " else", " @push event", " doAction: (f, args...) ->", " f = makeFunction(f, args)", " @withHandler (event) ->", " f(event.value()) if event.hasValue()", " @push event", " takeUntil: (stopper) =>", " src = this", " @withSubscribe (sink) ->", " unsubscribed = false", " unsubSrc = nop", " unsubStopper = nop", " unsubBoth = -> unsubSrc() ; unsubStopper() ; unsubscribed = true", " srcSink = (event) ->", " if event.isEnd()", " unsubStopper()", " sink event", " Bacon.noMore", " else", " event.getOriginalEvent().onDone ->", " if !unsubscribed", " reply = sink event", " if reply == Bacon.noMore", " unsubBoth()", " Bacon.more", " stopperSink = (event) ->", " if event.isError()", " Bacon.more", " else if event.isEnd()", " Bacon.noMore", " else", " unsubSrc()", " sink end()", " Bacon.noMore", " unsubSrc = src.subscribe(srcSink)", " unsubStopper = stopper.subscribe(stopperSink) unless unsubscribed", " unsubBoth", " skip : (count) ->", " assert \"skip: count must >= 0\", (count>=0)", " @withHandler (event) ->", " if !event.hasValue()", " @push event", " else if (count > 0)", " count--", " Bacon.more", " else", " @push event", " distinctUntilChanged: -> @skipDuplicates()", " skipDuplicates: (isEqual = (a, b) -> a is b) ->", " @withStateMachine None, (prev, event) ->", " if !event.hasValue()", " [prev, [event]]", " else if prev == None or not isEqual(prev.get(), event.value())", " [new Some(event.value()), [event]]", " else", " [prev, []]", " withStateMachine: (initState, f) ->", " state = initState", " @withHandler (event) ->", " fromF = f(state, event)", " assertArray fromF", " [newState, outputs] = fromF", " assertArray outputs", " state = newState", " reply = Bacon.more", " for output in outputs", " reply = @push output", " if reply == Bacon.noMore", " return reply", " reply", " scan: (seed, f) =>", " f = toCombinator(f)", " acc = toOption(seed)", " subscribe = (sink) =>", " initSent = false", " unsub = @subscribe (event) =>", " if (event.hasValue())", " if (initSent && event.isInitial())", " Bacon.more # init already sent, skip this one", " else", " initSent = true", " acc = new Some(f(acc.getOrElse(undefined), event.value()))", " sink (event.apply(acc.get()))", " else", " if event.isEnd() then initSent = true", " sink event", " if !initSent", " acc.forEach (value) ->", " reply = sink initial(value)", " if (reply == Bacon.noMore)", " unsub()", " unsub = nop", " unsub", " new Property(new PropertyDispatcher(subscribe).subscribe) ", "", " diff: (start, f) -> ", " f = toCombinator(f)", " @scan([start], (prevTuple, next) -> ", " [next, f(prevTuple[0], next)])", " .filter((tuple) -> tuple.length == 2)", " .map((tuple) -> tuple[1])", "", " flatMap: (f) ->", " root = this", " new EventStream (sink) ->", " children = []", " rootEnd = false", " unsubRoot = ->", " unbind = ->", " unsubRoot()", " for unsubChild in children", " unsubChild()", " children = []", " checkEnd = ->", " if rootEnd and (children.length == 0)", " sink end()", " spawner = (event) ->", " if event.isEnd()", " rootEnd = true", " checkEnd()", " else if event.isError()", " sink event", " else", " child = f event.value()", " unsubChild = undefined", " childEnded = false", " removeChild = ->", " remove(unsubChild, children) if unsubChild?", " checkEnd()", " handler = (event) ->", " if event.isEnd()", " removeChild()", " childEnded = true", " Bacon.noMore", " else", " if event instanceof Initial", " # To support Property as the spawned stream", " event = event.toNext()", " reply = sink event", " if reply == Bacon.noMore", " unbind()", " reply", " unsubChild = child.subscribe handler", " children.push unsubChild if not childEnded", " unsubRoot = root.subscribe(spawner)", " unbind", " flatMapLatest: (f) =>", " stream = @toEventStream()", " stream.flatMap (value) =>", " f(value).takeUntil(stream)", " not: -> @map((x) -> !x)", " log: -> ", " @subscribe (event) -> console.log(event.describe())", " this", " slidingWindow: (n) -> ", " @scan [], (window, value) ->", " window.concat([value]).slice(-n)", "", "class EventStream extends Observable", " constructor: (subscribe) ->", " super()", " assertFunction subscribe", " dispatcher = new Dispatcher(subscribe)", " @subscribe = dispatcher.subscribe", " @hasSubscribers = dispatcher.hasSubscribers", " map: (p, args...) ->", " if (p instanceof Property)", " p.sampledBy(this, former)", " else", " super(p, args...)", " filter: (p, args...) ->", " if (p instanceof Property)", " p.sampledBy(this, (p,s) -> [p,s])", " .filter(([p, s]) -> p)", " .map(([p, s]) -> s)", " else", " super(p, args...)", " delay: (delay) ->", " @flatMap (value) ->", " Bacon.later delay, value", " throttle: (delay) ->", " @flatMapLatest (value) ->", " Bacon.later delay, value", "", " throttle2: (delay) ->", " @bufferWithTime(delay).map((values) -> values[values.length - 1])", "", " bufferWithTime: (delay) ->", " schedule = (buffer) => buffer.schedule()", " @buffer(delay, schedule, schedule)", "", " bufferWithCount: (count) ->", " flushOnCount = (buffer) -> buffer.flush() if buffer.values.length == count", " @buffer(0, flushOnCount)", "", " buffer: (delay, onInput = (->), onFlush = (->)) ->", " buffer = {", " scheduled: false", " end : null", " values : []", " flush: ->", " @scheduled = false", " if @values.length > 0", " reply = @push next(@values)", " @values = []", " if @end?", " @push @end", " else if reply != Bacon.noMore", " onFlush(this)", " else", " @push @end if @end?", " schedule: ->", " if not @scheduled", " @scheduled = true", " delay(=> @flush())", " }", " reply = Bacon.more", " if not isFunction(delay)", " delayMs = delay", " delay = (f) -> setTimeout(f, delayMs)", " @withHandler (event) ->", " buffer.push = @push", " if event.isError()", " reply = @push event", " else if event.isEnd()", " buffer.end = event", " if not buffer.scheduled", " buffer.flush()", " else", " buffer.values.push(event.value())", " onInput(buffer)", " reply", "", " merge: (right) -> ", " left = this", " new EventStream (sink) ->", " unsubLeft = nop", " unsubRight = nop", " unsubscribed = false", " unsubBoth = -> unsubLeft() ; unsubRight() ; unsubscribed = true", " ends = 0", " smartSink = (event) ->", " if event.isEnd()", " ends++", " if ends == 2", " sink end()", " else", " Bacon.more", " else", " reply = sink event", " unsubBoth() if reply == Bacon.noMore", " reply", " unsubLeft = left.subscribe(smartSink)", " unsubRight = right.subscribe(smartSink) unless unsubscribed", " unsubBoth", "", " toProperty: (initValue) ->", " initValue = None if arguments.length == 0", " @scan(initValue, latter)", "", " toEventStream: -> this", "", " concat: (right) ->", " left = this", " new EventStream (sink) ->", " unsub = left.subscribe (e) ->", " if e.isEnd()", " unsub = right.subscribe sink", " else", " sink(e)", " -> unsub()", "", " awaiting: (other) -> ", " this.map(true).merge(other.map(false)).toProperty(false)", "", " startWith: (seed) ->", " Bacon.once(seed).concat(this)", "", " mapEnd : (f, args...) ->", " f = makeFunction(f, args)", " @withHandler (event) ->", " if (event.isEnd())", " @push next(f(event))", " @push end()", " Bacon.noMore", " else", " @push event", "", " withHandler: (handler) ->", " dispatcher = new Dispatcher(@subscribe, handler)", " new EventStream(dispatcher.subscribe)", " withSubscribe: (subscribe) -> new EventStream(subscribe)", "", "class Property extends Observable", " constructor: (@subscribe) ->", " super()", " combine = (other, leftSink, rightSink) => ", " myVal = None", " otherVal = None", " new Property (sink) =>", " unsubscribed = false", " unsubMe = nop", " unsubOther = nop", " unsubBoth = -> unsubMe() ; unsubOther() ; unsubscribed = true", " myEnd = false", " otherEnd = false", " checkEnd = ->", " if myEnd and otherEnd", " reply = sink end()", " unsubBoth() if reply == Bacon.noMore", " reply", " initialSent = false", " combiningSink = (markEnd, setValue, thisSink) =>", " (event) =>", " if (event.isEnd())", " markEnd()", " checkEnd()", " Bacon.noMore", " else if event.isError()", " reply = sink event", " unsubBoth() if reply == Bacon.noMore", " reply", " else", " setValue(new Some(event.value()))", " if (myVal.isDefined and otherVal.isDefined)", " if initialSent and event.isInitial()", " # don't send duplicate Initial", " Bacon.more", " else", " initialSent = true", " reply = thisSink(sink, event, myVal.value, otherVal.value)", " unsubBoth() if reply == Bacon.noMore", " reply", " else", " Bacon.more", "", " mySink = combiningSink (-> myEnd = true), ((value) -> myVal = value), leftSink", " otherSink = combiningSink (-> otherEnd = true), ((value) -> otherVal = value), rightSink", " unsubMe = this.subscribe mySink", " unsubOther = other.subscribe otherSink unless unsubscribed", " unsubBoth", " @combine = (other, f) =>", " combinator = toCombinator(f)", " combineAndPush = (sink, event, myVal, otherVal) -> sink(event.apply(combinator(myVal, otherVal)))", " combine(other, combineAndPush, combineAndPush)", " @sampledBy = (sampler, combinator = former) =>", " combinator = toCombinator(combinator)", " pushPropertyValue = (sink, event, propertyVal, streamVal) -> sink(event.apply(combinator(propertyVal, streamVal)))", " combine(sampler, nop, pushPropertyValue).changes().takeUntil(sampler.filter(false).mapEnd())", " sample: (interval) =>", " @sampledBy Bacon.interval(interval, {})", "", " changes: => new EventStream (sink) =>", " @subscribe (event) =>", " sink event unless event.isInitial()", " withHandler: (handler) ->", " new Property(new PropertyDispatcher(@subscribe, handler).subscribe)", " withSubscribe: (subscribe) -> new Property(new PropertyDispatcher(subscribe).subscribe)", " toProperty: => this", " toEventStream: => ", " new EventStream (sink) =>", " @subscribe (event) =>", " event = event.toNext() if event.isInitial()", " sink event", " and: (other) -> @combine(other, (x, y) -> x && y)", " or: (other) -> @combine(other, (x, y) -> x || y)", " decode: (cases) -> @combine(Bacon.combineTemplate(cases), (key, values) -> values[key])", " delay: (delay) -> @delayChanges((changes) -> changes.delay(delay))", " throttle: (delay) -> @delayChanges((changes) -> changes.throttle(delay))", " throttle2: (delay) -> @delayChanges((changes) -> changes.throttle2(delay))", " delayChanges: (f) -> addPropertyInitValueToStream(this, f(@changes())) ", "", "addPropertyInitValueToStream = (property, stream) ->", " getInitValue = (property) ->", " value = None", " property.subscribe (event) ->", " if event.isInitial()", " value = new Some(event.value())", " Bacon.noMore", " value", " stream.toProperty(getInitValue(property))", "", "class Dispatcher", " constructor: (subscribe, handleEvent) ->", " subscribe ?= -> nop", " sinks = []", " ended = false", " @hasSubscribers = -> sinks.length > 0", " unsubscribeFromSource = nop", " removeSink = (sink) ->", " remove(sink, sinks)", " @push = (event) =>", " waiters = undefined", " done = -> ", " if waiters?", " ws = waiters", " waiters = undefined", " w() for w in ws", " event.onDone = Event.prototype.onDone", " event.onDone = (listener) ->", " if waiters? and not _.contains(waiters, listener)", " waiters.push(listener)", " else", " waiters = [listener]", " assertEvent event", " for sink in (cloneArray(sinks))", " reply = sink event", " removeSink sink if reply == Bacon.noMore or event.isEnd()", " done()", " if @hasSubscribers() ", " Bacon.more ", " else ", " Bacon.noMore", " handleEvent ?= (event) -> @push event", " @handleEvent = (event) => ", " assertEvent event", " if event.isEnd()", " ended = true", " handleEvent.apply(this, [event])", " @subscribe = (sink) =>", " if ended", " sink end()", " nop", " else", " assertFunction sink", " sinks.push(sink)", " if sinks.length == 1", " unsubscribeFromSource = subscribe @handleEvent", " assertFunction unsubscribeFromSource", " =>", " removeSink sink", " unsubscribeFromSource() unless @hasSubscribers()", "", "class PropertyDispatcher extends Dispatcher", " constructor: (subscribe, handleEvent) ->", " super(subscribe, handleEvent)", " current = None", " push = @push", " subscribe = @subscribe", " ended = false", " @push = (event) =>", " if event.isEnd() ", " ended = true", " if event.hasValue()", " current = new Some(event.value())", " push.apply(this, [event])", " @subscribe = (sink) =>", " initSent = false", " # init value is \"bounced\" here because the base Dispatcher class", " # won't add more than one subscription to the underlying observable.", " # without bouncing, the init value would be missing from all new subscribers", " # after the first one", " shouldBounceInitialValue = => @hasSubscribers() or ended", " reply = current.filter(shouldBounceInitialValue).map(", " (val) -> sink initial(val))", " if reply.getOrElse(Bacon.more) == Bacon.noMore", " nop", " else if ended", " sink end()", " nop", " else", " subscribe.apply(this, [sink])", "", "class Bus extends EventStream", " constructor: ->", " sink = undefined", " subscriptions = []", " ended = false", " guardedSink = (input) => (event) =>", " if (event.isEnd())", " unsubscribeInput(input)", " Bacon.noMore", " else", " sink event", " unsubAll = => ", " for sub in subscriptions", " if sub.unsub?", " sub.unsub()", " subscriptions = []", " subscribeInput = (subscription) ->", " subscription.unsub = (subscription.input.subscribe(guardedSink(subscription.input)))", " unsubscribeInput = (input) ->", " for sub, i in subscriptions", " if sub.input == input", " sub.unsub() if sub.unsub?", " subscriptions.splice(i, 1)", " return", " subscribeAll = (newSink) =>", " sink = newSink", " unsubFuncs = []", " for subscription in cloneArray(subscriptions)", " subscribeInput(subscription)", " unsubAll", " dispatcher = new Dispatcher(subscribeAll)", " subscribeThis = (sink) =>", " dispatcher.subscribe(sink)", " super(subscribeThis)", " @plug = (input) =>", " return if ended", " sub = { input: input }", " subscriptions.push(sub)", " subscribeInput(sub) if (sink?)", " () -> unsubscribeInput(input)", " @push = (value) =>", " sink next(value) if sink?", " @error = (error) =>", " sink new Error(error) if sink?", " @end = =>", " ended = true", " unsubAll()", " sink end() if sink?", "", "class Some", " constructor: (@value) ->", " getOrElse: -> @value", " get: -> @value", " filter: (f) ->", " if f @value", " new Some(@value)", " else", " None", " map: (f) ->", " new Some(f @value)", " forEach: (f) ->", " f @value", " isDefined: true", " toArray: -> [@value]", "", "None =", " getOrElse: (value) -> value", " filter: -> None", " map: -> None", " forEach: ->", " isDefined: false", " toArray: -> []", "", "Bacon.EventStream = EventStream", "Bacon.Property = Property", "Bacon.Observable = Observable", "Bacon.Bus = Bus", "Bacon.Initial = Initial", "Bacon.Next = Next", "Bacon.End = End", "Bacon.Error = Error", "", "nop = ->", "latter = (_, x) -> x", "former = (x, _) -> x", "initial = (value) -> new Initial(_.always(value))", "next = (value) -> new Next(_.always(value))", "end = -> new End()", "isEvent = (x) -> x? and x.isEvent? and x.isEvent()", "toEvent = (x) -> ", " if isEvent x", " x", " else", " next x", "cloneArray = (xs) -> xs.slice(0)", "cloneObject = (src) ->", " clone = {}", " for key, value of src", " clone[key] = value", " clone", "indexOf = if Array::indexOf", " (xs, x) -> xs.indexOf(x)", "else", " (xs, x) ->", " for y, i in xs", " return i if x == y", " -1", "remove = (x, xs) ->", " i = indexOf(xs, x)", " if i >= 0", " xs.splice(i, 1)", "assert = (message, condition) -> throw message unless condition", "assertEvent = (event) -> assert \"not an event : \" + event, event.isEvent? ; assert \"not event\", event.isEvent()", "assertFunction = (f) -> assert \"not a function : \" + f, isFunction(f)", "isFunction = (f) -> typeof f == \"function\"", "assertArray = (xs) -> assert \"not an array : \" + xs, xs instanceof Array", "assertString = (x) -> assert \"not a string : \" + x, typeof x == \"string\"", "methodCall = (obj, method, args) ->", " assertString(method)", " if args == undefined then args = []", " (value) -> obj[method]((args.concat([value]))...)", "partiallyApplied = (f, args) ->", " (value) -> f((args.concat([value]))...)", "makeFunction = (f, args) ->", " if isFunction f", " if args.length then partiallyApplied(f, args) else f", " else if isFieldKey(f) ", " toFieldExtractor(f, args)", " else if typeof f == \"object\" and args.length", " methodCall(f, _.head(args), _.tail(args))", " else", " _.always f", "isFieldKey = (f) ->", " (typeof f == \"string\") and f.length > 1 and f.charAt(0) == \".\"", "Bacon.isFieldKey = isFieldKey", "toFieldExtractor = (f, args) ->", " parts = f.slice(1).split(\".\")", " partFuncs = _.map(toSimpleExtractor(args), parts)", " (value) ->", " for f in partFuncs", " value = f(value)", " value", "toSimpleExtractor = (args) -> (key) -> (value) ->", " fieldValue = value[key]", " if isFunction(fieldValue)", " fieldValue.apply(value, args)", " else", " fieldValue", "", "toFieldKey = (f) ->", " f.slice(1)", "toCombinator = (f) ->", " if isFunction f", " f", " else if isFieldKey f", " key = toFieldKey(f)", " (left, right) ->", " left[key](right)", " else", " assert \"not a function or a field key: \" + f, false", "toOption = (v) ->", " if v instanceof Some || v == None", " v", " else", " new Some(v)", "", "if define? and define.amd? then define? -> Bacon", "", "_ = {", " head: (xs) -> xs[0],", " always: (x) -> (-> x),", " empty: (xs) -> xs.length == 0,", " tail: (xs) -> xs[1...xs.length],", " filter: (f, xs) ->", " filtered = []", " for x in xs", " filtered.push(x) if f(x)", " filtered", " map: (f, xs) ->", " f(x) for x in xs", " each: (xs, f) ->", " for key, value of xs", " f(key, value)", " toArray: (xs) -> if (xs instanceof Array) then xs else [xs]", " contains: (xs, x) -> indexOf(xs, x) != -1", " id: (x) -> x", " last: (xs) -> xs[xs.length-1]", "}", "", "Bacon._ = _", ""];
(function() {
var Bacon, Bus, Dispatcher, End, Error, Event, EventStream, Initial, Next, None, Observable, Property, PropertyDispatcher, Some, addPropertyInitValueToStream, assert, assertArray, assertEvent, assertFunction, assertString, cloneArray, cloneObject, end, former, indexOf, initial, isEvent, isFieldKey, isFunction, latter, makeFunction, methodCall, next, nop, partiallyApplied, remove, sendWrapped, toCombinator, toEvent, toFieldExtractor, toFieldKey, toOption, toSimpleExtractor, _, _ref,
__slice = [].slice,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
_$jscoverage["Bacon.coffee"][1]++;
if ((_ref = this.jQuery || this.Zepto) != null) {
_ref.fn.asEventStream = function(eventName, selector, eventTransformer) {
var element;
if (eventTransformer == null) {
eventTransformer = _.id;
}
_$jscoverage["Bacon.coffee"][2]++;
if (isFunction(selector)) {
_$jscoverage["Bacon.coffee"][3]++;
eventTransformer = selector;
_$jscoverage["Bacon.coffee"][4]++;
selector = null;
}
_$jscoverage["Bacon.coffee"][5]++;
element = this;
_$jscoverage["Bacon.coffee"][6]++;
return new EventStream(function(sink) {
var handler, unbind;
_$jscoverage["Bacon.coffee"][7]++;
handler = function() {
var args, reply;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
_$jscoverage["Bacon.coffee"][8]++;
reply = sink(next(eventTransformer.apply(null, args)));
_$jscoverage["Bacon.coffee"][9]++;
if (reply === Bacon.noMore) {
_$jscoverage["Bacon.coffee"][10]++;
return unbind();
}
};
_$jscoverage["Bacon.coffee"][11]++;
unbind = function() {
return element.off(eventName, selector, handler);
};
_$jscoverage["Bacon.coffee"][12]++;
element.on(eventName, selector, handler);
_$jscoverage["Bacon.coffee"][13]++;
return unbind;
});
};
}
_$jscoverage["Bacon.coffee"][15]++;
Bacon = this.Bacon = {};
_$jscoverage["Bacon.coffee"][17]++;
Bacon.fromPromise = function(promise) {
_$jscoverage["Bacon.coffee"][18]++;
return new EventStream(function(sink) {
var onError, onSuccess;
_$jscoverage["Bacon.coffee"][20]++;
onSuccess = function(value) {
_$jscoverage["Bacon.coffee"][21]++;
sink(next(value));
_$jscoverage["Bacon.coffee"][22]++;
return sink(end());
};
_$jscoverage["Bacon.coffee"][23]++;
onError = function(e) {
_$jscoverage["Bacon.coffee"][24]++;
sink(new Error(e));
_$jscoverage["Bacon.coffee"][25]++;
return sink(end());
};
_$jscoverage["Bacon.coffee"][26]++;
promise.then(onSuccess, onError);
_$jscoverage["Bacon.coffee"][27]++;
return nop;
});
};
_$jscoverage["Bacon.coffee"][30]++;
Bacon.noMore = ["<no-more>"];
_$jscoverage["Bacon.coffee"][32]++;
Bacon.more = ["<more>"];
_$jscoverage["Bacon.coffee"][34]++;
Bacon.later = function(delay, value) {
_$jscoverage["Bacon.coffee"][35]++;
return Bacon.sequentially(delay, [value]);
};
_$jscoverage["Bacon.coffee"][37]++;
Bacon.sequentially = function(delay, values) {
var index, poll;
_$jscoverage["Bacon.coffee"][38]++;
index = -1;
_$jscoverage["Bacon.coffee"][39]++;
poll = function() {
var valueEvent;
_$jscoverage["Bacon.coffee"][40]++;
index++;
_$jscoverage["Bacon.coffee"][41]++;
valueEvent = toEvent(values[index]);
_$jscoverage["Bacon.coffee"][42]++;
if (index < values.length - 1) {
_$jscoverage["Bacon.coffee"][43]++;
return valueEvent;
} else {
_$jscoverage["Bacon.coffee"][45]++;
return [valueEvent, end()];
}
};
_$jscoverage["Bacon.coffee"][46]++;
return Bacon.fromPoll(delay, poll);
};
_$jscoverage["Bacon.coffee"][48]++;
Bacon.repeatedly = function(delay, values) {
var index, poll;
_$jscoverage["Bacon.coffee"][49]++;
index = -1;
_$jscoverage["Bacon.coffee"][50]++;
poll = function() {
_$jscoverage["Bacon.coffee"][51]++;
index++;
_$jscoverage["Bacon.coffee"][52]++;
return toEvent(values[index % values.length]);
};
_$jscoverage["Bacon.coffee"][53]++;
return Bacon.fromPoll(delay, poll);
};
_$jscoverage["Bacon.coffee"][55]++;
Bacon.fromCallback = function() {
var args, f;
f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
_$jscoverage["Bacon.coffee"][56]++;
f = makeFunction(f, args);
_$jscoverage["Bacon.coffee"][57]++;
return new EventStream(function(sink) {
var handler;
_$jscoverage["Bacon.coffee"][58]++;
handler = function(value) {
_$jscoverage["Bacon.coffee"][59]++;
sink(next(value));
_$jscoverage["Bacon.coffee"][60]++;
return sink(end());
};
_$jscoverage["Bacon.coffee"][61]++;
f(handler);
_$jscoverage["Bacon.coffee"][62]++;
return nop;
});
};
_$jscoverage["Bacon.coffee"][64]++;
Bacon.fromPoll = function(delay, poll) {
_$jscoverage["Bacon.coffee"][65]++;
return new EventStream(function(sink) {
var handler, id, unbind;
_$jscoverage["Bacon.coffee"][66]++;
id = void 0;
_$jscoverage["Bacon.coffee"][67]++;
handler = function() {
var event, events, reply, _i, _len, _results;
_$jscoverage["Bacon.coffee"][68]++;
events = _.toArray(poll());
_$jscoverage["Bacon.coffee"][69]++;
_results = [];
for (_i = 0, _len = events.length; _i < _len; _i++) {
event = events[_i];
_$jscoverage["Bacon.coffee"][70]++;
reply = sink(event);
_$jscoverage["Bacon.coffee"][71]++;
if (reply === Bacon.noMore || event.isEnd()) {
_$jscoverage["Bacon.coffee"][72]++;
_results.push(unbind());
} else {
_results.push(void 0);
}
}
return _results;
};
_$jscoverage["Bacon.coffee"][73]++;
unbind = function() {
_$jscoverage["Bacon.coffee"][74]++;
return clearInterval(id);
};
_$jscoverage["Bacon.coffee"][75]++;
id = setInterval(handler, delay);
_$jscoverage["Bacon.coffee"][76]++;
return unbind;
});
};
_$jscoverage["Bacon.coffee"][93]++;
Bacon.fromEventTarget = function(target, eventName, eventTransformer) {
if (eventTransformer == null) {
eventTransformer = _.id;
}
_$jscoverage["Bacon.coffee"][94]++;
return new EventStream(function(sink) {
var handler, unbind;
_$jscoverage["Bacon.coffee"][95]++;
handler = function() {
var args, reply;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
_$jscoverage["Bacon.coffee"][96]++;
reply = sink(next(eventTransformer.apply(null, args)));
_$jscoverage["Bacon.coffee"][97]++;
if (reply === Bacon.noMore) {
_$jscoverage["Bacon.coffee"][98]++;
return unbind();
}
};
_$jscoverage["Bacon.coffee"][100]++;
if (target.addEventListener) {
_$jscoverage["Bacon.coffee"][101]++;
unbind = function() {
return target.removeEventListener(eventName, handler, false);
};
_$jscoverage["Bacon.coffee"][102]++;
target.addEventListener(eventName, handler, false);
} else {
_$jscoverage["Bacon.coffee"][104]++;
unbind = function() {
return target.removeListener(eventName, handler);
};
_$jscoverage["Bacon.coffee"][105]++;
target.addListener(eventName, handler);
}
_$jscoverage["Bacon.coffee"][106]++;
return unbind;
});
};
_$jscoverage["Bacon.coffee"][108]++;
Bacon.interval = function(delay, value) {
var poll;
_$jscoverage["Bacon.coffee"][109]++;
if (value == null) {
value = {};
}
_$jscoverage["Bacon.coffee"][110]++;
poll = function() {
return next(value);
};
_$jscoverage["Bacon.coffee"][111]++;
return Bacon.fromPoll(delay, poll);
};
_$jscoverage["Bacon.coffee"][113]++;
Bacon.constant = function(value) {
_$jscoverage["Bacon.coffee"][114]++;
return new Property(sendWrapped([value], initial));
};
_$jscoverage["Bacon.coffee"][116]++;
Bacon.never = function() {
return Bacon.fromArray([]);
};
_$jscoverage["Bacon.coffee"][118]++;
Bacon.once = function(value) {
return Bacon.fromArray([value]);
};
_$jscoverage["Bacon.coffee"][120]++;
Bacon.fromArray = function(values) {
_$jscoverage["Bacon.coffee"][121]++;
return new EventStream(sendWrapped(values, next));
};
_$jscoverage["Bacon.coffee"][123]++;
sendWrapped = function(values, wrapper) {
_$jscoverage["Bacon.coffee"][124]++;
return function(sink) {
var value, _i, _len;
_$jscoverage["Bacon.coffee"][125]++;
for (_i = 0, _len = values.length; _i < _len; _i++) {
value = values[_i];
_$jscoverage["Bacon.coffee"][126]++;
sink(wrapper(value));
}
_$jscoverage["Bacon.coffee"][127]++;
sink(end());
_$jscoverage["Bacon.coffee"][128]++;
return nop;
};
};
_$jscoverage["Bacon.coffee"][130]++;
Bacon.combineAll = function(streams, f) {
var next, stream, _i, _len, _ref1;
_$jscoverage["Bacon.coffee"][131]++;
assertArray(streams);
_$jscoverage["Bacon.coffee"][132]++;
stream = _.head(streams);
_$jscoverage["Bacon.coffee"][133]++;
_ref1 = _.tail(streams);
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
next = _ref1[_i];
_$jscoverage["Bacon.coffee"][134]++;
stream = f(stream, next);
}
_$jscoverage["Bacon.coffee"][135]++;
return stream;
};
_$jscoverage["Bacon.coffee"][137]++;
Bacon.mergeAll = function(streams) {
_$jscoverage["Bacon.coffee"][138]++;
return Bacon.combineAll(streams, function(s1, s2) {
return s1.merge(s2);
});
};
_$jscoverage["Bacon.coffee"][140]++;
Bacon.combineAsArray = function() {
var more, next, stream, streams, _i, _len, _ref1;
streams = arguments[0], more = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
_$jscoverage["Bacon.coffee"][141]++;
if (!(streams instanceof Array)) {
_$jscoverage["Bacon.coffee"][142]++;
streams = [streams].concat(more);
}
_$jscoverage["Bacon.coffee"][143]++;
if (streams.length) {
_$jscoverage["Bacon.coffee"][144]++;
stream = (_.head(streams)).toProperty().map(function(x) {
return [x];
});
_$jscoverage["Bacon.coffee"][145]++;
_ref1 = _.tail(streams);
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
next = _ref1[_i];
_$jscoverage["Bacon.coffee"][146]++;
stream = stream.combine(next, function(xs, x) {
return xs.concat([x]);
});
}
_$jscoverage["Bacon.coffee"][147]++;
return stream;
} else {
_$jscoverage["Bacon.coffee"][149]++;
return Bacon.constant([]);
}
};
_$jscoverage["Bacon.coffee"][151]++;
Bacon.combineWith = function(streams, f) {
_$jscoverage["Bacon.coffee"][152]++;
return Bacon.combineAll(streams, function(s1, s2) {
_$jscoverage["Bacon.coffee"][153]++;
return s1.toProperty().combine(s2, f);
});
};
_$jscoverage["Bacon.coffee"][155]++;
Bacon.combineTemplate = function(template) {
var applyStreamValue, combinator, compile, compileTemplate, constantValue, current, funcs, mkContext, setValue, streams;
_$jscoverage["Bacon.coffee"][156]++;
funcs = [];
_$jscoverage["Bacon.coffee"][157]++;
streams = [];
_$jscoverage["Bacon.coffee"][158]++;
current = function(ctxStack) {
return ctxStack[ctxStack.length - 1];
};
_$jscoverage["Bacon.coffee"][159]++;
setValue = function(ctxStack, key, value) {
return current(ctxStack)[key] = value;
};
_$jscoverage["Bacon.coffee"][160]++;
applyStreamValue = function(key, index) {
return function(ctxStack, values) {
return setValue(ctxStack, key, values[index]);
};
};
_$jscoverage["Bacon.coffee"][161]++;
constantValue = function(key, value) {
return function(ctxStack, values) {
return setValue(ctxStack, key, value);
};
};
_$jscoverage["Bacon.coffee"][162]++;
mkContext = function(template) {
if (template instanceof Array) {
return [];
} else {
return {};
}
};
_$jscoverage["Bacon.coffee"][163]++;
compile = function(key, value) {
var popContext, pushContext;
_$jscoverage["Bacon.coffee"][164]++;
if (value instanceof Observable) {
_$jscoverage["Bacon.coffee"][165]++;
streams.push(value);
_$jscoverage["Bacon.coffee"][166]++;
return funcs.push(applyStreamValue(key, streams.length - 1));
} else if ((_$jscoverage["Bacon.coffee"][167]++, typeof value === "object")) {
_$jscoverage["Bacon.coffee"][168]++;
pushContext = function(key) {
return function(ctxStack, values) {
var newContext;
_$jscoverage["Bacon.coffee"][169]++;
newContext = mkContext(value);
_$jscoverage["Bacon.coffee"][170]++;
setValue(ctxStack, key, newContext);
_$jscoverage["Bacon.coffee"][171]++;
return ctxStack.push(newContext);
};
};
_$jscoverage["Bacon.coffee"][172]++;
popContext = function(ctxStack, values) {
return ctxStack.pop();
};
_$jscoverage["Bacon.coffee"][173]++;
funcs.push(pushContext(key));
_$jscoverage["Bacon.coffee"][174]++;
compileTemplate(value);
_$jscoverage["Bacon.coffee"][175]++;
return funcs.push(popContext);
} else {
_$jscoverage["Bacon.coffee"][177]++;
return funcs.push(constantValue(key, value));
}
};
_$jscoverage["Bacon.coffee"][178]++;
compileTemplate = function(template) {
return _.each(template, compile);
};
_$jscoverage["Bacon.coffee"][179]++;
compileTemplate(template);
_$jscoverage["Bacon.coffee"][180]++;
combinator = function(values) {
var ctxStack, f, rootContext, _i, _len;
_$jscoverage["Bacon.coffee"][181]++;
rootContext = mkContext(template);
_$jscoverage["Bacon.coffee"][182]++;
ctxStack = [rootContext];
_$jscoverage["Bacon.coffee"][183]++;
for (_i = 0, _len = funcs.length; _i < _len; _i++) {
f = funcs[_i];
_$jscoverage["Bacon.coffee"][184]++;
f(ctxStack, values);
}
_$jscoverage["Bacon.coffee"][185]++;
return rootContext;
};
_$jscoverage["Bacon.coffee"][186]++;
return Bacon.combineAsArray(streams).map(combinator);
};
_$jscoverage["Bacon.coffee"][188]++;
Event = (function() {
function Event() {}
_$jscoverage["Bacon.coffee"][189]++;
Event.prototype.isEvent = function() {
return true;
};
Event.prototype.isEnd = function() {
_$jscoverage["Bacon.coffee"][190]++;
return false;
};
Event.prototype.isInitial = function() {
_$jscoverage["Bacon.coffee"][191]++;
return false;
};
Event.prototype.isNext = function() {
_$jscoverage["Bacon.coffee"][192]++;
return false;
};
Event.prototype.isError = function() {
_$jscoverage["Bacon.coffee"][193]++;
return false;
};
Event.prototype.hasValue = function() {
_$jscoverage["Bacon.coffee"][194]++;
return false;
};
Event.prototype.filter = function(f) {
_$jscoverage["Bacon.coffee"][195]++;
return true;
};
Event.prototype.getOriginalEvent = function() {
_$jscoverage["Bacon.coffee"][197]++;
if (this.sourceEvent != null) {
_$jscoverage["Bacon.coffee"][198]++;
return this.sourceEvent.getOriginalEvent();
} else {
_$jscoverage["Bacon.coffee"][200]++;
return this;
}
};
Event.prototype.onDone = function(listener) {
_$jscoverage["Bacon.coffee"][201]++;
return listener();
};
return Event;
})();
_$jscoverage["Bacon.coffee"][203]++;
Next = (function(_super) {
__extends(Next, _super);
_$jscoverage["Bacon.coffee"][204]++;
function Next(value, sourceEvent) {
_$jscoverage["Bacon.coffee"][205]++;
this.value = isFunction(value) ? value : _.always(value);
}
Next.prototype.isNext = function() {
_$jscoverage["Bacon.coffee"][206]++;
return true;
};
Next.prototype.hasValue = function() {
_$jscoverage["Bacon.coffee"][207]++;
return true;
};
Next.prototype.fmap = function(f) {
_$jscoverage["Bacon.coffee"][208]++;
return this.apply(f(this.value()));
};
Next.prototype.apply = function(value) {
_$jscoverage["Bacon.coffee"][209]++;
return next(value, this.getOriginalEvent());
};
Next.prototype.filter = function(f) {
_$jscoverage["Bacon.coffee"][210]++;
return f(this.value());
};
Next.prototype.describe = function() {
_$jscoverage["Bacon.coffee"][211]++;
return this.value();
};
return Next;
})(Event);
_$jscoverage["Bacon.coffee"][213]++;
Initial = (function(_super) {
__extends(Initial, _super);
function Initial() {
return Initial.__super__.constructor.apply(this, arguments);
}
_$jscoverage["Bacon.coffee"][214]++;
Initial.prototype.isInitial = function() {
return true;
};
Initial.prototype.isNext = function() {
_$jscoverage["Bacon.coffee"][215]++;
return false;
};
Initial.prototype.apply = function(value) {
_$jscoverage["Bacon.coffee"][216]++;
return initial(value, this.getOriginalEvent());
};
Initial.prototype.toNext = function() {
_$jscoverage["Bacon.coffee"][217]++;
return new Next(this.value, this.getOriginalEvent());
};
return Initial;
})(Next);
_$jscoverage["Bacon.coffee"][219]++;
End = (function(_super) {
__extends(End, _super);
function End() {
return End.__super__.constructor.apply(this, arguments);
}
_$jscoverage["Bacon.coffee"][220]++;
End.prototype.isEnd = function() {
return true;
};
End.prototype.fmap = function() {
_$jscoverage["Bacon.coffee"][221]++;
return this;
};
End.prototype.apply = function() {
_$jscoverage["Bacon.coffee"][222]++;
return this;
};
End.prototype.describe = function() {
_$jscoverage["Bacon.coffee"][223]++;
return "<end>";
};
return End;
})(Event);
_$jscoverage["Bacon.coffee"][225]++;
Error = (function(_super) {
__extends(Error, _super);
_$jscoverage["Bacon.coffee"][226]++;
function Error(error) {
this.error = error;
}
Error.prototype.isError = function() {
_$jscoverage["Bacon.coffee"][227]++;
return true;
};
Error.prototype.fmap = function() {
_$jscoverage["Bacon.coffee"][228]++;
return this;
};
Error.prototype.apply = function() {
_$jscoverage["Bacon.coffee"][229]++;
return this;
};
Error.prototype.describe = function() {
_$jscoverage["Bacon.coffee"][230]++;
return "<error> " + this.error;
};
return Error;
})(Event);
_$jscoverage["Bacon.coffee"][232]++;
Observable = (function() {
_$jscoverage["Bacon.coffee"][233]++;
function Observable() {
this.flatMapLatest = __bind(this.flatMapLatest, this);
this.scan = __bind(this.scan, this);
this.takeUntil = __bind(this.takeUntil, this); _$jscoverage["Bacon.coffee"][234]++;
this.assign = this.onValue;
}
Observable.prototype.onValue = function() {
var args, f;
f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
_$jscoverage["Bacon.coffee"][236]++;
f = makeFunction(f, args);
_$jscoverage["Bacon.coffee"][237]++;
return this.subscribe(function(event) {
_$jscoverage["Bacon.coffee"][238]++;
if (event.hasValue()) {
return f(event.value());
}
});
};
Observable.prototype.onValues = function(f) {
_$jscoverage["Bacon.coffee"][240]++;
return this.onValue(function(args) {
return f.apply(null, args);
});
};
Observable.prototype.onError = function() {
var args, f;
f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
_$jscoverage["Bacon.coffee"][242]++;
f = makeFunction(f, args);
_$jscoverage["Bacon.coffee"][243]++;
return this.subscribe(function(event) {
_$jscoverage["Bacon.coffee"][244]++;
if (event.isError()) {
return f(event.error);
}
});
};
Observable.prototype.onEnd = function() {
var args, f;
f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
_$jscoverage["Bacon.coffee"][246]++;
f = makeFunction(f, args);
_$jscoverage["Bacon.coffee"][247]++;
return this.subscribe(function(event) {
_$jscoverage["Bacon.coffee"][248]++;
if (event.isEnd()) {
return f();
}
});
};
Observable.prototype.errors = function() {
_$jscoverage["Bacon.coffee"][249]++;
return this.filter(function() {
return false;
});
};
Observable.prototype.filter = function() {
var args, f;
f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
_$jscoverage["Bacon.coffee"][251]++;
f = makeFunction(f, args);
_$jscoverage["Bacon.coffee"][252]++;
return this.withHandler(function(event) {
_$jscoverage["Bacon.coffee"][253]++;
if (event.filter(f)) {
_$jscoverage["Bacon.coffee"][254]++;
return this.push(event);
} else {
_$jscoverage["Bacon.coffee"][256]++;
return Bacon.more;
}
});
};
Observable.prototype.takeWhile = function() {
var args, f;
f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
_$jscoverage["Bacon.coffee"][258]++;
f = makeFunction(f, args);
_$jscoverage["Bacon.coffee"][259]++;
return this.withHandler(function(event) {
_$jscoverage["Bacon.coffee"][260]++;
if (event.filter(f)) {
_$jscoverage["Bacon.coffee"][261]++;
return this.push(event);
} else {
_$jscoverage["Bacon.coffee"][263]++;
this.push(end());
_$jscoverage["Bacon.coffee"][264]++;
return Bacon.noMore;
}
});
};
Observable.prototype.endOnError = function() {
_$jscoverage["Bacon.coffee"][266]++;
return this.withHandler(function(event) {
_$jscoverage["Bacon.coffee"][267]++;
if (event.isError()) {
_$jscoverage["Bacon.coffee"][268]++;
this.push(event);
_$jscoverage["Bacon.coffee"][269]++;
return this.push(end());
} else {
_$jscoverage["Bacon.coffee"][271]++;
return this.push(event);
}
});
};
Observable.prototype.take = function(count) {
_$jscoverage["Bacon.coffee"][273]++;
assert("take: count must >= 1", count >= 1);
_$jscoverage["Bacon.coffee"][274]++;
return this.withHandler(function(event) {
_$jscoverage["Bacon.coffee"][275]++;
if (!event.hasValue()) {
_$jscoverage["Bacon.coffee"][276]++;
return this.push(event);
} else if ((_$jscoverage["Bacon.coffee"][277]++, count === 1)) {
_$jscoverage["Bacon.coffee"][278]++;
this.push(event);
_$jscoverage["Bacon.coffee"][279]++;
this.push(end());
_$jscoverage["Bacon.coffee"][280]++;
return Bacon.noMore;
} else {
_$jscoverage["Bacon.coffee"][282]++;
count--;
_$jscoverage["Bacon.coffee"][283]++;
return this.push(event);
}
});
};
Observable.prototype.map = function() {
var args, f;
f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
_$jscoverage["Bacon.coffee"][285]++;
f = makeFunction(f, args);
_$jscoverage["Bacon.coffee"][286]++;
return this.withHandler(function(event) {
_$jscoverage["Bacon.coffee"][287]++;
return this.push(event.fmap(f));
});
};
Observable.prototype.mapError = function() {
var args, f;
f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
_$jscoverage["Bacon.coffee"][289]++;
f = makeFunction(f, args);
_$jscoverage["Bacon.coffee"][290]++;
return this.withHandler(function(event) {
_$jscoverage["Bacon.coffee"][291]++;
if (event.isError()) {
_$jscoverage["Bacon.coffee"][292]++;
return this.push(next(f(event.error)));
} else {
_$jscoverage["Bacon.coffee"][294]++;
return this.push(event);
}
});
};
Observable.prototype.doAction = function() {
var args, f;
f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
_$jscoverage["Bacon.coffee"][296]++;
f = makeFunction(f, args);
_$jscoverage["Bacon.coffee"][297]++;
return this.withHandler(function(event) {
_$jscoverage["Bacon.coffee"][298]++;
if (event.hasValue()) {
f(event.value());
}
_$jscoverage["Bacon.coffee"][299]++;
return this.push(event);
});
};
Observable.prototype.takeUntil = function(stopper) {
var src;
_$jscoverage["Bacon.coffee"][301]++;
src = this;
_$jscoverage["Bacon.coffee"][302]++;
return this.withSubscribe(function(sink) {
var srcSink, stopperSink, unsubBoth, unsubSrc, unsubStopper, unsubscribed;
_$jscoverage["Bacon.coffee"][303]++;
unsubscribed = false;
_$jscoverage["Bacon.coffee"][304]++;
unsubSrc = nop;
_$jscoverage["Bacon.coffee"][305]++;
unsubStopper = nop;
_$jscoverage["Bacon.coffee"][306]++;
unsubBoth = function() {
unsubSrc();
unsubStopper();
return unsubscribed = true;
};
_$jscoverage["Bacon.coffee"][307]++;
srcSink = function(event) {
_$jscoverage["Bacon.coffee"][308]++;
if (event.isEnd()) {
_$jscoverage["Bacon.coffee"][309]++;
unsubStopper();
_$jscoverage["Bacon.coffee"][310]++;
sink(event);
_$jscoverage["Bacon.coffee"][311]++;
return Bacon.noMore;
} else {
_$jscoverage["Bacon.coffee"][313]++;
event.getOriginalEvent().onDone(function() {
var reply;
_$jscoverage["Bacon.coffee"][314]++;
if (!unsubscribed) {
_$jscoverage["Bacon.coffee"][315]++;
reply = sink(event);
_$jscoverage["Bacon.coffee"][316]++;
if (reply === Bacon.noMore) {
_$jscoverage["Bacon.coffee"][317]++;
return unsubBoth();
}
}
});
_$jscoverage["Bacon.coffee"][318]++;
return Bacon.more;
}
};
_$jscoverage["Bacon.coffee"][319]++;
stopperSink = function(event) {
_$jscoverage["Bacon.coffee"][320]++;
if (event.isError()) {
_$jscoverage["Bacon.coffee"][321]++;
return Bacon.more;
} else if (event.isEnd()) {
_$jscoverage["Bacon.coffee"][323]++;
return Bacon.noMore;
} else {
_$jscoverage["Bacon.coffee"][325]++;
unsubSrc();
_$jscoverage["Bacon.coffee"][326]++;
sink(end());
_$jscoverage["Bacon.coffee"][327]++;
return Bacon.noMore;
}
};
_$jscoverage["Bacon.coffee"][328]++;
unsubSrc = src.subscribe(srcSink);
_$jscoverage["Bacon.coffee"][329]++;
if (!unsubscribed) {
unsubStopper = stopper.subscribe(stopperSink);
}
_$jscoverage["Bacon.coffee"][330]++;
return unsubBoth;
});
};
Observable.prototype.skip = function(count) {
_$jscoverage["Bacon.coffee"][332]++;
assert("skip: count must >= 0", count >= 0);
_$jscoverage["Bacon.coffee"][333]++;
return this.withHandler(function(event) {
_$jscoverage["Bacon.coffee"][334]++;
if (!event.hasValue()) {
_$jscoverage["Bacon.coffee"][335]++;
return this.push(event);
} else if ((_$jscoverage["Bacon.coffee"][336]++, count > 0)) {
_$jscoverage["Bacon.coffee"][337]++;
count--;
_$jscoverage["Bacon.coffee"][338]++;
return Bacon.more;
} else {
_$jscoverage["Bacon.coffee"][340]++;
return this.push(event);
}
});
};
Observable.prototype.distinctUntilChanged = function() {
_$jscoverage["Bacon.coffee"][341]++;
return this.skipDuplicates();
};
Observable.prototype.skipDuplicates = function(isEqual) {
if (isEqual == null) {
isEqual = function(a, b) {
_$jscoverage["Bacon.coffee"][342]++;
return a === b;
};
}
_$jscoverage["Bacon.coffee"][343]++;
return this.withStateMachine(None, function(prev, event) {
_$jscoverage["Bacon.coffee"][344]++;
if (!event.hasValue()) {
_$jscoverage["Bacon.coffee"][345]++;
return [prev, [event]];
} else if (prev === None || !isEqual(prev.get(), event.value())) {
_$jscoverage["Bacon.coffee"][347]++;
return [new Some(event.value()), [event]];
} else {
_$jscoverage["Bacon.coffee"][349]++;
return [prev, []];
}
});
};
Observable.prototype.withStateMachine = function(initState, f) {
var state;
_$jscoverage["Bacon.coffee"][351]++;
state = initState;
_$jscoverage["Bacon.coffee"][352]++;
return this.withHandler(function(event) {
var fromF, newState, output, outputs, reply, _i, _len;
_$jscoverage["Bacon.coffee"][353]++;
fromF = f(state, event);
_$jscoverage["Bacon.coffee"][354]++;
assertArray(fromF);
_$jscoverage["Bacon.coffee"][355]++;
newState = fromF[0], outputs = fromF[1];
_$jscoverage["Bacon.coffee"][356]++;
assertArray(outputs);
_$jscoverage["Bacon.coffee"][357]++;
state = newState;
_$jscoverage["Bacon.coffee"][358]++;
reply = Bacon.more;
_$jscoverage["Bacon.coffee"][359]++;
for (_i = 0, _len = outputs.length; _i < _len; _i++) {
output = outputs[_i];
_$jscoverage["Bacon.coffee"][360]++;
reply = this.push(output);
_$jscoverage["Bacon.coffee"][361]++;
if (reply === Bacon.noMore) {
_$jscoverage["Bacon.coffee"][362]++;
return reply;
}
}
_$jscoverage["Bacon.coffee"][363]++;
return reply;
});
};
Observable.prototype.scan = function(seed, f) {
var acc, subscribe,
_this = this;
_$jscoverage["Bacon.coffee"][365]++;
f = toCombinator(f);
_$jscoverage["Bacon.coffee"][366]++;
acc = toOption(seed);
_$jscoverage["Bacon.coffee"][367]++;
subscribe = function(sink) {
var initSent, unsub;
_$jscoverage["Bacon.coffee"][368]++;
initSent = false;
_$jscoverage["Bacon.coffee"][369]++;
unsub = _this.subscribe(function(event) {
_$jscoverage["Bacon.coffee"][370]++;
if (event.hasValue()) {
_$jscoverage["Bacon.coffee"][371]++;
if (initSent && event.isInitial()) {
_$jscoverage["Bacon.coffee"][372]++;
return Bacon.more;
} else {
_$jscoverage["Bacon.coffee"][374]++;
initSent = true;
_$jscoverage["Bacon.coffee"][375]++;
acc = new Some(f(acc.getOrElse(void 0), event.value()));
_$jscoverage["Bacon.coffee"][376]++;
return sink(event.apply(acc.get()));
}
} else {
_$jscoverage["Bacon.coffee"][378]++;
if (event.isEnd()) {
initSent = true;
}
_$jscoverage["Bacon.coffee"][379]++;
return sink(event);
}
});
_$jscoverage["Bacon.coffee"][380]++;
if (!initSent) {
_$jscoverage["Bacon.coffee"][381]++;
acc.forEach(function(value) {
var reply;
_$jscoverage["Bacon.coffee"][382]++;
reply = sink(initial(value));
_$jscoverage["Bacon.coffee"][383]++;
if (reply === Bacon.noMore) {
_$jscoverage["Bacon.coffee"][384]++;
unsub();
_$jscoverage["Bacon.coffee"][385]++;
return unsub = nop;
}
});
}
_$jscoverage["Bacon.coffee"][386]++;
return unsub;
};
_$jscoverage["Bacon.coffee"][387]++;
return new Property(new PropertyDispatcher(subscribe).subscribe);
};
Observable.prototype.diff = function(start, f) {
_$jscoverage["Bacon.coffee"][390]++;
f = toCombinator(f);
_$jscoverage["Bacon.coffee"][391]++;
return this.scan([start], function(prevTuple, next) {
_$jscoverage["Bacon.coffee"][392]++;
return [next, f(prevTuple[0], next)];
}).filter(function(tuple) {
_$jscoverage["Bacon.coffee"][393]++;
return tuple.length === 2;
}).map(function(tuple) {
_$jscoverage["Bacon.coffee"][394]++;
return tuple[1];
});
};
Observable.prototype.flatMap = function(f) {
var root;
_$jscoverage["Bacon.coffee"][397]++;
root = this;
_$jscoverage["Bacon.coffee"][398]++;
return new EventStream(function(sink) {
var checkEnd, children, rootEnd, spawner, unbind, unsubRoot;
_$jscoverage["Bacon.coffee"][399]++;
children = [];
_$jscoverage["Bacon.coffee"][400]++;
rootEnd = false;
_$jscoverage["Bacon.coffee"][401]++;
unsubRoot = function() {};
_$jscoverage["Bacon.coffee"][402]++;
unbind = function() {
var unsubChild, _i, _len;
_$jscoverage["Bacon.coffee"][403]++;
unsubRoot();
_$jscoverage["Bacon.coffee"][404]++;
for (_i = 0, _len = children.length; _i < _len; _i++) {
unsubChild = children[_i];
_$jscoverage["Bacon.coffee"][405]++;
unsubChild();
}
_$jscoverage["Bacon.coffee"][406]++;
return children = [];
};
_$jscoverage["Bacon.coffee"][407]++;
checkEnd = function() {
_$jscoverage["Bacon.coffee"][408]++;
if (rootEnd && (children.length === 0)) {
_$jscoverage["Bacon.coffee"][409]++;
return sink(end());
}
};
_$jscoverage["Bacon.coffee"][410]++;
spawner = function(event) {
var child, childEnded, handler, removeChild, unsubChild;
_$jscoverage["Bacon.coffee"][411]++;
if (event.isEnd()) {
_$jscoverage["Bacon.coffee"][412]++;
rootEnd = true;
_$jscoverage["Bacon.coffee"][413]++;
return checkEnd();
} else if (event.isError()) {
_$jscoverage["Bacon.coffee"][415]++;
return sink(event);
} else {
_$jscoverage["Bacon.coffee"][417]++;
child = f(event.value());
_$jscoverage["Bacon.coffee"][418]++;
unsubChild = void 0;
_$jscoverage["Bacon.coffee"][419]++;
childEnded = false;
_$jscoverage["Bacon.coffee"][420]++;
removeChild = function() {
_$jscoverage["Bacon.coffee"][421]++;
if (unsubChild != null) {
remove(unsubChild, children);
}
_$jscoverage["Bacon.coffee"][422]++;
return checkEnd();
};
_$jscoverage["Bacon.coffee"][423]++;
handler = function(event) {
var reply;
_$jscoverage["Bacon.coffee"][424]++;
if (event.isEnd()) {
_$jscoverage["Bacon.coffee"][425]++;
removeChild();
_$jscoverage["Bacon.coffee"][426]++;
childEnded = true;
_$jscoverage["Bacon.coffee"][427]++;
return Bacon.noMore;
} else {
_$jscoverage["Bacon.coffee"][429]++;
if (event instanceof Initial) {
_$jscoverage["Bacon.coffee"][431]++;
event = event.toNext();
}
_$jscoverage["Bacon.coffee"][432]++;
reply = sink(event);
_$jscoverage["Bacon.coffee"][433]++;
if (reply === Bacon.noMore) {
_$jscoverage["Bacon.coffee"][434]++;
unbind();
}
_$jscoverage["Bacon.coffee"][435]++;
return reply;
}
};
_$jscoverage["Bacon.coffee"][436]++;
unsubChild = child.subscribe(handler);
_$jscoverage["Bacon.coffee"][437]++;
if (!childEnded) {
return children.push(unsubChild);
}
}
};
_$jscoverage["Bacon.coffee"][438]++;
unsubRoot = root.subscribe(spawner);
_$jscoverage["Bacon.coffee"][439]++;
return unbind;
});
};
Observable.prototype.flatMapLatest = function(f) {
var stream,
_this = this;
_$jscoverage["Bacon.coffee"][441]++;
stream = this.toEventStream();
_$jscoverage["Bacon.coffee"][442]++;
return stream.flatMap(function(value) {
_$jscoverage["Bacon.coffee"][443]++;
return f(value).takeUntil(stream);
});
};
Observable.prototype.not = function() {
_$jscoverage["Bacon.coffee"][444]++;
return this.map(function(x) {
return !x;
});
};
Observable.prototype.log = function() {
_$jscoverage["Bacon.coffee"][446]++;
this.subscribe(function(event) {
return console.log(event.describe());
});
_$jscoverage["Bacon.coffee"][447]++;
return this;
};
Observable.prototype.slidingWindow = function(n) {
_$jscoverage["Bacon.coffee"][449]++;
return this.scan([], function(window, value) {
_$jscoverage["Bacon.coffee"][450]++;
return window.concat([value]).slice(-n);
});
};
return Observable;
})();
_$jscoverage["Bacon.coffee"][452]++;
EventStream = (function(_super) {
__extends(EventStream, _super);
_$jscoverage["Bacon.coffee"][453]++;
function EventStream(subscribe) {
var dispatcher;
_$jscoverage["Bacon.coffee"][454]++;
EventStream.__super__.constructor.call(this);
_$jscoverage["Bacon.coffee"][455]++;
assertFunction(subscribe);
_$jscoverage["Bacon.coffee"][456]++;
dispatcher = new Dispatcher(subscribe);
_$jscoverage["Bacon.coffee"][457]++;
this.subscribe = dispatcher.subscribe;
_$jscoverage["Bacon.coffee"][458]++;
this.hasSubscribers = dispatcher.hasSubscribers;
}
EventStream.prototype.map = function() {
var args, p;
p = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
_$jscoverage["Bacon.coffee"][460]++;
if (p instanceof Property) {
_$jscoverage["Bacon.coffee"][461]++;
return p.sampledBy(this, former);
} else {
_$jscoverage["Bacon.coffee"][463]++;
return EventStream.__super__.map.apply(this, [p].concat(__slice.call(args)));
}
};
EventStream.prototype.filter = function() {
var args, p;
p = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
_$jscoverage["Bacon.coffee"][465]++;
if (p instanceof Property) {
_$jscoverage["Bacon.coffee"][466]++;
return p.sampledBy(this, function(p, s) {
return [p, s];
}).filter(function(_arg) {
var p, s;
p = _arg[0], s = _arg[1];
_$jscoverage["Bacon.coffee"][467]++;
return p;
}).map(function(_arg) {
var p, s;
p = _arg[0], s = _arg[1];
_$jscoverage["Bacon.coffee"][468]++;
return s;
});
} else {
_$jscoverage["Bacon.coffee"][470]++;
return EventStream.__super__.filter.apply(this, [p].concat(__slice.call(args)));
}
};
EventStream.prototype.delay = function(delay) {
_$jscoverage["Bacon.coffee"][472]++;
return this.flatMap(function(value) {
_$jscoverage["Bacon.coffee"][473]++;
return Bacon.later(delay, value);
});
};
EventStream.prototype.throttle = function(delay) {
_$jscoverage["Bacon.coffee"][475]++;
return this.flatMapLatest(function(value) {
_$jscoverage["Bacon.coffee"][476]++;
return Bacon.later(delay, value);
});
};
EventStream.prototype.throttle2 = function(delay) {
_$jscoverage["Bacon.coffee"][479]++;
return this.bufferWithTime(delay).map(function(values) {
return values[values.length - 1];
});
};
EventStream.prototype.bufferWithTime = function(delay) {
var schedule,
_this = this;
_$jscoverage["Bacon.coffee"][482]++;
schedule = function(buffer) {
return buffer.schedule();
};
_$jscoverage["Bacon.coffee"][483]++;
return this.buffer(delay, schedule, schedule);
};
EventStream.prototype.bufferWithCount = function(count) {
var flushOnCount;
_$jscoverage["Bacon.coffee"][486]++;
flushOnCount = function(buffer) {
if (buffer.values.length === count) {
return buffer.flush();
}
};
_$jscoverage["Bacon.coffee"][487]++;
return this.buffer(0, flushOnCount);
};
EventStream.prototype.buffer = function(delay, onInput, onFlush) {
var buffer, delayMs, reply;
if (onInput == null) {
onInput = (_$jscoverage["Bacon.coffee"][489]++, function() {});
}
if (onFlush == null) {
onFlush = (function() {});
}
_$jscoverage["Bacon.coffee"][490]++;
buffer = {
scheduled: false,
end: null,
values: [],
flush: function() {
var reply;
_$jscoverage["Bacon.coffee"][495]++;
this.scheduled = false;
_$jscoverage["Bacon.coffee"][496]++;
if (this.values.length > 0) {
_$jscoverage["Bacon.coffee"][497]++;
reply = this.push(next(this.values));
_$jscoverage["Bacon.coffee"][498]++;
this.values = [];
_$jscoverage["Bacon.coffee"][499]++;
if (this.end != null) {
_$jscoverage["Bacon.coffee"][500]++;
return this.push(this.end);
} else if (reply !== Bacon.noMore) {
_$jscoverage["Bacon.coffee"][502]++;
return onFlush(this);
}
} else {
_$jscoverage["Bacon.coffee"][504]++;
if (this.end != null) {
return this.push(this.end);
}
}
},
schedule: function() {
var _this = this;
_$jscoverage["Bacon.coffee"][506]++;
if (!this.scheduled) {
_$jscoverage["Bacon.coffee"][507]++;
this.scheduled = true;
_$jscoverage["Bacon.coffee"][508]++;
return delay(function() {
return _this.flush();
});
}
}
};
_$jscoverage["Bacon.coffee"][510]++;
reply = Bacon.more;
_$jscoverage["Bacon.coffee"][511]++;
if (!isFunction(delay)) {
_$jscoverage["Bacon.coffee"][512]++;
delayMs = delay;
_$jscoverage["Bacon.coffee"][513]++;
delay = function(f) {
return setTimeout(f, delayMs);
};
}
_$jscoverage["Bacon.coffee"][514]++;
return this.withHandler(function(event) {
_$jscoverage["Bacon.coffee"][515]++;
buffer.push = this.push;
_$jscoverage["Bacon.coffee"][516]++;
if (event.isError()) {
_$jscoverage["Bacon.coffee"][517]++;
reply = this.push(event);
} else if (event.isEnd()) {
_$jscoverage["Bacon.coffee"][519]++;
buffer.end = event;
_$jscoverage["Bacon.coffee"][520]++;
if (!buffer.scheduled) {
_$jscoverage["Bacon.coffee"][521]++;
buffer.flush();
}
} else {
_$jscoverage["Bacon.coffee"][523]++;
buffer.values.push(event.value());
_$jscoverage["Bacon.coffee"][524]++;
onInput(buffer);
}
_$jscoverage["Bacon.coffee"][525]++;
return reply;
});
};
EventStream.prototype.merge = function(right) {
var left;
_$jscoverage["Bacon.coffee"][528]++;
left = this;
_$jscoverage["Bacon.coffee"][529]++;
return new EventStream(function(sink) {
var ends, smartSink, unsubBoth, unsubLeft, unsubRight, unsubscribed;
_$jscoverage["Bacon.coffee"][530]++;
unsubLeft = nop;
_$jscoverage["Bacon.coffee"][531]++;
unsubRight = nop;
_$jscoverage["Bacon.coffee"][532]++;
unsubscribed = false;
_$jscoverage["Bacon.coffee"][533]++;
unsubBoth = function() {
unsubLeft();
unsubRight();
return unsubscribed = true;
};
_$jscoverage["Bacon.coffee"][534]++;
ends = 0;
_$jscoverage["Bacon.coffee"][535]++;
smartSink = function(event) {
var reply;
_$jscoverage["Bacon.coffee"][536]++;
if (event.isEnd()) {
_$jscoverage["Bacon.coffee"][537]++;
ends++;
_$jscoverage["Bacon.coffee"][538]++;
if (ends === 2) {
_$jscoverage["Bacon.coffee"][539]++;
return sink(end());
} else {
_$jscoverage["Bacon.coffee"][541]++;
return Bacon.more;
}
} else {
_$jscoverage["Bacon.coffee"][543]++;
reply = sink(event);
_$jscoverage["Bacon.coffee"][544]++;
if (reply === Bacon.noMore) {
unsubBoth();
}
_$jscoverage["Bacon.coffee"][545]++;
return reply;
}
};
_$jscoverage["Bacon.coffee"][546]++;
unsubLeft = left.subscribe(smartSink);
_$jscoverage["Bacon.coffee"][547]++;
if (!unsubscribed) {
unsubRight = right.subscribe(smartSink);
}
_$jscoverage["Bacon.coffee"][548]++;
return unsubBoth;
});
};
EventStream.prototype.toProperty = function(initValue) {
_$jscoverage["Bacon.coffee"][551]++;
if (arguments.length === 0) {
initValue = None;
}
_$jscoverage["Bacon.coffee"][552]++;
return this.scan(initValue, latter);
};
EventStream.prototype.toEventStream = function() {
_$jscoverage["Bacon.coffee"][554]++;
return this;
};
EventStream.prototype.concat = function(right) {
var left;
_$jscoverage["Bacon.coffee"][557]++;
left = this;
_$jscoverage["Bacon.coffee"][558]++;
return new EventStream(function(sink) {
var unsub;
_$jscoverage["Bacon.coffee"][559]++;
unsub = left.subscribe(function(e) {
_$jscoverage["Bacon.coffee"][560]++;
if (e.isEnd()) {
_$jscoverage["Bacon.coffee"][561]++;
return unsub = right.subscribe(sink);
} else {
_$jscoverage["Bacon.coffee"][563]++;
return sink(e);
}
});
_$jscoverage["Bacon.coffee"][564]++;
return function() {
return unsub();
};
});
};
EventStream.prototype.awaiting = function(other) {
_$jscoverage["Bacon.coffee"][567]++;
return this.map(true).merge(other.map(false)).toProperty(false);
};
EventStream.prototype.startWith = function(seed) {
_$jscoverage["Bacon.coffee"][570]++;
return Bacon.once(seed).concat(this);
};
EventStream.prototype.mapEnd = function() {
var args, f;
f = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
_$jscoverage["Bacon.coffee"][573]++;
f = makeFunction(f, args);
_$jscoverage["Bacon.coffee"][574]++;
return this.withHandler(function(event) {
_$jscoverage["Bacon.coffee"][575]++;
if (event.isEnd()) {
_$jscoverage["Bacon.coffee"][576]++;
this.push(next(f(event)));
_$jscoverage["Bacon.coffee"][577]++;
this.push(end());
_$jscoverage["Bacon.coffee"][578]++;
return Bacon.noMore;
} else {
_$jscoverage["Bacon.coffee"][580]++;
return this.push(event);
}
});
};
EventStream.prototype.withHandler = function(handler) {
var dispatcher;
_$jscoverage["Bacon.coffee"][583]++;
dispatcher = new Dispatcher(this.subscribe, handler);
_$jscoverage["Bacon.coffee"][584]++;
return new EventStream(dispatcher.subscribe);
};
EventStream.prototype.withSubscribe = function(subscribe) {
_$jscoverage["Bacon.coffee"][585]++;
return new EventStream(subscribe);
};
return EventStream;
})(Observable);
_$jscoverage["Bacon.coffee"][587]++;
Property = (function(_super) {
__extends(Property, _super);
_$jscoverage["Bacon.coffee"][588]++;
function Property(subscribe) {
var combine,
_this = this;
this.subscribe = subscribe;
this.toEventStream = __bind(this.toEventStream, this);
this.toProperty = __bind(this.toProperty, this);
this.changes = __bind(this.changes, this);
this.sample = __bind(this.sample, this);
_$jscoverage["Bacon.coffee"][589]++;
Property.__super__.constructor.call(this);
_$jscoverage["Bacon.coffee"][590]++;
combine = function(other, leftSink, rightSink) {
var myVal, otherVal;
_$jscoverage["Bacon.coffee"][591]++;
myVal = None;
_$jscoverage["Bacon.coffee"][592]++;
otherVal = None;
_$jscoverage["Bacon.coffee"][593]++;
return new Property(function(sink) {
var checkEnd, combiningSink, initialSent, myEnd, mySink, otherEnd, otherSink, unsubBoth, unsubMe, unsubOther, unsubscribed;
_$jscoverage["Bacon.coffee"][594]++;
unsubscribed = false;
_$jscoverage["Bacon.coffee"][595]++;
unsubMe = nop;
_$jscoverage["Bacon.coffee"][596]++;
unsubOther = nop;
_$jscoverage["Bacon.coffee"][597]++;
unsubBoth = function() {
unsubMe();
unsubOther();
return unsubscribed = true;
};
_$jscoverage["Bacon.coffee"][598]++;
myEnd = false;
_$jscoverage["Bacon.coffee"][599]++;
otherEnd = false;
_$jscoverage["Bacon.coffee"][600]++;
checkEnd = function() {
var reply;
_$jscoverage["Bacon.coffee"][601]++;
if (myEnd && otherEnd) {
_$jscoverage["Bacon.coffee"][602]++;
reply = sink(end());
_$jscoverage["Bacon.coffee"][603]++;
if (reply === Bacon.noMore) {
unsubBoth();
}
_$jscoverage["Bacon.coffee"][604]++;
return reply;
}
};
_$jscoverage["Bacon.coffee"][605]++;
initialSent = false;
_$jscoverage["Bacon.coffee"][606]++;
combiningSink = function(markEnd, setValue, thisSink) {
_$jscoverage["Bacon.coffee"][607]++;
return function(event) {
var reply;
_$jscoverage["Bacon.coffee"][608]++;
if (event.isEnd()) {
_$jscoverage["Bacon.coffee"][609]++;
markEnd();
_$jscoverage["Bacon.coffee"][610]++;
checkEnd();
_$jscoverage["Bacon.coffee"][611]++;
return Bacon.noMore;
} else if (event.isError()) {
_$jscoverage["Bacon.coffee"][613]++;
reply = sink(event);
_$jscoverage["Bacon.coffee"][614]++;
if (reply === Bacon.noMore) {
unsubBoth();
}
_$jscoverage["Bacon.coffee"][615]++;
return reply;
} else {
_$jscoverage["Bacon.coffee"][617]++;
setValue(new Some(event.value()));
_$jscoverage["Bacon.coffee"][618]++;
if (myVal.isDefined && otherVal.isDefined) {
_$jscoverage["Bacon.coffee"][619]++;
if (initialSent && event.isInitial()) {
_$jscoverage["Bacon.coffee"][621]++;
return Bacon.more;
} else {
_$jscoverage["Bacon.coffee"][623]++;
initialSent = true;
_$jscoverage["Bacon.coffee"][624]++;
reply = thisSink(sink, event, myVal.value, otherVal.value);
_$jscoverage["Bacon.coffee"][625]++;
if (reply === Bacon.noMore) {
unsubBoth();
}
_$jscoverage["Bacon.coffee"][626]++;
return reply;
}
} else {
_$jscoverage["Bacon.coffee"][628]++;
return Bacon.more;
}
}
};
};
_$jscoverage["Bacon.coffee"][630]++;
mySink = combiningSink((function() {
return myEnd = true;
}), (function(value) {
return myVal = value;
}), leftSink);
_$jscoverage["Bacon.coffee"][631]++;
otherSink = combiningSink((function() {
return otherEnd = true;
}), (function(value) {
return otherVal = value;
}), rightSink);
_$jscoverage["Bacon.coffee"][632]++;
unsubMe = _this.subscribe(mySink);
_$jscoverage["Bacon.coffee"][633]++;
if (!unsubscribed) {
unsubOther = other.subscribe(otherSink);
}
_$jscoverage["Bacon.coffee"][634]++;
return unsubBoth;
});
};
_$jscoverage["Bacon.coffee"][635]++;
this.combine = function(other, f) {
var combinator, combineAndPush;
_$jscoverage["Bacon.coffee"][636]++;
combinator = toCombinator(f);
_$jscoverage["Bacon.coffee"][637]++;
combineAndPush = function(sink, event, myVal, otherVal) {
return sink(event.apply(combinator(myVal, otherVal)));
};
_$jscoverage["Bacon.coffee"][638]++;
return combine(other, combineAndPush, combineAndPush);
};
_$jscoverage["Bacon.coffee"][639]++;
this.sampledBy = function(sampler, combinator) {
var pushPropertyValue;
if (combinator == null) {
combinator = former;
}
_$jscoverage["Bacon.coffee"][640]++;
combinator = toCombinator(combinator);
_$jscoverage["Bacon.coffee"][641]++;
pushPropertyValue = function(sink, event, propertyVal, streamVal) {
return sink(event.apply(combinator(propertyVal, streamVal)));
};
_$jscoverage["Bacon.coffee"][642]++;
return combine(sampler, nop, pushPropertyValue).changes().takeUntil(sampler.filter(false).mapEnd());
};
}
Property.prototype.sample = function(interval) {
_$jscoverage["Bacon.coffee"][644]++;
return this.sampledBy(Bacon.interval(interval, {}));
};
Property.prototype.changes = function() {
var _this = this;
_$jscoverage["Bacon.coffee"][646]++;
return new EventStream(function(sink) {
_$jscoverage["Bacon.coffee"][647]++;
return _this.subscribe(function(event) {
_$jscoverage["Bacon.coffee"][648]++;
if (!event.isInitial()) {
return sink(event);
}
});
});
};
Property.prototype.withHandler = function(handler) {
_$jscoverage["Bacon.coffee"][650]++;
return new Property(new PropertyDispatcher(this.subscribe, handler).subscribe);
};
Property.prototype.withSubscribe = function(subscribe) {
_$jscoverage["Bacon.coffee"][651]++;
return new Property(new PropertyDispatcher(subscribe).subscribe);
};
Property.prototype.toProperty = function() {
_$jscoverage["Bacon.coffee"][652]++;
return this;
};
Property.prototype.toEventStream = function() {
var _this = this;
_$jscoverage["Bacon.coffee"][654]++;
return new EventStream(function(sink) {
_$jscoverage["Bacon.coffee"][655]++;
return _this.subscribe(function(event) {
_$jscoverage["Bacon.coffee"][656]++;
if (event.isInitial()) {
event = event.toNext();
}
_$jscoverage["Bacon.coffee"][657]++;
return sink(event);
});
});
};
Property.prototype.and = function(other) {
_$jscoverage["Bacon.coffee"][658]++;
return this.combine(other, function(x, y) {
return x && y;
});
};
Property.prototype.or = function(other) {
_$jscoverage["Bacon.coffee"][659]++;
return this.combine(other, function(x, y) {
return x || y;
});
};
Property.prototype.decode = function(cases) {
_$jscoverage["Bacon.coffee"][660]++;
return this.combine(Bacon.combineTemplate(cases), function(key, values) {
return values[key];
});
};
Property.prototype.delay = function(delay) {
_$jscoverage["Bacon.coffee"][661]++;
return this.delayChanges(function(changes) {
return changes.delay(delay);
});
};
Property.prototype.throttle = function(delay) {
_$jscoverage["Bacon.coffee"][662]++;
return this.delayChanges(function(changes) {
return changes.throttle(delay);
});
};
Property.prototype.throttle2 = function(delay) {
_$jscoverage["Bacon.coffee"][663]++;
return this.delayChanges(function(changes) {
return changes.throttle2(delay);
});
};
Property.prototype.delayChanges = function(f) {
_$jscoverage["Bacon.coffee"][664]++;
return addPropertyInitValueToStream(this, f(this.changes()));
};
return Property;
})(Observable);
_$jscoverage["Bacon.coffee"][666]++;
addPropertyInitValueToStream = function(property, stream) {
var getInitValue;
_$jscoverage["Bacon.coffee"][667]++;
getInitValue = function(property) {
var value;
_$jscoverage["Bacon.coffee"][668]++;
value = None;
_$jscoverage["Bacon.coffee"][669]++;
property.subscribe(function(event) {
_$jscoverage["Bacon.coffee"][670]++;
if (event.isInitial()) {
_$jscoverage["Bacon.coffee"][671]++;
value = new Some(event.value());
}
_$jscoverage["Bacon.coffee"][672]++;
return Bacon.noMore;
});
_$jscoverage["Bacon.coffee"][673]++;
return value;
};
_$jscoverage["Bacon.coffee"][674]++;
return stream.toProperty(getInitValue(property));
};
_$jscoverage["Bacon.coffee"][676]++;
Dispatcher = (function() {
_$jscoverage["Bacon.coffee"][677]++;
function Dispatcher(subscribe, handleEvent) {
var ended, removeSink, sinks, unsubscribeFromSource,
_this = this;
_$jscoverage["Bacon.coffee"][678]++;
if (subscribe == null) {
subscribe = function() {
return nop;
};
}
_$jscoverage["Bacon.coffee"][679]++;
sinks = [];
_$jscoverage["Bacon.coffee"][680]++;
ended = false;
_$jscoverage["Bacon.coffee"][681]++;
this.hasSubscribers = function() {
return sinks.length > 0;
};
_$jscoverage["Bacon.coffee"][682]++;
unsubscribeFromSource = nop;
_$jscoverage["Bacon.coffee"][683]++;
removeSink = function(sink) {
_$jscoverage["Bacon.coffee"][684]++;
return remove(sink, sinks);
};
_$jscoverage["Bacon.coffee"][685]++;
this.push = function(event) {
var done, reply, sink, waiters, _i, _len, _ref1;
_$jscoverage["Bacon.coffee"][686]++;
waiters = void 0;
_$jscoverage["Bacon.coffee"][687]++;
done = function() {
var w, ws, _i, _len;
_$jscoverage["Bacon.coffee"][688]++;
if (waiters != null) {
_$jscoverage["Bacon.coffee"][689]++;
ws = waiters;
_$jscoverage["Bacon.coffee"][690]++;
waiters = void 0;
_$jscoverage["Bacon.coffee"][691]++;
for (_i = 0, _len = ws.length; _i < _len; _i++) {
w = ws[_i];
w();
}
}
_$jscoverage["Bacon.coffee"][692]++;
return event.onDone = Event.prototype.onDone;
};
_$jscoverage["Bacon.coffee"][693]++;
event.onDone = function(listener) {
_$jscoverage["Bacon.coffee"][694]++;
if ((waiters != null) && !_.contains(waiters, listener)) {
_$jscoverage["Bacon.coffee"][695]++;
return waiters.push(listener);
} else {
_$jscoverage["Bacon.coffee"][697]++;
return waiters = [listener];
}
};
_$jscoverage["Bacon.coffee"][698]++;
assertEvent(event);
_$jscoverage["Bacon.coffee"][699]++;
_ref1 = cloneArray(sinks);
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
sink = _ref1[_i];
_$jscoverage["Bacon.coffee"][700]++;
reply = sink(event);
_$jscoverage["Bacon.coffee"][701]++;
if (reply === Bacon.noMore || event.isEnd()) {
removeSink(sink);
}
}
_$jscoverage["Bacon.coffee"][702]++;
done();
_$jscoverage["Bacon.coffee"][703]++;
if (_this.hasSubscribers()) {
_$jscoverage["Bacon.coffee"][704]++;
return Bacon.more;
} else {
_$jscoverage["Bacon.coffee"][706]++;
return Bacon.noMore;
}
};
_$jscoverage["Bacon.coffee"][707]++;
if (handleEvent == null) {
handleEvent = function(event) {
return this.push(event);
};
}
_$jscoverage["Bacon.coffee"][708]++;
this.handleEvent = function(event) {
_$jscoverage["Bacon.coffee"][709]++;
assertEvent(event);
_$jscoverage["Bacon.coffee"][710]++;
if (event.isEnd()) {
_$jscoverage["Bacon.coffee"][711]++;
ended = true;
}
_$jscoverage["Bacon.coffee"][712]++;
return handleEvent.apply(_this, [event]);
};
_$jscoverage["Bacon.coffee"][713]++;
this.subscribe = function(sink) {
_$jscoverage["Bacon.coffee"][714]++;
if (ended) {
_$jscoverage["Bacon.coffee"][715]++;
sink(end());
_$jscoverage["Bacon.coffee"][716]++;
return nop;
} else {
_$jscoverage["Bacon.coffee"][718]++;
assertFunction(sink);
_$jscoverage["Bacon.coffee"][719]++;
sinks.push(sink);
_$jscoverage["Bacon.coffee"][720]++;
if (sinks.length === 1) {
_$jscoverage["Bacon.coffee"][721]++;
unsubscribeFromSource = subscribe(_this.handleEvent);
}
_$jscoverage["Bacon.coffee"][722]++;
assertFunction(unsubscribeFromSource);
_$jscoverage["Bacon.coffee"][723]++;
return function() {
_$jscoverage["Bacon.coffee"][724]++;
removeSink(sink);
_$jscoverage["Bacon.coffee"][725]++;
if (!_this.hasSubscribers()) {
return unsubscribeFromSource();
}
};
}
};
}
return Dispatcher;
})();
_$jscoverage["Bacon.coffee"][727]++;
PropertyDispatcher = (function(_super) {
__extends(PropertyDispatcher, _super);
_$jscoverage["Bacon.coffee"][728]++;
function PropertyDispatcher(subscribe, handleEvent) {
var current, ended, push,
_this = this;
_$jscoverage["Bacon.coffee"][729]++;
PropertyDispatcher.__super__.constructor.call(this, subscribe, handleEvent);
_$jscoverage["Bacon.coffee"][730]++;
current = None;
_$jscoverage["Bacon.coffee"][731]++;
push = this.push;
_$jscoverage["Bacon.coffee"][732]++;
subscribe = this.subscribe;
_$jscoverage["Bacon.coffee"][733]++;
ended = false;
_$jscoverage["Bacon.coffee"][734]++;
this.push = function(event) {
_$jscoverage["Bacon.coffee"][735]++;
if (event.isEnd()) {
_$jscoverage["Bacon.coffee"][736]++;
ended = true;
}
_$jscoverage["Bacon.coffee"][737]++;
if (event.hasValue()) {
_$jscoverage["Bacon.coffee"][738]++;
current = new Some(event.value());
}
_$jscoverage["Bacon.coffee"][739]++;
return push.apply(_this, [event]);
};
_$jscoverage["Bacon.coffee"][740]++;
this.subscribe = function(sink) {
var initSent, reply, shouldBounceInitialValue;
_$jscoverage["Bacon.coffee"][741]++;
initSent = false;
_$jscoverage["Bacon.coffee"][746]++;
shouldBounceInitialValue = function() {
return _this.hasSubscribers() || ended;
};
_$jscoverage["Bacon.coffee"][747]++;
reply = current.filter(shouldBounceInitialValue).map(function(val) {
_$jscoverage["Bacon.coffee"][748]++;
return sink(initial(val));
});
_$jscoverage["Bacon.coffee"][749]++;
if (reply.getOrElse(Bacon.more) === Bacon.noMore) {
_$jscoverage["Bacon.coffee"][750]++;
return nop;
} else if (ended) {
_$jscoverage["Bacon.coffee"][752]++;
sink(end());
_$jscoverage["Bacon.coffee"][753]++;
return nop;
} else {
_$jscoverage["Bacon.coffee"][755]++;
return subscribe.apply(_this, [sink]);
}
};
}
return PropertyDispatcher;
})(Dispatcher);
_$jscoverage["Bacon.coffee"][757]++;
Bus = (function(_super) {
__extends(Bus, _super);
_$jscoverage["Bacon.coffee"][758]++;
function Bus() {
var dispatcher, ended, guardedSink, sink, subscribeAll, subscribeInput, subscribeThis, subscriptions, unsubAll, unsubscribeInput,
_this = this;
_$jscoverage["Bacon.coffee"][759]++;
sink = void 0;
_$jscoverage["Bacon.coffee"][760]++;
subscriptions = [];
_$jscoverage["Bacon.coffee"][761]++;
ended = false;
_$jscoverage["Bacon.coffee"][762]++;
guardedSink = function(input) {
return function(event) {
_$jscoverage["Bacon.coffee"][763]++;
if (event.isEnd()) {
_$jscoverage["Bacon.coffee"][764]++;
unsubscribeInput(input);
_$jscoverage["Bacon.coffee"][765]++;
return Bacon.noMore;
} else {
_$jscoverage["Bacon.coffee"][767]++;
return sink(event);
}
};
};
_$jscoverage["Bacon.coffee"][768]++;
unsubAll = function() {
var sub, _i, _len;
_$jscoverage["Bacon.coffee"][769]++;
for (_i = 0, _len = subscriptions.length; _i < _len; _i++) {
sub = subscriptions[_i];
_$jscoverage["Bacon.coffee"][770]++;
if (sub.unsub != null) {
_$jscoverage["Bacon.coffee"][771]++;
sub.unsub();
}
}
_$jscoverage["Bacon.coffee"][772]++;
return subscriptions = [];
};
_$jscoverage["Bacon.coffee"][773]++;
subscribeInput = function(subscription) {
_$jscoverage["Bacon.coffee"][774]++;
return subscription.unsub = subscription.input.subscribe(guardedSink(subscription.input));
};
_$jscoverage["Bacon.coffee"][775]++;
unsubscribeInput = function(input) {
var i, sub, _i, _len;
_$jscoverage["Bacon.coffee"][776]++;
for (i = _i = 0, _len = subscriptions.length; _i < _len; i = ++_i) {
sub = subscriptions[i];
_$jscoverage["Bacon.coffee"][777]++;
if (sub.input === input) {
_$jscoverage["Bacon.coffee"][778]++;
if (sub.unsub != null) {
sub.unsub();
}
_$jscoverage["Bacon.coffee"][779]++;
subscriptions.splice(i, 1);
_$jscoverage["Bacon.coffee"][780]++;
return;
}
}
};
_$jscoverage["Bacon.coffee"][781]++;
subscribeAll = function(newSink) {
var subscription, unsubFuncs, _i, _len, _ref1;
_$jscoverage["Bacon.coffee"][782]++;
sink = newSink;
_$jscoverage["Bacon.coffee"][783]++;
unsubFuncs = [];
_$jscoverage["Bacon.coffee"][784]++;
_ref1 = cloneArray(subscriptions);
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
subscription = _ref1[_i];
_$jscoverage["Bacon.coffee"][785]++;
subscribeInput(subscription);
}
_$jscoverage["Bacon.coffee"][786]++;
return unsubAll;
};
_$jscoverage["Bacon.coffee"][787]++;
dispatcher = new Dispatcher(subscribeAll);
_$jscoverage["Bacon.coffee"][788]++;
subscribeThis = function(sink) {
_$jscoverage["Bacon.coffee"][789]++;
return dispatcher.subscribe(sink);
};
_$jscoverage["Bacon.coffee"][790]++;
Bus.__super__.constructor.call(this, subscribeThis);
_$jscoverage["Bacon.coffee"][791]++;
this.plug = function(input) {
var sub;
_$jscoverage["Bacon.coffee"][792]++;
if (ended) {
return;
}
_$jscoverage["Bacon.coffee"][793]++;
sub = {
input: input
};
_$jscoverage["Bacon.coffee"][794]++;
subscriptions.push(sub);
_$jscoverage["Bacon.coffee"][795]++;
if ((sink != null)) {
subscribeInput(sub);
}
_$jscoverage["Bacon.coffee"][796]++;
return function() {
return unsubscribeInput(input);
};
};
_$jscoverage["Bacon.coffee"][797]++;
this.push = function(value) {
_$jscoverage["Bacon.coffee"][798]++;
if (sink != null) {
return sink(next(value));
}
};
_$jscoverage["Bacon.coffee"][799]++;
this.error = function(error) {
_$jscoverage["Bacon.coffee"][800]++;
if (sink != null) {
return sink(new Error(error));
}
};
_$jscoverage["Bacon.coffee"][801]++;
this.end = function() {
_$jscoverage["Bacon.coffee"][802]++;
ended = true;
_$jscoverage["Bacon.coffee"][803]++;
unsubAll();
_$jscoverage["Bacon.coffee"][804]++;
if (sink != null) {
return sink(end());
}
};
}
return Bus;
})(EventStream);
_$jscoverage["Bacon.coffee"][806]++;
Some = (function() {
_$jscoverage["Bacon.coffee"][807]++;
function Some(value) {
this.value = value;
}
Some.prototype.getOrElse = function() {
_$jscoverage["Bacon.coffee"][808]++;
return this.value;
};
Some.prototype.get = function() {
_$jscoverage["Bacon.coffee"][809]++;
return this.value;
};
Some.prototype.filter = function(f) {
_$jscoverage["Bacon.coffee"][811]++;
if (f(this.value)) {
_$jscoverage["Bacon.coffee"][812]++;
return new Some(this.value);
} else {
_$jscoverage["Bacon.coffee"][814]++;
return None;
}
};
Some.prototype.map = function(f) {
_$jscoverage["Bacon.coffee"][816]++;
return new Some(f(this.value));
};
Some.prototype.forEach = function(f) {
_$jscoverage["Bacon.coffee"][818]++;
return f(this.value);
};
Some.prototype.isDefined = true;
Some.prototype.toArray = function() {
_$jscoverage["Bacon.coffee"][820]++;
return [this.value];
};
return Some;
})();
_$jscoverage["Bacon.coffee"][822]++;
None = {
getOrElse: function(value) {
_$jscoverage["Bacon.coffee"][823]++;
return value;
},
filter: function() {
_$jscoverage["Bacon.coffee"][824]++;
return None;
},
map: function() {
_$jscoverage["Bacon.coffee"][825]++;
return None;
},
forEach: function() {},
isDefined: false,
toArray: function() {
_$jscoverage["Bacon.coffee"][828]++;
return [];
}
};
_$jscoverage["Bacon.coffee"][830]++;
Bacon.EventStream = EventStream;
_$jscoverage["Bacon.coffee"][831]++;
Bacon.Property = Property;
_$jscoverage["Bacon.coffee"][832]++;
Bacon.Observable = Observable;
_$jscoverage["Bacon.coffee"][833]++;
Bacon.Bus = Bus;
_$jscoverage["Bacon.coffee"][834]++;
Bacon.Initial = Initial;
_$jscoverage["Bacon.coffee"][835]++;
Bacon.Next = Next;
_$jscoverage["Bacon.coffee"][836]++;
Bacon.End = End;
_$jscoverage["Bacon.coffee"][837]++;
Bacon.Error = Error;
_$jscoverage["Bacon.coffee"][839]++;
nop = function() {};
_$jscoverage["Bacon.coffee"][840]++;
latter = function(_, x) {
return x;
};
_$jscoverage["Bacon.coffee"][841]++;
former = function(x, _) {
return x;
};
_$jscoverage["Bacon.coffee"][842]++;
initial = function(value) {
return new Initial(_.always(value));
};
_$jscoverage["Bacon.coffee"][843]++;
next = function(value) {
return new Next(_.always(value));
};
_$jscoverage["Bacon.coffee"][844]++;
end = function() {
return new End();
};
_$jscoverage["Bacon.coffee"][845]++;
isEvent = function(x) {
return (x != null) && (x.isEvent != null) && x.isEvent();
};
_$jscoverage["Bacon.coffee"][846]++;
toEvent = function(x) {
_$jscoverage["Bacon.coffee"][847]++;
if (isEvent(x)) {
_$jscoverage["Bacon.coffee"][848]++;
return x;
} else {
_$jscoverage["Bacon.coffee"][850]++;
return next(x);
}
};
_$jscoverage["Bacon.coffee"][851]++;
cloneArray = function(xs) {
return xs.slice(0);
};
_$jscoverage["Bacon.coffee"][852]++;
cloneObject = function(src) {
var clone, key, value;
_$jscoverage["Bacon.coffee"][853]++;
clone = {};
_$jscoverage["Bacon.coffee"][854]++;
for (key in src) {
value = src[key];
_$jscoverage["Bacon.coffee"][855]++;
clone[key] = value;
}
_$jscoverage["Bacon.coffee"][856]++;
return clone;
};
_$jscoverage["Bacon.coffee"][857]++;
indexOf = Array.prototype.indexOf ? (_$jscoverage["Bacon.coffee"][858]++, function(xs, x) {
return xs.indexOf(x);
}) : (_$jscoverage["Bacon.coffee"][860]++, function(xs, x) {
var i, y, _i, _len;
_$jscoverage["Bacon.coffee"][861]++;
for (i = _i = 0, _len = xs.length; _i < _len; i = ++_i) {
y = xs[i];
_$jscoverage["Bacon.coffee"][862]++;
if (x === y) {
return i;
}
}
_$jscoverage["Bacon.coffee"][863]++;
return -1;
});
_$jscoverage["Bacon.coffee"][864]++;
remove = function(x, xs) {
var i;
_$jscoverage["Bacon.coffee"][865]++;
i = indexOf(xs, x);
_$jscoverage["Bacon.coffee"][866]++;
if (i >= 0) {
_$jscoverage["Bacon.coffee"][867]++;
return xs.splice(i, 1);
}
};
_$jscoverage["Bacon.coffee"][868]++;
assert = function(message, condition) {
if (!condition) {
throw message;
}
};
_$jscoverage["Bacon.coffee"][869]++;
assertEvent = function(event) {
assert("not an event : " + event, event.isEvent != null);
return assert("not event", event.isEvent());
};
_$jscoverage["Bacon.coffee"][870]++;
assertFunction = function(f) {
return assert("not a function : " + f, isFunction(f));
};
_$jscoverage["Bacon.coffee"][871]++;
isFunction = function(f) {
return typeof f === "function";
};
_$jscoverage["Bacon.coffee"][872]++;
assertArray = function(xs) {
return assert("not an array : " + xs, xs instanceof Array);
};
_$jscoverage["Bacon.coffee"][873]++;
assertString = function(x) {
return assert("not a string : " + x, typeof x === "string");
};
_$jscoverage["Bacon.coffee"][874]++;
methodCall = function(obj, method, args) {
_$jscoverage["Bacon.coffee"][875]++;
assertString(method);
_$jscoverage["Bacon.coffee"][876]++;
if (args === void 0) {
args = [];
}
_$jscoverage["Bacon.coffee"][877]++;
return function(value) {
return obj[method].apply(obj, args.concat([value]));
};
};
_$jscoverage["Bacon.coffee"][878]++;
partiallyApplied = function(f, args) {
_$jscoverage["Bacon.coffee"][879]++;
return function(value) {
return f.apply(null, args.concat([value]));
};
};
_$jscoverage["Bacon.coffee"][880]++;
makeFunction = function(f, args) {
_$jscoverage["Bacon.coffee"][881]++;
if (isFunction(f)) {
_$jscoverage["Bacon.coffee"][882]++;
if (args.length) {
return partiallyApplied(f, args);
} else {
return f;
}
} else if (isFieldKey(f)) {
_$jscoverage["Bacon.coffee"][884]++;
return toFieldExtractor(f, args);
} else if (typeof f === "object" && args.length) {
_$jscoverage["Bacon.coffee"][886]++;
return methodCall(f, _.head(args), _.tail(args));
} else {
_$jscoverage["Bacon.coffee"][888]++;
return _.always(f);
}
};
_$jscoverage["Bacon.coffee"][889]++;
isFieldKey = function(f) {
_$jscoverage["Bacon.coffee"][890]++;
return (typeof f === "string") && f.length > 1 && f.charAt(0) === ".";
};
_$jscoverage["Bacon.coffee"][891]++;
Bacon.isFieldKey = isFieldKey;
_$jscoverage["Bacon.coffee"][892]++;
toFieldExtractor = function(f, args) {
var partFuncs, parts;
_$jscoverage["Bacon.coffee"][893]++;
parts = f.slice(1).split(".");
_$jscoverage["Bacon.coffee"][894]++;
partFuncs = _.map(toSimpleExtractor(args), parts);
_$jscoverage["Bacon.coffee"][895]++;
return function(value) {
var _i, _len;
_$jscoverage["Bacon.coffee"][896]++;
for (_i = 0, _len = partFuncs.length; _i < _len; _i++) {
f = partFuncs[_i];
_$jscoverage["Bacon.coffee"][897]++;
value = f(value);
}
_$jscoverage["Bacon.coffee"][898]++;
return value;
};
};
_$jscoverage["Bacon.coffee"][899]++;
toSimpleExtractor = function(args) {
return function(key) {
return function(value) {
var fieldValue;
_$jscoverage["Bacon.coffee"][900]++;
fieldValue = value[key];
_$jscoverage["Bacon.coffee"][901]++;
if (isFunction(fieldValue)) {
_$jscoverage["Bacon.coffee"][902]++;
return fieldValue.apply(value, args);
} else {
_$jscoverage["Bacon.coffee"][904]++;
return fieldValue;
}
};
};
};
_$jscoverage["Bacon.coffee"][906]++;
toFieldKey = function(f) {
_$jscoverage["Bacon.coffee"][907]++;
return f.slice(1);
};
_$jscoverage["Bacon.coffee"][908]++;
toCombinator = function(f) {
var key;
_$jscoverage["Bacon.coffee"][909]++;
if (isFunction(f)) {
_$jscoverage["Bacon.coffee"][910]++;
return f;
} else if (isFieldKey(f)) {
_$jscoverage["Bacon.coffee"][912]++;
key = toFieldKey(f);
_$jscoverage["Bacon.coffee"][913]++;
return function(left, right) {
_$jscoverage["Bacon.coffee"][914]++;
return left[key](right);
};
} else {
_$jscoverage["Bacon.coffee"][916]++;
return assert("not a function or a field key: " + f, false);
}
};
_$jscoverage["Bacon.coffee"][917]++;
toOption = function(v) {
_$jscoverage["Bacon.coffee"][918]++;
if (v instanceof Some || v === None) {
_$jscoverage["Bacon.coffee"][919]++;
return v;
} else {
_$jscoverage["Bacon.coffee"][921]++;
return new Some(v);
}
};
_$jscoverage["Bacon.coffee"][923]++;
if ((typeof define !== "undefined" && define !== null) && (define.amd != null)) {
if (typeof define === "function") {
define(function() {
return Bacon;
});
}
}
_$jscoverage["Bacon.coffee"][925]++;
_ = {
head: function(xs) {
_$jscoverage["Bacon.coffee"][926]++;
return xs[0];
},
always: function(x) {
_$jscoverage["Bacon.coffee"][927]++;
return function() {
return x;
};
},
empty: function(xs) {
_$jscoverage["Bacon.coffee"][928]++;
return xs.length === 0;
},
tail: function(xs) {
_$jscoverage["Bacon.coffee"][929]++;
return xs.slice(1, xs.length);
},
filter: function(f, xs) {
var filtered, x, _i, _len;
_$jscoverage["Bacon.coffee"][931]++;
filtered = [];
_$jscoverage["Bacon.coffee"][932]++;
for (_i = 0, _len = xs.length; _i < _len; _i++) {
x = xs[_i];
_$jscoverage["Bacon.coffee"][933]++;
if (f(x)) {
filtered.push(x);
}
}
_$jscoverage["Bacon.coffee"][934]++;
return filtered;
},
map: function(f, xs) {
var x, _i, _len, _results;
_$jscoverage["Bacon.coffee"][936]++;
_results = [];
for (_i = 0, _len = xs.length; _i < _len; _i++) {
x = xs[_i];
_results.push(f(x));
}
return _results;
},
each: function(xs, f) {
var key, value, _results;
_$jscoverage["Bacon.coffee"][938]++;
_results = [];
for (key in xs) {
value = xs[key];
_$jscoverage["Bacon.coffee"][939]++;
_results.push(f(key, value));
}
return _results;
},
toArray: function(xs) {
_$jscoverage["Bacon.coffee"][940]++;
if (xs instanceof Array) {
return xs;
} else {
return [xs];
}
},
contains: function(xs, x) {
_$jscoverage["Bacon.coffee"][941]++;
return indexOf(xs, x) !== -1;
},
id: function(x) {
_$jscoverage["Bacon.coffee"][942]++;
return x;
},
last: function(xs) {
_$jscoverage["Bacon.coffee"][943]++;
return xs[xs.length - 1];
}
};
_$jscoverage["Bacon.coffee"][946]++;
Bacon._ = _;
}).call(this);
});
require.define("/spec/Mock.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
var Mock, eq, mockFunction,
__slice = [].slice;
Mock = (function() {
function Mock() {
var methodNames, name, _i, _len,
_this = this;
methodNames = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
for (_i = 0, _len = methodNames.length; _i < _len; _i++) {
name = methodNames[_i];
this[name] = mockFunction(name);
}
this.verify = function() {
var verifier, _j, _len1;
verifier = {};
for (_j = 0, _len1 = methodNames.length; _j < _len1; _j++) {
name = methodNames[_j];
verifier[name] = _this[name].verify;
}
return verifier;
};
this.when = function() {
var assign, returner, _j, _len1;
returner = {};
assign = function(name) {
return returner[name] = function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return {
thenReturn: function(returnValue) {
var _ref;
return (_ref = _this[name].doReturn(returnValue)).when.apply(_ref, args);
}
};
};
};
for (_j = 0, _len1 = methodNames.length; _j < _len1; _j++) {
name = methodNames[_j];
assign(name);
}
return returner;
};
}
return Mock;
})();
mockFunction = function(name) {
var calls, method, returns,
_this = this;
calls = [];
returns = [];
method = function() {
var args, returnCombo, _i, _len;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
calls.push(args);
for (_i = 0, _len = returns.length; _i < _len; _i++) {
returnCombo = returns[_i];
if (eq(returnCombo.args, args)) {
return returnCombo.returnValue;
}
}
};
method.verify = function() {
var actualCall, args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
if (!calls) {
throw "not called: " + name;
}
actualCall = calls[0];
calls.splice(0, 1);
return expect(actualCall).toEqual(args);
};
method.doReturn = function(returnValue) {
return {
when: function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return returns.push({
args: args,
returnValue: returnValue
});
}
};
};
return method;
};
eq = function(xs, ys) {
var i, x, _i, _len;
if (xs.length !== ys.length) {
return false;
}
for (i = _i = 0, _len = xs.length; _i < _len; i = ++_i) {
x = xs[i];
if (x !== ys[i]) {
return false;
}
}
return true;
};
this.mock = function() {
var methodNames;
methodNames = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return (function(func, args, ctor) {
ctor.prototype = func.prototype;
var child = new ctor, result = func.apply(child, args);
return Object(result) === result ? result : child;
})(Mock, methodNames, function(){});
};
this.mockFunction = mockFunction;
}).call(this);
});
require.define("/spec/BaconSpec.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
var Bacon, EventEmitter, Mocks, add, error, expectPropertyEvents, expectStreamEvents, id, lessThan, mock, mockFunction, repeat, series, soon, t, testSideEffects, th, times, toEventTarget, toValues, verifyCleanup;
Bacon = (require("../src/Bacon")).Bacon;
Mocks = require("./Mock");
mock = Mocks.mock;
mockFunction = Mocks.mockFunction;
EventEmitter = require("events").EventEmitter;
th = require("./SpecHelper");
t = th.t;
expectStreamEvents = th.expectStreamEvents;
expectPropertyEvents = th.expectPropertyEvents;
verifyCleanup = th.verifyCleanup;
error = th.error;
soon = th.soon;
series = th.series;
repeat = th.repeat;
toValues = th.toValues;
describe("Bacon.later", function() {
return it("should send single event and end", function() {
return expectStreamEvents(function() {
return Bacon.later(t(1), "lol");
}, ["lol"]);
});
});
describe("Bacon.sequentially", function() {
it("should send given events and end", function() {
return expectStreamEvents(function() {
return Bacon.sequentially(t(1), ["lol", "wut"]);
}, ["lol", "wut"]);
});
return it("include error events", function() {
return expectStreamEvents(function() {
return Bacon.sequentially(t(1), [error(), "lol"]);
}, [error(), "lol"]);
});
});
describe("Bacon.interval", function() {
return it("repeats single element indefinitely", function() {
return expectStreamEvents(function() {
return Bacon.interval(t(1), "x").take(3);
}, ["x", "x", "x"]);
});
});
describe("Bacon.fromCallback", function() {
it("makes an EventStream from function that takes a callback", function() {
return expectStreamEvents(function() {
var src, stream;
src = function(callback) {
return callback("lol");
};
return stream = Bacon.fromCallback(src);
}, ["lol"]);
});
return it("supports partial application", function() {
return expectStreamEvents(function() {
var src, stream;
src = function(param, callback) {
return callback(param);
};
return stream = Bacon.fromCallback(src, "lol");
}, ["lol"]);
});
});
describe("Bacon.fromEventTarget", function() {
it("should create EventStream from DOM object", function() {
var element, emitter;
emitter = new EventEmitter();
emitter.on("newListener", function() {
return runs(function() {
return emitter.emit("click", "x");
});
});
element = toEventTarget(emitter);
return expectStreamEvents(function() {
return Bacon.fromEventTarget(element, "click").take(1);
}, ["x"]);
});
it("should create EventStream from EventEmitter", function() {
var emitter;
emitter = new EventEmitter();
emitter.on("newListener", function() {
return runs(function() {
return emitter.emit("data", "x");
});
});
return expectStreamEvents(function() {
return Bacon.fromEventTarget(emitter, "data").take(1);
}, ["x"]);
});
it("should allow a custom map function for EventStream from EventEmitter", function() {
var emitter;
emitter = new EventEmitter();
emitter.on("newListener", function() {
return runs(function() {
return emitter.emit("data", "x", "y");
});
});
return expectStreamEvents(function() {
var _this = this;
return Bacon.fromEventTarget(emitter, "data", function(x, y) {
return [x, y];
}).take(1);
}, [["x", "y"]]);
});
it("should clean up event listeners from EventEmitter", function() {
var emitter;
emitter = new EventEmitter();
Bacon.fromEventTarget(emitter, "data").take(1).subscribe(function() {});
emitter.emit("data", "x");
return expect(emitter.listeners("data").length).toEqual(0);
});
return it("should clean up event listeners from DOM object", function() {
var dispose, element, emitter;
emitter = new EventEmitter();
element = toEventTarget(emitter);
dispose = Bacon.fromEventTarget(element, "click").subscribe(function() {});
dispose();
return expect(emitter.listeners("click").length).toEqual(0);
});
});
describe("Observable.log", function() {
return it("does not crash", function() {
return Bacon.constant(1).log;
});
});
describe("Observable.slidingWindow", function() {
it("slides the window for EventStreams", function() {
return expectPropertyEvents(function() {
return series(1, [1, 2, 3]).slidingWindow(2);
}, [[], [1], [1, 2], [2, 3]]);
});
return it("slides the window for Properties", function() {
return expectPropertyEvents(function() {
return series(1, [1, 2, 3]).toProperty().slidingWindow(2);
}, [[], [1], [1, 2], [2, 3]]);
});
});
describe("EventStream.filter", function() {
it("should filter values", function() {
return expectStreamEvents(function() {
return series(1, [1, 2, error(), 3]).filter(lessThan(3));
}, [1, 2, error()]);
});
it("extracts field values", function() {
return expectStreamEvents(function() {
return series(1, [
{
good: true,
value: "yes"
}, {
good: false,
value: "no"
}
]).filter(".good").map(".value");
}, ["yes"]);
});
return it("can filter by Property value", function() {
return expectStreamEvents(function() {
var odd, src;
src = series(1, [1, 1, 2, 3, 4, 4, 8, 7]);
odd = src.map(function(x) {
return x % 2;
}).toProperty();
return src.filter(odd);
}, [1, 1, 3, 7]);
});
});
describe("EventStream.map", function() {
it("should map with given function", function() {
return expectStreamEvents(function() {
return series(1, [1, 2, 3]).map(times, 2);
}, [2, 4, 6]);
});
it("also accepts a constant value", function() {
return expectStreamEvents(function() {
return series(1, [1, 2, 3]).map("lol");
}, ["lol", "lol", "lol"]);
});
it("extracts property from value object", function() {
var o;
o = {
lol: "wut"
};
return expectStreamEvents(function() {
return repeat(1, [o]).take(3).map(".lol");
}, ["wut", "wut", "wut"]);
});
it("extracts a nested property too", function() {
var o;
o = {
lol: {
wut: "wat"
}
};
return expectStreamEvents(function() {
return Bacon.once(o).map(".lol.wut");
}, ["wat"]);
});
it("in case of a function property, calls the function with no args", function() {
return expectStreamEvents(function() {
return Bacon.once([1, 2, 3]).map(".length");
}, [3]);
});
it("allows arguments for methods", function() {
var thing;
thing = {
square: function(x) {
return x * x;
}
};
return expectStreamEvents(function() {
return Bacon.once(thing).map(".square", 2);
}, [4]);
});
it("works with method call on given object, with partial application", function() {
var multiplier;
multiplier = {
multiply: function(x, y) {
return x * y;
}
};
return expectStreamEvents(function() {
return series(1, [1, 2, 3]).map(multiplier, "multiply", 2);
}, [2, 4, 6]);
});
return it("can map to a Property value", function() {
return expectStreamEvents(function() {
return series(1, [1, 2, 3]).map(Bacon.constant(2));
}, [2, 2, 2]);
});
});
describe("EventStream.mapError", function() {
it("should map error events with given function", function() {
return expectStreamEvents(function() {
return repeat(1, [1, error("OOPS")]).mapError(id).take(2);
}, [1, "OOPS"]);
});
return it("also accepts a constant value", function() {
return expectStreamEvents(function() {
return repeat(1, [1, error()]).mapError("ERR").take(2);
}, [1, "ERR"]);
});
});
describe("EventStream.doAction", function() {
it("calls function before sending value to listeners", function() {
var bus, called, s;
called = [];
bus = new Bacon.Bus();
s = bus.doAction(function(x) {
return called.push(x);
});
s.onValue(function() {});
s.onValue(function() {});
bus.push(1);
return expect(called).toEqual([1]);
});
return it("does not alter the stream", function() {
return expectStreamEvents(function() {
return series(1, [1, 2]).doAction(function() {});
}, [1, 2]);
});
});
describe("EventStream.mapEnd", function() {
it("produces an extra element on stream end", function() {
return expectStreamEvents(function() {
return series(1, ["1", error()]).mapEnd("the end");
}, ["1", error(), "the end"]);
});
it("accepts either a function or a constant value", function() {
return expectStreamEvents(function() {
return series(1, ["1", error()]).mapEnd(function() {
return "the end";
});
}, ["1", error(), "the end"]);
});
return it("works with undefined value as well", function() {
return expectStreamEvents(function() {
return series(1, ["1", error()]).mapEnd();
}, ["1", error(), void 0]);
});
});
describe("EventStream.takeWhile", function() {
return it("should take while predicate is true", function() {
return expectStreamEvents(function() {
return repeat(1, [1, error("wat"), 2, 3]).takeWhile(lessThan(3));
}, [1, error("wat"), 2]);
});
});
describe("EventStream.skip", function() {
return it("should skip first N items", function() {
return expectStreamEvents(function() {
return series(1, [1, error(), 2, error(), 3]).skip(1);
}, [error(), 2, error(), 3]);
});
});
describe("EventStream.skipDuplicates", function() {
it("drops duplicates", function() {
return expectStreamEvents(function() {
return series(1, [1, 2, error(), 2, 3, 1]).skipDuplicates();
}, [1, 2, error(), 3, 1]);
});
it("allows undefined as initial value", function() {
return expectStreamEvents(function() {
return series(1, [void 0, void 0, 1, 2]).skipDuplicates();
}, [void 0, 1, 2]);
});
return it("works with custom isEqual function", function() {
var a, b, c, d, e, isEqual;
a = {
x: 1
};
b = {
x: 2
};
c = {
x: 2
};
d = {
x: 3
};
e = {
x: 1
};
isEqual = function(a, b) {
return (a != null ? a.x : void 0) === (b != null ? b.x : void 0);
};
return expectStreamEvents(function() {
return series(1, [a, b, error(), c, d, e]).skipDuplicates(isEqual);
}, [a, b, error(), d, e]);
});
});
describe("EventStream.flatMap", function() {
it("should spawn new stream for each value and collect results into a single stream", function() {
return expectStreamEvents(function() {
return series(1, [1, 2]).flatMap(function(value) {
return Bacon.sequentially(t(2), [value, error(), value]);
});
}, [1, 2, error(), error(), 1, 2]);
});
it("should pass source errors through to the result", function() {
return expectStreamEvents(function() {
return series(1, [error(), 1]).flatMap(function(value) {
return Bacon.later(t(1), value);
});
}, [error(), 1]);
});
it("should work with a spawned stream responding synchronously", function() {
return expectStreamEvents(function() {
return series(1, [1, 2]).flatMap(function(value) {
return Bacon.never().concat(Bacon.once(value));
});
}, [1, 2]);
});
it("should work with a source stream responding synchronously", function() {
return expectStreamEvents(function() {
return Bacon.once(1).flatMap(function(value) {
return Bacon.once(value);
});
}, [1]);
});
return it("Works also when f returns a Property instead of an EventStream", function() {
return expectStreamEvents(function() {
return series(1, [1, 2]).flatMap(Bacon.constant);
}, [1, 2]);
});
});
describe("Property.flatMap", function() {
it("should spawn new stream for all events including Init", function() {
return expectStreamEvents(function() {
var once;
once = function(x) {
return Bacon.once(x);
};
return series(1, [1, 2]).toProperty(0).flatMap(once);
}, [0, 1, 2]);
});
return it("Works also when f returns a Property instead of an EventStream", function() {
expectStreamEvents(function() {
return series(1, [1, 2]).toProperty().flatMap(Bacon.constant);
}, [1, 2]);
return expectPropertyEvents(function() {
return series(1, [1, 2]).toProperty().flatMap(Bacon.constant).toProperty();
}, [1, 2]);
});
});
describe("EventStream.flatMapLatest", function() {
return it("spawns new streams but collects values from the latest spawned stream only", function() {
return expectStreamEvents(function() {
return series(3, [1, 2]).flatMapLatest(function(value) {
return Bacon.sequentially(t(2), [value, error(), value]);
});
}, [1, 2, error(), 2]);
});
});
describe("Property.flatMapLatest", function() {
return it("spawns new streams but collects values from the latest spawned stream only", function() {
return expectStreamEvents(function() {
return series(3, [1, 2]).toProperty(0).flatMapLatest(function(value) {
return Bacon.sequentially(t(2), [value, value]);
});
}, [0, 1, 2, 2]);
});
});
describe("EventStream.merge", function() {
it("merges two streams and ends when both are exhausted", function() {
return expectStreamEvents(function() {
var left, right;
left = series(1, [1, error(), 2, 3]);
right = series(1, [4, 5, 6]).delay(t(4));
return left.merge(right);
}, [1, error(), 2, 3, 4, 5, 6]);
});
return it("respects subscriber return value", function() {
return expectStreamEvents(function() {
var left, right;
left = repeat(2, [1, 3]).take(3);
right = repeat(3, [2]).take(3);
return left.merge(right).takeWhile(lessThan(2));
}, [1]);
});
});
describe("EventStream.delay", function() {
return it("delays all events (except errors) by given delay in milliseconds", function() {
return expectStreamEvents(function() {
var left, right;
left = series(2, [1, 2, 3]);
right = series(1, [error(), 4, 5, 6]).delay(t(6));
return left.merge(right);
}, [error(), 1, 2, 3, 4, 5, 6]);
});
});
describe("EventStream.throttle", function() {
it("throttles input by given delay, passing-through errors", function() {
return expectStreamEvents(function() {
return series(2, [1, error(), 2]).throttle(t(7));
}, [error(), 2]);
});
return it("waits for a quiet period before outputing anything", function() {
return expectStreamTimings(function() {
return series(2, [1, 2, 3, 4]).throttle(t(3));
}, [[11, 4]]);
});
});
describe("EventStream.throttle2(delay)", function() {
return it("outputs at steady intervals, without waiting for quite period", function() {
return expectStreamTimings(function() {
return series(2, [1, 2, 3]).throttle2(t(3));
}, [[5, 2], [8, 3]]);
});
});
describe("EventStream.bufferWithTime", function() {
it("returns events in bursts, passing through errors", function() {
return expectStreamEvents(function() {
return series(2, [error(), 1, 2, 3, 4, 5, 6, 7]).bufferWithTime(t(7));
}, [error(), [1, 2, 3, 4], [5, 6, 7]]);
});
it("keeps constant output rate even when input is sporadical", function() {
return th.expectStreamTimings(function() {
return th.atGivenTimes([[0, "a"], [3, "b"], [5, "c"]]).bufferWithTime(t(2));
}, [[2, ["a"]], [4, ["b"]], [6, ["c"]]]);
});
it("works with empty stream", function() {
return expectStreamEvents(function() {
return Bacon.never().bufferWithTime(t(1));
}, []);
});
it("allows custom defer-function", function() {
var fast;
fast = function(f) {
return setTimeout(f, 0);
};
return th.expectStreamTimings(function() {
return th.atGivenTimes([[0, "a"], [2, "b"]]).bufferWithTime(fast);
}, [[0, ["a"]], [2, ["b"]]]);
});
return it("works with synchronous defer-function", function() {
var sync;
sync = function(f) {
return f();
};
return th.expectStreamTimings(function() {
return th.atGivenTimes([[0, "a"], [2, "b"]]).bufferWithTime(sync);
}, [[0, ["a"]], [2, ["b"]]]);
});
});
describe("EventStream.bufferWithCount", function() {
return it("returns events in chunks of fixed size, passing through errors", function() {
return expectStreamEvents(function() {
return series(1, [1, 2, 3, error(), 4, 5]).bufferWithCount(2);
}, [[1, 2], error(), [3, 4], [5]]);
});
});
describe("EventStream.takeUntil", function() {
it("takes elements from source until an event appears in the other stream", function() {
return expectStreamEvents(function() {
var src, stopper;
src = repeat(3, [1, 2, 3]);
stopper = repeat(7, ["stop!"]);
return src.takeUntil(stopper);
}, [1, 2]);
});
it("works on self-derived stopper", function() {
return expectStreamEvents(function() {
var src, stopper;
src = repeat(3, [3, 2, 1]);
stopper = src.filter(lessThan(3));
return src.takeUntil(stopper);
}, [3]);
});
return it("includes source errors, ignores stopper errors", function() {
return expectStreamEvents(function() {
var src, stopper;
src = repeat(2, [1, error(), 2, 3]);
stopper = repeat(7, ["stop!"]).merge(repeat(1, [error()]));
return src.takeUntil(stopper);
}, [1, error(), 2]);
});
});
describe("EventStream.awaiting(other)", function() {
return it("indicates whether s1 has produced output after s2 (or only the former has output so far)", function() {
return expectPropertyEvents(function() {
return series(2, [1, 1]).awaiting(series(3, [2]));
}, [false, true, false, true]);
});
});
describe("EventStream.endOnError", function() {
return it("terminates on error", function() {
return expectStreamEvents(function() {
return repeat(1, [1, 2, error(), 3]).endOnError();
}, [1, 2, error()]);
});
});
describe("Bacon.constant", function() {
it("creates a constant property", function() {
return expectPropertyEvents(function() {
return Bacon.constant("lol");
}, ["lol"]);
});
it("ignores unsubscribe", function() {
var _this = this;
return Bacon.constant("lol").onValue(function() {})();
});
it("provides same value to all listeners", function() {
var c, f;
c = Bacon.constant("lol");
expectPropertyEvents((function() {
return c;
}), ["lol"]);
f = mockFunction();
c.onValue(f);
return f.verify("lol");
});
return it("provides same value to all listeners, when mapped (bug fix)", function() {
var c, f;
c = Bacon.constant("lol").map(id);
f = mockFunction();
c.onValue(f);
f.verify("lol");
c.onValue(f);
return f.verify("lol");
});
});
describe("Bacon.never", function() {
return it("should send just end", function() {
return expectStreamEvents(function() {
return Bacon.never();
}, []);
});
});
describe("Bacon.once", function() {
return it("should send single event and end", function() {
return expectStreamEvents(function() {
return Bacon.once("pow");
}, ["pow"]);
});
});
describe("EventStream.concat", function() {
it("provides values from streams in given order and ends when both are exhausted", function() {
return expectStreamEvents(function() {
var left, right;
left = series(2, [1, error(), 2, 3]);
right = series(1, [4, 5, 6]);
return left.concat(right);
}, [1, error(), 2, 3, 4, 5, 6]);
});
it("respects subscriber return value when providing events from left stream", function() {
return expectStreamEvents(function() {
var left, right;
left = repeat(3, [1, 3]).take(3);
right = repeat(2, [1]).take(3);
return left.concat(right).takeWhile(lessThan(2));
}, [1]);
});
it("respects subscriber return value when providing events from right stream", function() {
return expectStreamEvents(function() {
var left, right;
left = series(3, [1, 2]);
right = series(2, [2, 4, 6]);
return left.concat(right).takeWhile(lessThan(4));
}, [1, 2, 2]);
});
it("works with Bacon.never()", function() {
return expectStreamEvents(function() {
return Bacon.never().concat(Bacon.never());
}, []);
});
it("works with Bacon.once()", function() {
return expectStreamEvents(function() {
return Bacon.once(2).concat(Bacon.once(1));
}, [2, 1]);
});
it("works with Bacon.once() and Bacon.never()", function() {
return expectStreamEvents(function() {
return Bacon.once(1).concat(Bacon.never());
}, [1]);
});
return it("works with Bacon.never() and Bacon.once()", function() {
return expectStreamEvents(function() {
return Bacon.never().concat(Bacon.once(1));
}, [1]);
});
});
describe("EventStream.startWith", function() {
return it("provides seed value, then the rest", function() {
return expectStreamEvents(function() {
var left;
left = series(1, [1, 2, 3]);
return left.startWith('pow');
}, ['pow', 1, 2, 3]);
});
});
describe("Property", function() {
it("delivers current value and changes to subscribers", function() {
return expectPropertyEvents(function() {
var p, s;
s = new Bacon.Bus();
p = s.toProperty("a");
soon(function() {
s.push("b");
return s.end();
});
return p;
}, ["a", "b"]);
});
it("passes through also Errors", function() {
return expectPropertyEvents(function() {
return series(1, [1, error(), 2]).toProperty();
}, [1, error(), 2]);
});
it("supports null as value", function() {
return expectPropertyEvents(function() {
return series(1, [null, 1, null]).toProperty(null);
}, [null, null, 1, null]);
});
return it("does not get messed-up by a transient subscriber (bug fix)", function() {
return expectPropertyEvents(function() {
var prop,
_this = this;
prop = series(1, [1, 2, 3]).toProperty(0);
prop.subscribe(function(event) {
return Bacon.noMore;
});
return prop;
}, [0, 1, 2, 3]);
});
});
describe("Property.toEventStream", function() {
return it("creates a stream that starts with current property value", function() {
return expectStreamEvents(function() {
return series(1, [1, 2]).toProperty(0).toEventStream();
}, [0, 1, 2]);
});
});
describe("Property.map", function() {
return it("maps property values", function() {
return expectPropertyEvents(function() {
var p, s;
s = new Bacon.Bus();
p = s.toProperty(1).map(times, 2);
soon(function() {
s.push(2);
s.error();
return s.end();
});
return p;
}, [2, 4, error()]);
});
});
describe("Property.filter", function() {
it("should filter values", function() {
return expectPropertyEvents(function() {
return series(1, [1, error(), 2, 3]).toProperty().filter(lessThan(3));
}, [1, error(), 2]);
});
return it("preserves old current value if the updated value is non-matching", function() {
var p, s, values,
_this = this;
s = new Bacon.Bus();
p = s.toProperty().filter(lessThan(2));
p.onValue(function() {});
s.push(1);
s.push(2);
values = [];
p.onValue(function(v) {
return values.push(v);
});
return expect(values).toEqual([1]);
});
});
describe("Property.take(1)", function() {
it("takes the Initial event", function() {
return expectPropertyEvents(function() {
return series(1, [1, 2, 3]).toProperty(0).take(1);
}, [0]);
});
it("takes the first Next event, if no Initial value", function() {
return expectPropertyEvents(function() {
return series(1, [1, 2, 3]).toProperty().take(1);
}, [1]);
});
return it("works for constants", function() {
return expectPropertyEvents(function() {
return Bacon.constant(1);
}, [1]);
});
});
describe("Bacon.once().take(1)", function() {
return it("works", function() {
return expectStreamEvents(function() {
return Bacon.once(1).take(1);
}, [1]);
});
});
describe("Property.takeUntil", function() {
it("takes elements from source until an event appears in the other stream", function() {
return expectPropertyEvents(function() {
return series(2, [1, 2, 3]).toProperty().takeUntil(Bacon.later(t(3)));
}, [1]);
});
return it("works with errors", function() {
return expectPropertyEvents(function() {
var src, stopper;
src = repeat(2, [1, error(), 3]);
stopper = repeat(5, ["stop!"]);
return src.toProperty(0).takeUntil(stopper);
}, [0, 1, error()]);
});
});
describe("Property.delay", function() {
it("delivers initial value and changes", function() {
return expectPropertyEvents(function() {
return series(1, [1, 2, 3]).toProperty(0).delay(t(1));
}, [0, 1, 2, 3]);
});
it("delays changes", function() {
return expectStreamEvents(function() {
return series(2, [1, 2, 3]).toProperty().delay(t(2)).changes().takeUntil(Bacon.later(t(5)));
}, [1]);
});
return it("does not delay initial value", function() {
return expectPropertyEvents(function() {
return series(3, [1]).toProperty(0).delay(1).takeUntil(Bacon.later(t(2)));
}, [0]);
});
});
describe("Property.throttle", function() {
it("delivers initial value and changes", function() {
return expectPropertyEvents(function() {
return series(2, [1, 2, 3]).toProperty(0).throttle(t(1));
}, [0, 1, 2, 3]);
});
it("throttles changes, but not initial value", function() {
return expectPropertyEvents(function() {
return series(1, [1, 2, 3]).toProperty(0).throttle(t(4));
}, [0, 3]);
});
return it("works without initial value", function() {
return expectPropertyEvents(function() {
return series(2, [1, 2, 3]).toProperty().throttle(t(4));
}, [3]);
});
});
describe("Property.throttle2", function() {
return it("throttles changes, but not initial value", function() {
return expectPropertyEvents(function() {
return series(1, [1, 2, 3]).toProperty(0).throttle2(t(4));
}, [0, 3]);
});
});
describe("Property.endOnError", function() {
return it("terminates on Error", function() {
return expectPropertyEvents(function() {
return series(2, [1, error(), 2]).toProperty().endOnError();
}, [1, error()]);
});
});
describe("Property.skipDuplicates", function() {
return it("drops duplicates", function() {
return expectPropertyEvents(function() {
return series(1, [1, 2, error(), 2, 3, 1]).toProperty(0).skipDuplicates();
}, [0, 1, 2, error(), 3, 1]);
});
});
describe("Property.changes", function() {
return it("sends property change events", function() {
return expectStreamEvents(function() {
var p, s;
s = new Bacon.Bus();
p = s.toProperty("a").changes();
soon(function() {
s.push("b");
s.error();
return s.end();
});
return p;
}, ["b", error()]);
});
});
describe("Property.combine", function() {
it("combines latest values of two properties, with given combinator function, passing through errors", function() {
return expectPropertyEvents(function() {
var left, right;
left = series(2, [1, error(), 2, 3]).toProperty();
right = series(2, [4, error(), 5, 6]).delay(t(1)).toProperty();
return left.combine(right, add);
}, [5, error(), error(), 6, 7, 8, 9]);
});
it("also accepts a field name instead of combinator function", function() {
return expectPropertyEvents(function() {
var left, right;
left = series(1, [[1]]).toProperty();
right = series(2, [[2]]).toProperty();
return left.combine(right, ".concat");
}, [[1, 2]]);
});
it("combines with null values", function() {
return expectPropertyEvents(function() {
var left, right;
left = series(1, [null]).toProperty();
right = series(1, [null]).toProperty();
return left.combine(right, function(l, r) {
return [l, r];
});
}, [[null, null]]);
});
return it("unsubscribes when initial value callback returns Bacon.noMore", function() {
var bus, calls, other;
calls = 0;
bus = new Bacon.Bus();
other = Bacon.constant(["rolfcopter"]);
bus.toProperty(["lollerskates"]).combine(other, ".concat").subscribe(function(e) {
if (!e.isInitial()) {
calls += 1;
}
return Bacon.noMore;
});
bus.push(["fail whale"]);
return expect(calls).toBe(0);
});
});
describe("Bacon.combineAsArray", function() {
it("combines properties and latest values of streams, into a Property having arrays as values", function() {
return expectPropertyEvents(function() {
var stream;
stream = series(1, ["a", "b"]);
return Bacon.combineAsArray([Bacon.constant(1), Bacon.constant(2), stream]);
}, [[1, 2, "a"], [1, 2, "b"]]);
});
it("Works with streams provided as a list of arguments as well as with a single array arg", function() {
return expectPropertyEvents(function() {
var stream;
stream = series(1, ["a", "b"]);
return Bacon.combineAsArray(Bacon.constant(1), Bacon.constant(2), stream);
}, [[1, 2, "a"], [1, 2, "b"]]);
});
it("works with single stream", function() {
return expectPropertyEvents(function() {
return Bacon.combineAsArray([Bacon.constant(1)]);
}, [[1]]);
});
it("works with arrays as values, with first array being empty (bug fix)", function() {
return expectPropertyEvents(function() {
return Bacon.combineAsArray([Bacon.constant([]), Bacon.constant([1])]);
}, [[[], [1]]]);
});
it("works with arrays as values, with first array being non-empty (bug fix)", function() {
return expectPropertyEvents(function() {
return Bacon.combineAsArray([Bacon.constant([1]), Bacon.constant([2])]);
}, [[[1], [2]]]);
});
return it("works with empty array", function() {
return expectPropertyEvents(function() {
return Bacon.combineAsArray([]);
}, [[]]);
});
});
describe("Bacon.combineWith", function() {
return it("combines properties by applying the combinator function to values", function() {
return expectPropertyEvents(function() {
var stream;
stream = series(1, [[1]]);
return Bacon.combineWith([stream, Bacon.constant([2]), Bacon.constant([3])], ".concat");
}, [[1, 2, 3]]);
});
});
describe("Boolean logic", function() {
it("combines Properties with and()", function() {
return expectPropertyEvents(function() {
return Bacon.constant(true).and(Bacon.constant(false));
}, [false]);
});
it("combines Properties with or()", function() {
return expectPropertyEvents(function() {
return Bacon.constant(true).or(Bacon.constant(false));
}, [true]);
});
return it("inverts property with not()", function() {
return expectPropertyEvents(function() {
return Bacon.constant(true).not();
}, [false]);
});
});
describe("Bacon.mergeAll", function() {
return it("merges all given streams", function() {
return expectStreamEvents(function() {
return Bacon.mergeAll([series(3, [1, 2]), series(3, [3, 4]).delay(t(1)), series(3, [5, 6]).delay(t(2))]);
}, [1, 3, 5, 2, 4, 6]);
});
});
describe("Property.sampledBy", function() {
it("samples property at events, resulting to EventStream", function() {
return expectStreamEvents(function() {
var prop, stream;
prop = series(2, [1, 2]).toProperty();
stream = repeat(3, ["troll"]).take(4);
return prop.sampledBy(stream);
}, [1, 2, 2, 2]);
});
it("includes errors from both Property and EventStream", function() {
return expectStreamEvents(function() {
var prop, stream;
prop = series(2, [error(), 2]).toProperty();
stream = series(3, [error(), "troll"]);
return prop.sampledBy(stream);
}, [error(), error(), 2]);
});
it("ends when sampling stream ends", function() {
return expectStreamEvents(function() {
var prop, stream;
prop = repeat(2, [1, 2]).toProperty();
stream = repeat(2, [""]).delay(t(1)).take(4);
return prop.sampledBy(stream);
}, [1, 2, 1, 2]);
});
it("accepts optional combinator function f(Vp, Vs)", function() {
return expectStreamEvents(function() {
var prop, stream;
prop = series(2, ["a", "b"]).toProperty();
stream = series(2, ["1", "2", "1", "2"]).delay(t(1));
return prop.sampledBy(stream, add);
}, ["a1", "b2", "b1", "b2"]);
});
it("allows method name instead of function too", function() {
return expectStreamEvents(function() {
return Bacon.constant([1]).sampledBy(Bacon.once([2]), ".concat");
}, [[1, 2]]);
});
return it("works with same origin", function() {
expectStreamEvents(function() {
var src;
src = series(2, [1, 2]);
return src.toProperty().sampledBy(src);
}, [1, 2]);
return expectStreamEvents(function() {
var src;
src = series(2, [1, 2]);
return src.toProperty().sampledBy(src.map(times, 2));
}, [1, 2]);
});
});
describe("Property.sample", function() {
it("samples property by given interval", function() {
return expectStreamEvents(function() {
var prop;
prop = series(2, [1, 2]).toProperty();
return prop.sample(t(3)).take(4);
}, [1, 2, 2, 2]);
});
return it("includes all errors", function() {
return expectStreamEvents(function() {
var prop;
prop = series(2, [1, error(), 2]).toProperty();
return prop.sample(t(5)).take(2);
}, [error(), 1, 2]);
});
});
describe("EventStream.scan", function() {
it("accumulates values with given seed and accumulator function, passing through errors", function() {
return expectPropertyEvents(function() {
return series(1, [1, 2, error(), 3]).scan(0, add);
}, [0, 1, 3, error(), 6]);
});
it("also works with method name", function() {
return expectPropertyEvents(function() {
return series(1, [[1], [2]]).scan([], ".concat");
}, [[], [1], [1, 2]]);
});
it("yields the seed value immediately", function() {
var bus, outputs;
outputs = [];
bus = new Bacon.Bus();
bus.scan(0, function() {
return 1;
}).onValue(function(value) {
return outputs.push(value);
});
return expect(outputs).toEqual([0]);
});
return it("yields null seed value", function() {
return expectPropertyEvents(function() {
return series(1, [1]).scan(null, function() {
return 1;
});
}, [null, 1]);
});
});
describe("Property.scan", function() {
it("with Init value, starts with f(seed, init)", function() {
return expectPropertyEvents(function() {
return series(1, [2, 3]).toProperty(1).scan(0, add);
}, [1, 3, 6]);
});
it("without Init value, starts with seed", function() {
return expectPropertyEvents(function() {
return series(1, [2, 3]).toProperty().scan(0, add);
}, [0, 2, 5]);
});
return it("treats null seed value like any other value", function() {
expectPropertyEvents(function() {
return series(1, [1]).toProperty().scan(null, add);
}, [null, 1]);
return expectPropertyEvents(function() {
return series(1, [2]).toProperty(1).scan(null, add);
}, [1, 3]);
});
});
describe("EventStream.diff", function() {
it("apply diff function to previous and current values, passing through errors", function() {
return expectPropertyEvents(function() {
return series(1, [1, 2, error(), 3]).diff(0, add);
}, [1, 3, error(), 5]);
});
it("also works with method name", function() {
return expectPropertyEvents(function() {
return series(1, [[1], [2]]).diff([0], ".concat");
}, [[0, 1], [1, 2]]);
});
return it("does not yields the start value immediately", function() {
var bus, outputs;
outputs = [];
bus = new Bacon.Bus();
bus.diff(0, function() {
return 1;
}).onValue(function(value) {
return outputs.push(value);
});
return expect(outputs).toEqual([]);
});
});
describe("Property.diff", function() {
it("with Init value, starts with f(start, init)", function() {
return expectPropertyEvents(function() {
return series(1, [2, 3]).toProperty(1).diff(0, add);
}, [1, 3, 5]);
});
it("without Init value, waits for the first value", function() {
return expectPropertyEvents(function() {
return series(1, [2, 3]).toProperty().diff(0, add);
}, [2, 5]);
});
return it("treats null start value like any other value", function() {
expectPropertyEvents(function() {
return series(1, [1]).toProperty().diff(null, add);
}, [1]);
return expectPropertyEvents(function() {
return series(1, [2]).toProperty(1).diff(null, add);
}, [1, 3]);
});
});
describe("combineTemplate", function() {
it("combines streams according to a template object", function() {
return expectPropertyEvents(function() {
var firstName, lastName, userName;
firstName = Bacon.constant("juha");
lastName = Bacon.constant("paananen");
userName = Bacon.constant("mr.bacon");
return Bacon.combineTemplate({
userName: userName,
password: "*****",
fullName: {
firstName: firstName,
lastName: lastName
}
});
}, [
{
userName: "mr.bacon",
password: "*****",
fullName: {
firstName: "juha",
lastName: "paananen"
}
}
]);
});
it("works with a single-stream template", function() {
return expectPropertyEvents(function() {
var bacon;
bacon = Bacon.constant("bacon");
return Bacon.combineTemplate({
favoriteFood: bacon
});
}, [
{
favoriteFood: "bacon"
}
]);
});
it("works when dynamic part is not the last part (bug fix)", function() {
return expectPropertyEvents(function() {
var password, username;
username = Bacon.constant("raimohanska");
password = Bacon.constant("easy");
return Bacon.combineTemplate({
url: "/user/login",
data: {
username: username,
password: password
},
type: "post"
});
}, [
{
url: "/user/login",
data: {
username: "raimohanska",
password: "easy"
},
type: "post"
}
]);
});
it("works with arrays as data (bug fix)", function() {
return expectPropertyEvents(function() {
return Bacon.combineTemplate({
x: Bacon.constant([]),
y: Bacon.constant([[]]),
z: Bacon.constant(["z"])
});
}, [
{
x: [],
y: [[]],
z: ["z"]
}
]);
});
it("supports empty object", function() {
return expectPropertyEvents(function() {
return Bacon.combineTemplate({});
}, [{}]);
});
return it("supports arrays", function() {
var value;
value = {
key: [
{
x: 1
}, {
x: 2
}
]
};
Bacon.combineTemplate(value).onValue(function(x) {
expect(x).toEqual(value);
return expect(x.key instanceof Array).toEqual(true);
});
value = [
{
x: 1
}, {
x: 2
}
];
Bacon.combineTemplate(value).onValue(function(x) {
expect(x).toEqual(value);
return expect(x instanceof Array).toEqual(true);
});
value = {
key: [
{
x: 1
}, {
x: 2
}
],
key2: {}
};
Bacon.combineTemplate(value).onValue(function(x) {
expect(x).toEqual(value);
return expect(x.key instanceof Array).toEqual(true);
});
value = {
key: [
{
x: 1
}, {
x: Bacon.constant(2)
}
]
};
return Bacon.combineTemplate(value).onValue(function(x) {
expect(x).toEqual({
key: [
{
x: 1
}, {
x: 2
}
]
});
return expect(x.key instanceof Array).toEqual(true);
});
});
});
describe("Property.decode", function() {
return it("switches between source Properties based on property value", function() {
return expectPropertyEvents(function() {
var a, b, c;
a = Bacon.constant("a");
b = Bacon.constant("b");
c = Bacon.constant("c");
return series(1, [1, 2, 3]).toProperty().decode({
1: a,
2: b,
3: c
});
}, ["a", "b", "c"]);
});
});
describe("Observable.onValues", function() {
return it("splits value array to callback arguments", function() {
var f;
f = mockFunction();
Bacon.constant([1, 2, 3]).onValues(f);
return f.verify(1, 2, 3);
});
});
describe("Observable.subscribe and onValue", function() {
return it("returns a dispose() for unsubscribing", function() {
var dispose, s, values;
s = new Bacon.Bus();
values = [];
dispose = s.onValue(function(value) {
return values.push(value);
});
s.push("lol");
dispose();
s.push("wut");
return expect(values).toEqual(["lol"]);
});
});
describe("Observable.onEnd", function() {
return it("is called on stream end", function() {
var ended, s;
s = new Bacon.Bus();
ended = false;
s.onEnd(function() {
return ended = true;
});
s.push("LOL");
expect(ended).toEqual(false);
s.end();
return expect(ended).toEqual(true);
});
});
describe("Field value extraction", function() {
it("extracts field value", function() {
return expectStreamEvents(function() {
return Bacon.once({
lol: "wut"
}).map(".lol");
}, ["wut"]);
});
it("extracts nested field value", function() {
return expectStreamEvents(function() {
return Bacon.once({
lol: {
wut: "wat"
}
}).map(".lol.wut");
}, ["wat"]);
});
return it("if field value is method, it does a method call", function() {
var context, object, result;
context = null;
result = null;
object = {
method: function() {
context = this;
return "result";
}
};
Bacon.once(object).map(".method").onValue(function(x) {
return result = x;
});
expect(result).toEqual("result");
return expect(context).toEqual(object);
});
});
testSideEffects = function(wrapper, method) {
return function() {
it("(f) calls function with property value", function() {
var f;
f = mockFunction();
wrapper("kaboom")[method](f);
return f.verify("kaboom");
});
it("(f, param) calls function, partially applied with param", function() {
var f;
f = mockFunction();
wrapper("kaboom")[method](f, "pow");
return f.verify("pow", "kaboom");
});
it("('.method') calls event value object method", function() {
var value;
value = mock("get");
value.when().get().thenReturn("pow");
wrapper(value)[method](".get");
return value.verify().get();
});
it("('.method', param) calls event value object method with param", function() {
var value;
value = mock("get");
value.when().get("value").thenReturn("pow");
wrapper(value)[method](".get", "value");
return value.verify().get("value");
});
it("(object, method) calls object method with property value", function() {
var target;
target = mock("pow");
wrapper("kaboom")[method](target, "pow");
return target.verify().pow("kaboom");
});
it("(object, method, param) partially applies object method with param", function() {
var target;
target = mock("pow");
wrapper("kaboom")[method](target, "pow", "smack");
return target.verify().pow("smack", "kaboom");
});
return it("(object, method, param1, param2) partially applies with 2 args", function() {
var target;
target = mock("pow");
wrapper("kaboom")[method](target, "pow", "smack", "whack");
return target.verify().pow("smack", "whack", "kaboom");
});
};
};
describe("Property.onValue", testSideEffects(Bacon.constant, "onValue"));
describe("Property.assign", testSideEffects(Bacon.constant, "assign"));
describe("EventStream.onValue", testSideEffects(Bacon.once, "onValue"));
describe("Property.assign", function() {
it("calls given objects given method with property values", function() {
var target;
target = mock("pow");
Bacon.constant("kaboom").assign(target, "pow");
return target.verify().pow("kaboom");
});
it("allows partial application of method (i.e. adding fixed args)", function() {
var target;
target = mock("pow");
Bacon.constant("kaboom").assign(target, "pow", "smack");
return target.verify().pow("smack", "kaboom");
});
return it("allows partial application of method with 2 args (i.e. adding fixed args)", function() {
var target;
target = mock("pow");
Bacon.constant("kaboom").assign(target, "pow", "smack", "whack");
return target.verify().pow("smack", "whack", "kaboom");
});
});
describe("Bacon.Bus", function() {
it("merges plugged-in streams", function() {
var bus, dispose, push, values;
bus = new Bacon.Bus();
values = [];
dispose = bus.onValue(function(value) {
return values.push(value);
});
push = new Bacon.Bus();
bus.plug(push);
push.push("lol");
expect(values).toEqual(["lol"]);
dispose();
return verifyCleanup();
});
it("works with looped streams", function() {
return expectStreamEvents(function() {
var bus,
_this = this;
bus = new Bacon.Bus();
bus.plug(Bacon.later(t(2), "lol"));
bus.plug(bus.filter(function(value) {
return "lol" === value;
}).map(function() {
return "wut";
}));
Bacon.later(t(4)).onValue(function() {
return bus.end();
});
return bus;
}, ["lol", "wut"]);
});
it("dispose works with looped streams", function() {
var bus, dispose,
_this = this;
bus = new Bacon.Bus();
bus.plug(Bacon.later(t(2), "lol"));
bus.plug(bus.filter(function(value) {
return "lol" === value;
}).map(function() {
return "wut";
}));
dispose = bus.onValue(function() {});
return dispose();
});
it("Removes input from input list on End event", function() {
var bus, dispose, input, inputSubscribe, subscribed,
_this = this;
subscribed = 0;
bus = new Bacon.Bus();
input = new Bacon.Bus();
inputSubscribe = input.subscribe;
input.subscribe = function(sink) {
subscribed++;
return inputSubscribe(sink);
};
bus.plug(input);
dispose = bus.onValue(function() {});
input.end();
dispose();
bus.onValue(function() {});
return expect(subscribed).toEqual(1);
});
it("unsubscribes inputs on end() call", function() {
var bus, events, input,
_this = this;
bus = new Bacon.Bus();
input = new Bacon.Bus();
events = [];
bus.plug(input);
bus.subscribe(function(e) {
return events.push(e);
});
input.push("a");
bus.end();
input.push("b");
return expect(toValues(events)).toEqual(["a", "<end>"]);
});
it("handles cold single-event streams correctly (bug fix)", function() {
var bus, values;
values = [];
bus = new Bacon.Bus();
bus.plug(Bacon.once("x"));
bus.plug(Bacon.once("y"));
bus.onValue(function(x) {
return values.push(x);
});
return expect(values).toEqual(["x", "y"]);
});
it("handles end() calls even when there are no subscribers", function() {
var bus;
bus = new Bacon.Bus();
return bus.end();
});
it("delivers pushed events and errors", function() {
return expectStreamEvents(function() {
var s;
s = new Bacon.Bus();
s.push("pullMe");
soon(function() {
s.push("pushMe");
s.error();
return s.end();
});
return s;
}, ["pushMe", error()]);
});
it("does not deliver pushed events after end() call", function() {
var bus, called;
called = false;
bus = new Bacon.Bus();
bus.onValue(function() {
return called = true;
});
bus.end();
bus.push("LOL");
return expect(called).toEqual(false);
});
it("does not plug after end() call", function() {
var bus, plugged;
plugged = false;
bus = new Bacon.Bus();
bus.end();
bus.plug(new Bacon.EventStream(function(sink) {
plugged = true;
return function() {};
}));
bus.onValue(function() {});
return expect(plugged).toEqual(false);
});
return it("returns unplug function from plug", function() {
var bus, src, unplug, values;
values = [];
bus = new Bacon.Bus();
src = new Bacon.Bus();
unplug = bus.plug(src);
bus.onValue(function(x) {
return values.push(x);
});
src.push("x");
unplug();
src.push("y");
return expect(values).toEqual(["x"]);
});
});
describe("EventStream", function() {
return it("works with functions as values (bug fix)", function() {
expectStreamEvents(function() {
return Bacon.once(function() {
return "hello";
}).map(function(f) {
return f();
});
}, ["hello"]);
expectStreamEvents(function() {
return Bacon.once(function() {
return "hello";
}).flatMap(Bacon.once).map(function(f) {
return f();
});
}, ["hello"]);
expectPropertyEvents(function() {
return Bacon.constant(function() {
return "hello";
}).map(function(f) {
return f();
});
}, ["hello"]);
return expectStreamEvents(function() {
return Bacon.constant(function() {
return "hello";
}).flatMap(Bacon.once).map(function(f) {
return f();
});
}, ["hello"]);
});
});
lessThan = function(limit) {
return function(x) {
return x < limit;
};
};
times = function(x, y) {
return x * y;
};
add = function(x, y) {
return x + y;
};
id = function(x) {
return x;
};
toEventTarget = function(emitter) {
return {
addEventListener: function(event, handler) {
return emitter.addListener(event, handler);
},
removeEventListener: function(event, handler) {
return emitter.removeListener(event, handler);
}
};
};
}).call(this);
});
require.define("events",function(require,module,exports,__dirname,__filename,process,global){if (!process.EventEmitter) process.EventEmitter = function () {};
var EventEmitter = exports.EventEmitter = process.EventEmitter;
var isArray = typeof Array.isArray === 'function'
? Array.isArray
: function (xs) {
return Object.prototype.toString.call(xs) === '[object Array]'
}
;
function indexOf (xs, x) {
if (xs.indexOf) return xs.indexOf(x);
for (var i = 0; i < xs.length; i++) {
if (x === xs[i]) return i;
}
return -1;
}
// By default EventEmitters will print a warning if more than
// 10 listeners are added to it. This is a useful default which
// helps finding memory leaks.
//
// Obviously not all Emitters should be limited to 10. This function allows
// that to be increased. Set to zero for unlimited.
var defaultMaxListeners = 10;
EventEmitter.prototype.setMaxListeners = function(n) {
if (!this._events) this._events = {};
this._events.maxListeners = n;
};
EventEmitter.prototype.emit = function(type) {
// If there is no 'error' event listener then throw.
if (type === 'error') {
if (!this._events || !this._events.error ||
(isArray(this._events.error) && !this._events.error.length))
{
if (arguments[1] instanceof Error) {
throw arguments[1]; // Unhandled 'error' event
} else {
throw new Error("Uncaught, unspecified 'error' event.");
}
return false;
}
}
if (!this._events) return false;
var handler = this._events[type];
if (!handler) return false;
if (typeof handler == 'function') {
switch (arguments.length) {
// fast cases
case 1:
handler.call(this);
break;
case 2:
handler.call(this, arguments[1]);
break;
case 3:
handler.call(this, arguments[1], arguments[2]);
break;
// slower
default:
var args = Array.prototype.slice.call(arguments, 1);
handler.apply(this, args);
}
return true;
} else if (isArray(handler)) {
var args = Array.prototype.slice.call(arguments, 1);
var listeners = handler.slice();
for (var i = 0, l = listeners.length; i < l; i++) {
listeners[i].apply(this, args);
}
return true;
} else {
return false;
}
};
// EventEmitter is defined in src/node_events.cc
// EventEmitter.prototype.emit() is also defined there.
EventEmitter.prototype.addListener = function(type, listener) {
if ('function' !== typeof listener) {
throw new Error('addListener only takes instances of Function');
}
if (!this._events) this._events = {};
// To avoid recursion in the case that type == "newListeners"! Before
// adding it to the listeners, first emit "newListeners".
this.emit('newListener', type, listener);
if (!this._events[type]) {
// Optimize the case of one listener. Don't need the extra array object.
this._events[type] = listener;
} else if (isArray(this._events[type])) {
// Check for listener leak
if (!this._events[type].warned) {
var m;
if (this._events.maxListeners !== undefined) {
m = this._events.maxListeners;
} else {
m = defaultMaxListeners;
}
if (m && m > 0 && this._events[type].length > m) {
this._events[type].warned = true;
console.error('(node) warning: possible EventEmitter memory ' +
'leak detected. %d listeners added. ' +
'Use emitter.setMaxListeners() to increase limit.',
this._events[type].length);
console.trace();
}
}
// If we've already got an array, just append.
this._events[type].push(listener);
} else {
// Adding the second element, need to change to array.
this._events[type] = [this._events[type], listener];
}
return this;
};
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.once = function(type, listener) {
var self = this;
self.on(type, function g() {
self.removeListener(type, g);
listener.apply(this, arguments);
});
return this;
};
EventEmitter.prototype.removeListener = function(type, listener) {
if ('function' !== typeof listener) {
throw new Error('removeListener only takes instances of Function');
}
// does not use listeners(), so no side effect of creating _events[type]
if (!this._events || !this._events[type]) return this;
var list = this._events[type];
if (isArray(list)) {
var i = indexOf(list, listener);
if (i < 0) return this;
list.splice(i, 1);
if (list.length == 0)
delete this._events[type];
} else if (this._events[type] === listener) {
delete this._events[type];
}
return this;
};
EventEmitter.prototype.removeAllListeners = function(type) {
// does not use listeners(), so no side effect of creating _events[type]
if (type && this._events && this._events[type]) this._events[type] = null;
return this;
};
EventEmitter.prototype.listeners = function(type) {
if (!this._events) this._events = {};
if (!this._events[type]) this._events[type] = [];
if (!isArray(this._events[type])) {
this._events[type] = [this._events[type]];
}
return this._events[type];
};
});
require.define("/spec/PromiseSpec.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
var Bacon, calls, fail, promise, success, _;
Bacon = (require("../src/Bacon")).Bacon;
success = void 0;
fail = void 0;
calls = 0;
promise = {
then: function(s, f) {
success = s;
fail = f;
return calls = calls + 1;
}
};
_ = Bacon._;
describe("Bacon.fromPromise", function() {
it("should produce value and end on success", function() {
var events,
_this = this;
events = [];
Bacon.fromPromise(promise).subscribe(function(e) {
return events.push(e);
});
success("a");
return expect(_.map((function(e) {
return e.describe();
}), events)).toEqual(["a", "<end>"]);
});
it("should produce error and end on error", function() {
var events,
_this = this;
events = [];
Bacon.fromPromise(promise).subscribe(function(e) {
return events.push(e);
});
fail("a");
return expect(events).toEqual([new Bacon.Error("a"), new Bacon.End()]);
});
return it("should respect unsubscription", function() {
var dispose, events,
_this = this;
events = [];
dispose = Bacon.fromPromise(promise).subscribe(function(e) {
return events.push(e);
});
dispose();
success("a");
return expect(events).toEqual([]);
});
});
}).call(this);
});
require.define("/browsertest/jasmine-harness.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
var currentWindowOnload, expose, html, startJasmine, tap;
expose = function(obj) {
var key, _results;
_results = [];
for (key in obj) {
_results.push(window[key] = obj[key]);
}
return _results;
};
if (typeof jasmine === "undefined" || jasmine === null) {
expose(require('../spec/lib/jasmine.js'));
}
html = require('../spec/lib/jasmine-html.js');
tap = require('../spec/lib/jasmine.tap_reporter.js');
expose(require('../spec/SpecHelper'));
expose(require('../spec/Mock'));
require('../spec/BaconSpec');
require('../spec/PromiseSpec');
describe('Basic Suite', function() {
return it('Should pass a basic truthiness test.', function() {
expect(true).toEqual(true);
return expect(false).toEqual(false);
});
});
startJasmine = function() {
var env;
env = jasmine.getEnv();
env.addReporter(new jasmine.TapReporter());
return env.execute();
};
currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload != null) {
currentWindowOnload();
}
return setTimeout(startJasmine, 1);
};
}).call(this);
});
require("/browsertest/jasmine-harness.coffee");
})();
<html>
<head>
<meta charset="utf-8">
<title>D3 realtime visulization</title>
<style type="text/css">
.chart rect {
stroke: white;
fill: steelblue;
}
.chart line {
stroke: white;
fill: steelblue;
}
</style>
<script src="https://raw.github.com/searls/jasmine-all/master/jasmine-all-min.js"></script>
<script>
if (location.hash === '#testem')
document.write('<script src="/testem.js"></'+'script>')
</script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
<script src="https://raw.github.com/mennovanslooten/Observable-Arrays/master/js/underscore.observable.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="https://raw.github.com/airportyh/testem/master/public/testem/jasmine_adapter.js"></script>
<script src="https://raw.github.com/raimohanska/bacon.js/master/dist/Bacon.min.js"></script>
<script src="http://coffeescript.org/extras/coffee-script.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/d3/3.0.1/d3.v3.min.js"></script>
</head>
<body>
<h1>Real-time data visulization by D3.js and Bacon.js</h1>
<p>Data source: Test Coverage of Bacon.js</p>
<p>X: log coverage Y: lineno</p>
<div class="coverage"></div>
<script src="bundle.js"></script>
<script type="text/coffeescript">
# Settings
w = 960
h = 3000
svg = d3.select(".coverage").append("svg")
.attr("class", "chart")
.attr("width", w)
.attr("height", h)
.append("g")
lineno = [0..9]
lineno[i] = n * 100 for n, i in lineno
svg.selectAll("text").data(lineno)
.enter().append("text")
.attr("y", (d) -> if d is 0 then 20 else d * 3)
.attr("x", 40)
.attr("text-anchor", "middle")
.text((d) -> if d is 0 then 'line number' else d)
window.coverage = new Bacon.Bus() unless window.coverage?
coverage.onValue (data) ->
x = d3.scale.log().domain([1, 7157]).range([0, w])
# bar chart
bar = svg.selectAll("rect").data(data)
bar.enter().append("rect")
.attr("y", (d, i) -> i * 3)
.attr("x", 100)
.attr("height", 3)
bar.attr("width", x)
bar.exit().remove()
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment