js: Build updated mopidy.js

This commit is contained in:
Stein Magnus Jodal 2014-01-04 00:07:12 +01:00
parent c7e96cf992
commit edc27135fd
2 changed files with 207 additions and 221 deletions

View File

@ -1,8 +1,8 @@
/*! Mopidy.js - built 2013-12-15 /*! Mopidy.js - built 2014-01-04
* http://www.mopidy.com/ * http://www.mopidy.com/
* Copyright (c) 2013 Stein Magnus Jodal and contributors * Copyright (c) 2014 Stein Magnus Jodal and contributors
* Licensed under the Apache License, Version 2.0 */ * Licensed under the Apache License, Version 2.0 */
!function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.Mopidy=e():"undefined"!=typeof global?global.Mopidy=e():"undefined"!=typeof self&&(self.Mopidy=e())}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ !function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Mopidy=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
module.exports = { Client: window.WebSocket }; module.exports = { Client: window.WebSocket };
},{}],2:[function(require,module,exports){ },{}],2:[function(require,module,exports){
@ -167,7 +167,18 @@ module.exports = { Client: window.WebSocket };
return object; return object;
} }
return { createEventEmitter: createEventEmitter }; return {
createEventEmitter: createEventEmitter,
aggregate: function (emitters) {
var aggregate = createEventEmitter();
emitters.forEach(function (emitter) {
emitter.on(function (event, data) {
aggregate.emit(event, data);
});
});
return aggregate;
}
};
}); });
},{}],3:[function(require,module,exports){ },{}],3:[function(require,module,exports){
@ -189,7 +200,8 @@ process.nextTick = (function () {
if (canPost) { if (canPost) {
var queue = []; var queue = [];
window.addEventListener('message', function (ev) { window.addEventListener('message', function (ev) {
if (ev.source === window && ev.data === 'process-tick') { var source = ev.source;
if ((source === window || source === null) && ev.data === 'process-tick') {
ev.stopPropagation(); ev.stopPropagation();
if (queue.length > 0) { if (queue.length > 0) {
var fn = queue.shift(); var fn = queue.shift();
@ -236,7 +248,7 @@ var process=require("__browserify_process");/** @license MIT License (c) copyrig
* *
* @author Brian Cavalier * @author Brian Cavalier
* @author John Hann * @author John Hann
* @version 2.7.0 * @version 2.7.1
*/ */
(function(define) { 'use strict'; (function(define) { 'use strict';
define(function (require) { define(function (require) {
@ -282,8 +294,14 @@ define(function (require) {
return cast(promiseOrValue).then(onFulfilled, onRejected, onProgress); return cast(promiseOrValue).then(onFulfilled, onRejected, onProgress);
} }
function cast(x) { /**
return x instanceof Promise ? x : resolve(x); * Creates a new promise whose fate is determined by resolver.
* @param {function} resolver function(resolve, reject, notify)
* @returns {Promise} promise whose fate is determine by resolver
*/
function promise(resolver) {
return new Promise(resolver,
monitorApi.PromiseStatus && monitorApi.PromiseStatus());
} }
/** /**
@ -291,16 +309,90 @@ define(function (require) {
* a trusted when.js promise. Any other duck-typed promise is considered * a trusted when.js promise. Any other duck-typed promise is considered
* untrusted. * untrusted.
* @constructor * @constructor
* @param {function} sendMessage function to deliver messages to the promise's handler * @returns {Promise} promise whose fate is determine by resolver
* @param {function?} inspect function that reports the promise's state
* @name Promise * @name Promise
*/ */
function Promise(sendMessage, inspect) { function Promise(resolver, status) {
this._message = sendMessage; var self, value, consumers = [];
self = this;
this._status = status;
this.inspect = inspect; this.inspect = inspect;
this._when = _when;
// Call the provider resolver to seal the promise's fate
try {
resolver(promiseResolve, promiseReject, promiseNotify);
} catch(e) {
promiseReject(e);
}
/**
* Returns a snapshot of this promise's current status at the instant of call
* @returns {{state:String}}
*/
function inspect() {
return value ? value.inspect() : toPendingState();
}
/**
* Private message delivery. Queues and delivers messages to
* the promise's ultimate fulfillment value or rejection reason.
* @private
*/
function _when(resolve, notify, onFulfilled, onRejected, onProgress) {
consumers ? consumers.push(deliver) : enqueue(function() { deliver(value); });
function deliver(p) {
p._when(resolve, notify, onFulfilled, onRejected, onProgress);
}
}
/**
* Transition from pre-resolution state to post-resolution state, notifying
* all listeners of the ultimate fulfillment or rejection
* @param {*} val resolution value
*/
function promiseResolve(val) {
if(!consumers) {
return;
}
var queue = consumers;
consumers = undef;
enqueue(function () {
value = coerce(self, val);
if(status) {
updateStatus(value, status);
}
runHandlers(queue, value);
});
}
/**
* Reject this promise with the supplied reason, which will be used verbatim.
* @param {*} reason reason for the rejection
*/
function promiseReject(reason) {
promiseResolve(new RejectedPromise(reason));
}
/**
* Issue a progress event, notifying all progress listeners
* @param {*} update progress event payload to pass to all listeners
*/
function promiseNotify(update) {
if(consumers) {
var queue = consumers;
enqueue(function () {
runHandlers(queue, new ProgressingPromise(update));
});
}
}
} }
var promisePrototype = Promise.prototype; promisePrototype = Promise.prototype;
/** /**
* Register handlers for this promise. * Register handlers for this promise.
@ -310,14 +402,10 @@ define(function (require) {
* @return {Promise} new Promise * @return {Promise} new Promise
*/ */
promisePrototype.then = function(onFulfilled, onRejected, onProgress) { promisePrototype.then = function(onFulfilled, onRejected, onProgress) {
/*jshint unused:false*/ var self = this;
var args, sendMessage;
args = arguments; return new Promise(function(resolve, reject, notify) {
sendMessage = this._message; self._when(resolve, notify, onFulfilled, onRejected, onProgress);
return _promise(function(resolve, reject, notify) {
sendMessage('when', args, resolve, notify);
}, this._status && this._status.observed()); }, this._status && this._status.observed());
}; };
@ -361,7 +449,7 @@ define(function (require) {
* @returns {undefined} * @returns {undefined}
*/ */
promisePrototype.done = function(handleResult, handleError) { promisePrototype.done = function(handleResult, handleError) {
this.then(handleResult, handleError).otherwise(crash); this.then(handleResult, handleError)['catch'](crash);
}; };
/** /**
@ -412,12 +500,23 @@ define(function (require) {
return this.then(onFulfilledOrRejected, onFulfilledOrRejected, onProgress); return this.then(onFulfilledOrRejected, onFulfilledOrRejected, onProgress);
}; };
/**
* Casts x to a trusted promise. If x is already a trusted promise, it is
* returned, otherwise a new trusted Promise which follows x is returned.
* @param {*} x
* @returns {Promise}
*/
function cast(x) {
return x instanceof Promise ? x : resolve(x);
}
/** /**
* Returns a resolved promise. The returned promise will be * Returns a resolved promise. The returned promise will be
* - fulfilled with promiseOrValue if it is a value, or * - fulfilled with promiseOrValue if it is a value, or
* - if promiseOrValue is a promise * - if promiseOrValue is a promise
* - fulfilled with promiseOrValue's value after it is fulfilled * - fulfilled with promiseOrValue's value after it is fulfilled
* - rejected with promiseOrValue's reason after it is rejected * - rejected with promiseOrValue's reason after it is rejected
* In contract to cast(x), this always creates a new Promise
* @param {*} value * @param {*} value
* @return {Promise} * @return {Promise}
*/ */
@ -438,7 +537,9 @@ define(function (require) {
* @return {Promise} rejected {@link Promise} * @return {Promise} rejected {@link Promise}
*/ */
function reject(promiseOrValue) { function reject(promiseOrValue) {
return when(promiseOrValue, rejected); return when(promiseOrValue, function(e) {
return new RejectedPromise(e);
});
} }
/** /**
@ -483,7 +584,7 @@ define(function (require) {
deferred.reject = deferred.resolver.reject = function(reason) { deferred.reject = deferred.resolver.reject = function(reason) {
if(resolved) { if(resolved) {
return resolve(rejected(reason)); return resolve(new RejectedPromise(reason));
} }
resolved = true; resolved = true;
rejectPending(reason); rejectPending(reason);
@ -497,112 +598,6 @@ define(function (require) {
} }
} }
/**
* Creates a new promise whose fate is determined by resolver.
* @param {function} resolver function(resolve, reject, notify)
* @returns {Promise} promise whose fate is determine by resolver
*/
function promise(resolver) {
return _promise(resolver, monitorApi.PromiseStatus && monitorApi.PromiseStatus());
}
/**
* Creates a new promise, linked to parent, whose fate is determined
* by resolver.
* @param {function} resolver function(resolve, reject, notify)
* @param {Promise?} status promise from which the new promise is begotten
* @returns {Promise} promise whose fate is determine by resolver
* @private
*/
function _promise(resolver, status) {
var self, value, consumers = [];
self = new Promise(_message, inspect);
self._status = status;
// Call the provider resolver to seal the promise's fate
try {
resolver(promiseResolve, promiseReject, promiseNotify);
} catch(e) {
promiseReject(e);
}
// Return the promise
return self;
/**
* Private message delivery. Queues and delivers messages to
* the promise's ultimate fulfillment value or rejection reason.
* @private
* @param {String} type
* @param {Array} args
* @param {Function} resolve
* @param {Function} notify
*/
function _message(type, args, resolve, notify) {
consumers ? consumers.push(deliver) : enqueue(function() { deliver(value); });
function deliver(p) {
p._message(type, args, resolve, notify);
}
}
/**
* Returns a snapshot of the promise's state at the instant inspect()
* is called. The returned object is not live and will not update as
* the promise's state changes.
* @returns {{ state:String, value?:*, reason?:* }} status snapshot
* of the promise.
*/
function inspect() {
return value ? value.inspect() : toPendingState();
}
/**
* Transition from pre-resolution state to post-resolution state, notifying
* all listeners of the ultimate fulfillment or rejection
* @param {*|Promise} val resolution value
*/
function promiseResolve(val) {
if(!consumers) {
return;
}
var queue = consumers;
consumers = undef;
enqueue(function () {
value = coerce(self, val);
if(status) {
updateStatus(value, status);
}
runHandlers(queue, value);
});
}
/**
* Reject this promise with the supplied reason, which will be used verbatim.
* @param {*} reason reason for the rejection
*/
function promiseReject(reason) {
promiseResolve(rejected(reason));
}
/**
* Issue a progress event, notifying all progress listeners
* @param {*} update progress event payload to pass to all listeners
*/
function promiseNotify(update) {
if(consumers) {
var queue = consumers;
enqueue(function () {
runHandlers(queue, progressed(update));
});
}
}
}
/** /**
* Run a queue of functions as quickly as possible, passing * Run a queue of functions as quickly as possible, passing
* value to each. * value to each.
@ -613,67 +608,6 @@ define(function (require) {
} }
} }
/**
* Creates a fulfilled, local promise as a proxy for a value
* NOTE: must never be exposed
* @param {*} value fulfillment value
* @returns {Promise}
*/
function fulfilled(value) {
return near(
new NearFulfilledProxy(value),
function() { return toFulfilledState(value); }
);
}
/**
* Creates a rejected, local promise with the supplied reason
* NOTE: must never be exposed
* @param {*} reason rejection reason
* @returns {Promise}
*/
function rejected(reason) {
return near(
new NearRejectedProxy(reason),
function() { return toRejectedState(reason); }
);
}
/**
* Creates a near promise using the provided proxy
* NOTE: must never be exposed
* @param {object} proxy proxy for the promise's ultimate value or reason
* @param {function} inspect function that returns a snapshot of the
* returned near promise's state
* @returns {Promise}
*/
function near(proxy, inspect) {
return new Promise(function (type, args, resolve) {
try {
resolve(proxy[type].apply(proxy, args));
} catch(e) {
resolve(rejected(e));
}
}, inspect);
}
/**
* Create a progress promise with the supplied update.
* @private
* @param {*} update
* @return {Promise} progress promise
*/
function progressed(update) {
return new Promise(function (type, args, _, notify) {
var onProgress = args[2];
try {
notify(typeof onProgress === 'function' ? onProgress(update) : update);
} catch(e) {
notify(e);
}
});
}
/** /**
* Coerces x to a trusted Promise * Coerces x to a trusted Promise
* @param {*} x thing to coerce * @param {*} x thing to coerce
@ -685,7 +619,7 @@ define(function (require) {
*/ */
function coerce(self, x) { function coerce(self, x) {
if (x === self) { if (x === self) {
return rejected(new TypeError()); return new RejectedPromise(new TypeError());
} }
if (x instanceof Promise) { if (x instanceof Promise) {
@ -697,9 +631,9 @@ define(function (require) {
return typeof untrustedThen === 'function' return typeof untrustedThen === 'function'
? assimilate(untrustedThen, x) ? assimilate(untrustedThen, x)
: fulfilled(x); : new FulfilledPromise(x);
} catch(e) { } catch(e) {
return rejected(e); return new RejectedPromise(e);
} }
} }
@ -715,36 +649,89 @@ define(function (require) {
}); });
} }
makePromisePrototype = Object.create ||
function(o) {
function PromisePrototype() {}
PromisePrototype.prototype = o;
return new PromisePrototype();
};
/** /**
* Proxy for a near, fulfilled value * Creates a fulfilled, local promise as a proxy for a value
* @param {*} value * NOTE: must never be exposed
* @constructor * @private
* @param {*} value fulfillment value
* @returns {Promise}
*/ */
function NearFulfilledProxy(value) { function FulfilledPromise(value) {
this.value = value; this.value = value;
} }
NearFulfilledProxy.prototype.when = function(onResult) { FulfilledPromise.prototype = makePromisePrototype(promisePrototype);
return typeof onResult === 'function' ? onResult(this.value) : this.value;
FulfilledPromise.prototype.inspect = function() {
return toFulfilledState(this.value);
}; };
/** FulfilledPromise.prototype._when = function(resolve, _, onFulfilled) {
* Proxy for a near rejection try {
* @param {*} reason resolve(typeof onFulfilled === 'function' ? onFulfilled(this.value) : this.value);
* @constructor } catch(e) {
*/ resolve(new RejectedPromise(e));
function NearRejectedProxy(reason) {
this.reason = reason;
}
NearRejectedProxy.prototype.when = function(_, onError) {
if(typeof onError === 'function') {
return onError(this.reason);
} else {
throw this.reason;
} }
}; };
/**
* Creates a rejected, local promise as a proxy for a value
* NOTE: must never be exposed
* @private
* @param {*} reason rejection reason
* @returns {Promise}
*/
function RejectedPromise(reason) {
this.value = reason;
}
RejectedPromise.prototype = makePromisePrototype(promisePrototype);
RejectedPromise.prototype.inspect = function() {
return toRejectedState(this.value);
};
RejectedPromise.prototype._when = function(resolve, _, __, onRejected) {
try {
resolve(typeof onRejected === 'function' ? onRejected(this.value) : this);
} catch(e) {
resolve(new RejectedPromise(e));
}
};
/**
* Create a progress promise with the supplied update.
* @private
* @param {*} value progress update value
* @return {Promise} progress promise
*/
function ProgressingPromise(value) {
this.value = value;
}
ProgressingPromise.prototype = makePromisePrototype(promisePrototype);
ProgressingPromise.prototype._when = function(_, notify, f, r, u) {
try {
notify(typeof u === 'function' ? u(this.value) : this.value);
} catch(e) {
notify(e);
}
};
/**
* Update a PromiseStatus monitor object with the outcome
* of the supplied value promise.
* @param {Promise} value
* @param {PromiseStatus} status
*/
function updateStatus(value, status) { function updateStatus(value, status) {
value.then(statusFulfilled, statusRejected); value.then(statusFulfilled, statusRejected);
@ -921,7 +908,7 @@ define(function (require) {
function _map(array, mapFunc, fallback) { function _map(array, mapFunc, fallback) {
return when(array, function(array) { return when(array, function(array) {
return _promise(resolveMap); return new Promise(resolveMap);
function resolveMap(resolve, reject, notify) { function resolveMap(resolve, reject, notify) {
var results, len, toResolve, i; var results, len, toResolve, i;
@ -1028,7 +1015,7 @@ define(function (require) {
// Internals, utilities, etc. // Internals, utilities, etc.
// //
var reduceArray, slice, fcall, nextTick, handlerQueue, var promisePrototype, makePromisePrototype, reduceArray, slice, fcall, nextTick, handlerQueue,
funcProto, call, arrayProto, monitorApi, funcProto, call, arrayProto, monitorApi,
capturedSetTimeout, cjsRequire, MutationObs, undef; capturedSetTimeout, cjsRequire, MutationObs, undef;
@ -1476,4 +1463,3 @@ module.exports = Mopidy;
},{"../lib/websocket/":1,"bane":2,"when":4}]},{},[5]) },{"../lib/websocket/":1,"bane":2,"when":4}]},{},[5])
(5) (5)
}); });
;

File diff suppressed because one or more lines are too long