Comparing version 0.17.0 to 0.17.1
@@ -7,3 +7,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */ | ||
var streamOf = require('../source/core').of; | ||
var flatMapEnd = require('./flatMapEnd').flatMapEnd; | ||
var continueWith = require('./continueWith').continueWith; | ||
var Sink = require('../sink/Pipe'); | ||
@@ -32,3 +32,3 @@ var Promise = require('../Promise'); | ||
function concat(left, right) { | ||
return flatMapEnd(returnRight, left); | ||
return continueWith(returnRight, left); | ||
@@ -35,0 +35,0 @@ function returnRight() { |
@@ -8,3 +8,4 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */ | ||
exports.flatMapError = flatMapError; | ||
exports.flatMapError = recoverWith; | ||
exports.recoverWith = recoverWith; | ||
exports.throwError = throwError; | ||
@@ -19,4 +20,4 @@ | ||
*/ | ||
function flatMapError(f, stream) { | ||
return new Stream(new FlatMapError(f, stream.source)); | ||
function recoverWith(f, stream) { | ||
return new Stream(new RecoverWith(f, stream.source)); | ||
} | ||
@@ -37,3 +38,3 @@ | ||
function FlatMapError(f, source) { | ||
function RecoverWith(f, source) { | ||
this.f = f; | ||
@@ -43,7 +44,7 @@ this.source = source; | ||
FlatMapError.prototype.run = function(sink, scheduler) { | ||
return new FlatMapErrorSink(this.f, this.source, sink, scheduler); | ||
RecoverWith.prototype.run = function(sink, scheduler) { | ||
return new RecoverWithSink(this.f, this.source, sink, scheduler); | ||
}; | ||
function FlatMapErrorSink(f, source, sink, scheduler) { | ||
function RecoverWithSink(f, source, sink, scheduler) { | ||
this.f = f; | ||
@@ -56,3 +57,3 @@ this.sink = sink; | ||
FlatMapErrorSink.prototype.error = function(t, e) { | ||
RecoverWithSink.prototype.error = function(t, e) { | ||
if(!this.active) { | ||
@@ -71,3 +72,3 @@ return; | ||
FlatMapErrorSink.prototype.event = function(t, x) { | ||
RecoverWithSink.prototype.event = function(t, x) { | ||
if(!this.active) { | ||
@@ -79,3 +80,3 @@ return; | ||
FlatMapErrorSink.prototype.end = function(t, x) { | ||
RecoverWithSink.prototype.end = function(t, x) { | ||
if(!this.active) { | ||
@@ -87,5 +88,5 @@ return; | ||
FlatMapErrorSink.prototype.dispose = function() { | ||
RecoverWithSink.prototype.dispose = function() { | ||
this.active = false; | ||
return this.disposable.dispose(); | ||
}; | ||
}; |
@@ -10,3 +10,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */ | ||
exports.fromPromise = fromPromise; | ||
exports.await = await; | ||
exports.awaitPromises = awaitPromises; | ||
@@ -73,3 +73,3 @@ /** | ||
*/ | ||
function await(stream) { | ||
function awaitPromises(stream) { | ||
return new Stream(new Await(stream.source)); | ||
@@ -76,0 +76,0 @@ } |
@@ -8,5 +8,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */ | ||
var dispose = require('../disposable/dispose'); | ||
var never = require('../source/core').never; | ||
var join = require('../combinator/flatMap').join; | ||
var take = require('../combinator/slice').take; | ||
var noop = require('../base').noop; | ||
@@ -23,13 +21,9 @@ | ||
function skipUntil(signal, stream) { | ||
return between(signal, never(), stream); | ||
return new Stream(new Since(signal.source, stream.source)); | ||
} | ||
function during(timeWindow, stream) { | ||
return between(timeWindow, join(timeWindow), stream); | ||
return takeUntil(join(timeWindow), skipUntil(timeWindow, stream)); | ||
} | ||
function between(start, end, stream) { | ||
return new Stream(new During(take(1, start).source, take(1, end).source, stream.source)); | ||
} | ||
function Until(maxSignal, source) { | ||
@@ -41,3 +35,3 @@ this.maxSignal = maxSignal; | ||
Until.prototype.run = function(sink, scheduler) { | ||
var min = new MinBound(sink); | ||
var min = new Bound(-Infinity, sink); | ||
var max = new UpperBound(this.maxSignal, sink, scheduler); | ||
@@ -49,21 +43,10 @@ var disposable = this.source.run(new TimeWindowSink(min, max, sink), scheduler); | ||
function MinBound(sink) { | ||
this.value = -Infinity; | ||
this.sink = sink; | ||
} | ||
MinBound.prototype.error = Pipe.prototype.error; | ||
MinBound.prototype.event = noop; | ||
MinBound.prototype.end = noop; | ||
MinBound.prototype.dispose = noop; | ||
function During(minSignal, maxSignal, source) { | ||
function Since(minSignal, source) { | ||
this.minSignal = minSignal; | ||
this.maxSignal = maxSignal; | ||
this.source = source; | ||
} | ||
During.prototype.run = function(sink, scheduler) { | ||
Since.prototype.run = function(sink, scheduler) { | ||
var min = new LowerBound(this.minSignal, sink, scheduler); | ||
var max = new UpperBound(this.maxSignal, sink, scheduler); | ||
var max = new Bound(Infinity, sink); | ||
var disposable = this.source.run(new TimeWindowSink(min, max, sink), scheduler); | ||
@@ -74,2 +57,12 @@ | ||
function Bound(value, sink) { | ||
this.value = value; | ||
this.sink = sink; | ||
} | ||
Bound.prototype.error = Pipe.prototype.error; | ||
Bound.prototype.event = noop; | ||
Bound.prototype.end = noop; | ||
Bound.prototype.dispose = noop; | ||
function TimeWindowSink(min, max, sink) { | ||
@@ -76,0 +69,0 @@ this.min = min; |
@@ -18,2 +18,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */ | ||
exports.settable = settable; | ||
exports.promised = promised; | ||
@@ -58,2 +59,15 @@ /** | ||
/** | ||
* Create a disposable from a promise for another disposable | ||
* @param {Promise<Disposable>} disposablePromise | ||
* @return {Disposable} | ||
*/ | ||
function promised(disposablePromise) { | ||
return newDisposable(disposePromise, disposablePromise); | ||
} | ||
function disposePromise(disposablePromise) { | ||
return disposablePromise.then(disposeOne); | ||
} | ||
/** | ||
* Create a disposable proxy that allows its underlying disposable to | ||
@@ -60,0 +74,0 @@ * be set later. |
@@ -19,7 +19,11 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */ | ||
return new Promise(function (resolve, reject) { | ||
var disposable = dispose.settable(); | ||
var observer = new Observer(f, resolve, reject, disposable); | ||
disposable.setDisposable(source.run(observer, scheduler)); | ||
runSource(f, source, scheduler, resolve, reject); | ||
}); | ||
} | ||
function runSource(f, source, scheduler, resolve, reject) { | ||
var disposable = dispose.settable(); | ||
var observer = new Observer(f, resolve, reject, disposable); | ||
disposable.setDisposable(source.run(observer, scheduler)); | ||
} |
@@ -5,55 +5,9 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */ | ||
/*global setTimeout, clearTimeout*/ | ||
var Scheduler = require('./Scheduler'); | ||
var defer = require('../defer'); | ||
var setTimeoutTimer = require('./timeoutTimer'); | ||
var nodeTimer = require('./nodeTimer'); | ||
// Default timer functions | ||
var defaultSetTimer, defaultClearTimer; | ||
var isNode = typeof process === 'object' | ||
&& typeof process.nextTick === 'function'; | ||
function Task(f) { | ||
this.f = f; | ||
this.active = true; | ||
} | ||
Task.prototype.run = function() { | ||
if(!this.active) { | ||
return; | ||
} | ||
var f = this.f; | ||
return f(); | ||
}; | ||
Task.prototype.error = function(e) { | ||
throw e; | ||
}; | ||
Task.prototype.cancel = function() { | ||
this.active = false; | ||
}; | ||
function runAsTask(f) { | ||
var task = new Task(f); | ||
defer(task); | ||
return task; | ||
} | ||
if(typeof process === 'object' && typeof process.nextTick === 'function') { | ||
defaultSetTimer = function(f, ms) { | ||
return ms <= 0 ? runAsTask(f) : setTimeout(f, ms); | ||
}; | ||
defaultClearTimer = function(t) { | ||
return t instanceof Task ? t.cancel() : clearTimeout(t); | ||
}; | ||
} | ||
else { | ||
defaultSetTimer = function(f, ms) { | ||
return setTimeout(f, ms); | ||
}; | ||
defaultClearTimer = function(t) { | ||
return clearTimeout(t); | ||
}; | ||
} | ||
module.exports = new Scheduler(defaultSetTimer, defaultClearTimer, Date.now); | ||
module.exports = new Scheduler(isNode ? nodeTimer : setTimeoutTimer); |
@@ -38,6 +38,4 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */ | ||
function Scheduler(setTimer, clearTimer, now) { | ||
this.now = now; | ||
this._setTimer = setTimer; | ||
this._clearTimer = clearTimer; | ||
function Scheduler(timer) { | ||
this.timer = timer; | ||
@@ -54,2 +52,6 @@ this._timer = null; | ||
Scheduler.prototype.now = function() { | ||
return this.timer.now(); | ||
}; | ||
Scheduler.prototype.asap = function(task) { | ||
@@ -101,3 +103,3 @@ return this.schedule(0, -1, task); | ||
Scheduler.prototype._unschedule = function() { | ||
this._clearTimer(this._timer); | ||
this.timer.clearTimer(this._timer); | ||
this._timer = null; | ||
@@ -124,3 +126,3 @@ }; | ||
var delay = Math.max(0, nextArrival - now); | ||
this._timer = this._setTimer(this._runReadyTasksBound, delay); | ||
this._timer = this.timer.setTimer(this._runReadyTasksBound, delay); | ||
}; | ||
@@ -132,3 +134,3 @@ | ||
this._findAndRunTasks(now); | ||
this._tasks = this._findAndRunTasks(now); | ||
@@ -151,4 +153,5 @@ this._scheduleNextRun(this.now()); | ||
for (var j = 0; j < i; ++j) { | ||
runTasks(tasks[j], this._tasks); | ||
this._tasks = runTasks(tasks[j], this._tasks); | ||
} | ||
return this._tasks; | ||
}; | ||
@@ -172,2 +175,4 @@ | ||
} | ||
return tasks; | ||
} | ||
@@ -174,0 +179,0 @@ |
@@ -8,2 +8,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */ | ||
var DeferredSink = require('../sink/DeferredSink'); | ||
var tryEvent = require('./tryEvent'); | ||
@@ -55,3 +56,3 @@ exports.create = create; | ||
} | ||
tryEvent(this.scheduler.now(), x, this.sink); | ||
tryEvent.tryEvent(this.scheduler.now(), x, this.sink); | ||
}; | ||
@@ -64,3 +65,3 @@ | ||
this.active = false; | ||
tryEnd(this.scheduler.now(), x, this.sink); | ||
tryEvent.tryEnd(this.scheduler.now(), x, this.sink); | ||
}; | ||
@@ -79,17 +80,1 @@ | ||
}; | ||
function tryEvent(t, x, sink) { | ||
try { | ||
sink.event(t, x); | ||
} catch(e) { | ||
sink.error(t, e); | ||
} | ||
} | ||
function tryEnd(t, x, sink) { | ||
try { | ||
sink.end(t, x); | ||
} catch(e) { | ||
sink.error(t, e); | ||
} | ||
} |
@@ -7,3 +7,4 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */ | ||
var MulticastSource = require('./MulticastSource'); | ||
var DeferredSink = require('../sink/DeferredSink'); | ||
var EventTargetSource = require('./EventTargetSource'); | ||
var EventEmitterSource = require('./EventEmitterSource'); | ||
@@ -16,9 +17,13 @@ exports.fromEvent = fromEvent; | ||
* @param {EventTarget|EventEmitter} source EventTarget or EventEmitter | ||
* @param {boolean?} useCapture for DOM events, whether to use | ||
* capturing--passed as 3rd parameter to addEventListener. | ||
* @returns {Stream} stream containing all events of the specified type | ||
* from the source. | ||
*/ | ||
function fromEvent(event, source) { | ||
function fromEvent(event, source /*, useCapture = false */) { | ||
var s; | ||
if(typeof source.addEventListener === 'function' && typeof source.removeEventListener === 'function') { | ||
s = new MulticastSource(new EventTargetSource(event, source)); | ||
var capture = arguments.length > 2 && !!arguments[2]; | ||
s = new MulticastSource(new EventTargetSource(event, source, capture)); | ||
} else if(typeof source.addListener === 'function' && typeof source.removeListener === 'function') { | ||
@@ -32,77 +37,1 @@ s = new EventEmitterSource(event, source); | ||
} | ||
function EventTargetSource(event, source) { | ||
this.event = event; | ||
this.source = source; | ||
} | ||
EventTargetSource.prototype.run = function(sink, scheduler) { | ||
return new EventAdapter(initEventTarget, this.event, this.source, sink, scheduler); | ||
}; | ||
function initEventTarget(addEvent, event, source) { | ||
source.addEventListener(event, addEvent, false); | ||
return function(event, target) { | ||
target.removeEventListener(event, addEvent, false); | ||
}; | ||
} | ||
function EventEmitterSource(event, source) { | ||
this.event = event; | ||
this.source = source; | ||
} | ||
EventEmitterSource.prototype.run = function(sink, scheduler) { | ||
// NOTE: Because EventEmitter allows events in the same call stack as | ||
// a listener is added, use a DeferredSink to buffer events | ||
// until the stack clears, then propagate. This maintains most.js's | ||
// invariant that no event will be delivered in the same call stack | ||
// as an observer begins observing. | ||
return new EventAdapter(initEventEmitter, this.event, this.source, new DeferredSink(sink), scheduler); | ||
}; | ||
function initEventEmitter(addEvent, event, source) { | ||
// EventEmitter supports varargs (eg: emitter.emit('event', a, b, c, ...)) so | ||
// have to support it here by turning into an array | ||
function addEventVariadic(a) { | ||
var l = arguments.length; | ||
if(l > 1) { | ||
var arr = new Array(l); | ||
for(var i=0; i<l; ++i) { | ||
arr[i] = arguments[i]; | ||
} | ||
addEvent(arr); | ||
} else { | ||
addEvent(a); | ||
} | ||
} | ||
source.addListener(event, addEventVariadic); | ||
return function(event, target) { | ||
target.removeListener(event, addEventVariadic); | ||
}; | ||
} | ||
function EventAdapter(init, event, source, sink, scheduler) { | ||
this.event = event; | ||
this.source = source; | ||
function addEvent(ev) { | ||
tryEvent(scheduler.now(), ev, sink); | ||
} | ||
this._dispose = init(addEvent, event, source); | ||
} | ||
EventAdapter.prototype.dispose = function() { | ||
return this._dispose(this.event, this.source); | ||
}; | ||
function tryEvent (t, x, sink) { | ||
try { | ||
sink.event(t, x); | ||
} catch(e) { | ||
sink.error(t, e); | ||
} | ||
} |
12
most.js
@@ -268,6 +268,6 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */ | ||
var flatMapEnd = require('./lib/combinator/flatMapEnd').flatMapEnd; | ||
var continueWith = require('./lib/combinator/continueWith').continueWith; | ||
exports.continueWith = flatMapEnd; | ||
exports.flatMapEnd = flatMapEnd; | ||
exports.continueWith = continueWith; | ||
exports.flatMapEnd = continueWith; | ||
@@ -282,3 +282,3 @@ /** | ||
Stream.prototype.continueWith = Stream.prototype.flatMapEnd = function(f) { | ||
return flatMapEnd(f, this); | ||
return continueWith(f, this); | ||
}; | ||
@@ -632,3 +632,3 @@ | ||
exports.fromPromise = promises.fromPromise; | ||
exports.await = promises.await; | ||
exports.await = promises.awaitPromises; | ||
@@ -641,3 +641,3 @@ /** | ||
Stream.prototype.await = function() { | ||
return promises.await(this); | ||
return promises.awaitPromises(this); | ||
}; | ||
@@ -644,0 +644,0 @@ |
{ | ||
"name": "most", | ||
"version": "0.17.0", | ||
"version": "0.17.1", | ||
"description": "Monadic streams", | ||
@@ -12,3 +12,4 @@ "main": "most.js", | ||
"test": "jshint . && buster-test", | ||
"build": "webpack --output-library most --output-library-target umd ./most.js --output-file dist/most.js && uglifyjs dist/most.js -c 'warnings=false' -m -o dist/most.min.js" | ||
"build": "webpack --output-library most --output-library-target umd ./most.js --output-file dist/most.js && uglifyjs dist/most.js -c 'warnings=false' -m -o dist/most.min.js", | ||
"preversion": "npm run build" | ||
}, | ||
@@ -15,0 +16,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
123366
68
3717