Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

most

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

most - npm Package Compare versions

Comparing version 0.16.0 to 0.17.0

lib/disposable/dispose.js

16

lib/base.js

@@ -20,2 +20,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

exports.findIndex = findIndex;
exports.isArrayLike = isArrayLike;

@@ -110,3 +111,3 @@ function noop() {}

var l = array.length;
if(index >= array) { // exit early if index beyond end of array
if(l === 0 || index >= array) { // exit early if index beyond end of array
return array;

@@ -119,10 +120,13 @@ }

l -= 1;
return unsafeRemove(index, array, l-1);
}
function unsafeRemove(index, a, l) {
var b = new Array(l);
var i;
for(i=0; i<index; ++i) {
b[i] = array[i];
b[i] = a[i];
}
for(i=index; i<l; ++i) {
b[i] = array[i+1];
b[i] = a[i+1];
}

@@ -156,1 +160,5 @@

}
function isArrayLike(x){
return x != null && typeof x.length === 'number' && typeof x !== 'function';
}

@@ -8,2 +8,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

var runSource = require('../runSource');
var cons = require('./build').cons;
var noop = require('../base').noop;

@@ -23,15 +24,5 @@

function scan(f, initial, stream) {
return new Stream(new Scan(f, initial, stream.source));
return cons(initial, new Stream(new Accumulate(ScanSink, f, initial, stream.source)));
}
function Scan(f, z, source) {
this.f = f;
this.value = z;
this.source = source;
}
Scan.prototype.run = function(sink, scheduler) {
return this.source.run(new ScanSink(this.f, this.value, sink), scheduler);
};
function ScanSink(f, z, sink) {

@@ -41,11 +32,5 @@ this.f = f;

this.sink = sink;
this.init = true;
}
ScanSink.prototype.event = function(t, x) {
if(this.init) {
this.init = false;
this.sink.event(t, this.value);
}
var f = this.f;

@@ -69,6 +54,7 @@ this.value = f(this.value, x);

function reduce(f, initial, stream) {
return runSource.withDefaultScheduler(noop, new Accumulate(f, initial, stream.source));
return runSource.withDefaultScheduler(noop, new Accumulate(AccumulateSink, f, initial, stream.source));
}
function Accumulate(f, z, source) {
function Accumulate(SinkType, f, z, source) {
this.SinkType = SinkType;
this.f = f;

@@ -80,3 +66,3 @@ this.value = z;

Accumulate.prototype.run = function(sink, scheduler) {
return this.source.run(new AccumulateSink(this.f, this.value, sink), scheduler);
return this.source.run(new this.SinkType(this.f, this.value, sink), scheduler);
};

@@ -83,0 +69,0 @@

@@ -7,7 +7,5 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

var streamOf = require('../source/core').of;
var fromArray = require('../source/fromArray').fromArray;
var concatMap = require('./concatMap').concatMap;
var flatMapEnd = require('./flatMapEnd').flatMapEnd;
var Sink = require('../sink/Pipe');
var Promise = require('../Promise');
var identity = require('../base').identity;

@@ -34,3 +32,7 @@ exports.concat = concat;

function concat(left, right) {
return concatMap(identity, fromArray([left, right]));
return flatMapEnd(returnRight, left);
function returnRight() {
return right;
}
}

@@ -87,2 +89,2 @@

return this.disposable.dispose();
};
};

@@ -10,3 +10,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

var IndexSink = require('../sink/IndexSink');
var CompoundDisposable = require('../disposable/CompoundDisposable');
var dispose = require('../disposable/dispose');
var base = require('../base');

@@ -16,3 +16,2 @@ var invoke = require('../invoke');

var hasValue = IndexSink.hasValue;
var getValue = IndexSink.getValue;

@@ -69,3 +68,3 @@ var map = base.map;

return new CompoundDisposable(disposables);
return dispose.all(disposables);
};

@@ -76,2 +75,3 @@

this.sinks = sinks;
this.values = new Array(sinks.length);
this.sink = sink;

@@ -82,3 +82,3 @@ this.ready = false;

CombineSink.prototype.event = function(t /*, indexSink */) {
CombineSink.prototype.event = function(t, indexedValue) {
if(!this.ready) {

@@ -88,5 +88,5 @@ this.ready = this.sinks.every(hasValue);

this.values[indexedValue.index] = indexedValue.value;
if(this.ready) {
// TODO: Maybe cache values in their own array once this.ready
this.sink.event(t, invoke(this.f, map(getValue, this.sinks)));
this.sink.event(t, invoke(this.f, this.values));
}

@@ -93,0 +93,0 @@ };

@@ -7,3 +7,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

var Sink = require('../sink/Pipe');
var CompoundDisposable = require('../disposable/CompoundDisposable');
var dispose = require('../disposable/dispose');
var PropagateTask = require('../scheduler/PropagateTask');

@@ -30,3 +30,3 @@

var delaySink = new DelaySink(this.dt, sink, scheduler);
return new CompoundDisposable([delaySink, this.source.run(delaySink, scheduler)]);
return dispose.all([delaySink, this.source.run(delaySink, scheduler)]);
};

@@ -33,0 +33,0 @@

@@ -7,4 +7,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

var Sink = require('../sink/Pipe');
var AwaitingDisposable = require('../disposable/AwaitingDisposable');
var CompoundDisposable = require('../disposable/CompoundDisposable');
var dispose = require('../disposable/dispose');

@@ -31,3 +30,3 @@ exports.flatMapEnd = flatMapEnd;

this.active = true;
this.disposable = new AwaitingDisposable(source.run(this, scheduler));
this.disposable = dispose.once(source.run(this, scheduler));
}

@@ -54,3 +53,3 @@

var disposable = stream.source.run(this.sink, this.scheduler);
this.disposable = new CompoundDisposable([this.disposable, disposable]);
this.disposable = dispose.all([this.disposable, disposable]);
};

@@ -61,2 +60,2 @@

return this.disposable.dispose();
};
};

@@ -7,3 +7,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

var Sink = require('../sink/Pipe');
var CompoundDisposable = require('../disposable/CompoundDisposable');
var dispose = require('../disposable/dispose');
var PropagateTask = require('../scheduler/PropagateTask');

@@ -46,5 +46,3 @@

ThrottleSink.prototype.end = function(t, e) {
return Sink.prototype.end.call(this, t, e);
};
ThrottleSink.prototype.end = Sink.prototype.end;

@@ -81,3 +79,3 @@ ThrottleSink.prototype.error = Sink.prototype.error;

var sourceDisposable = source.run(this, scheduler);
this.disposable = new CompoundDisposable([this, sourceDisposable]);
this.disposable = dispose.all([this, sourceDisposable]);
}

@@ -84,0 +82,0 @@

@@ -6,3 +6,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

var Stream = require('../Stream');
var AwaitingDisposable = require('../disposable/AwaitingDisposable');
var dispose = require('../disposable/dispose');
var LinkedList = require('../LinkedList');

@@ -32,3 +32,3 @@ var Promise = require('../Promise');

this.current = new LinkedList();
this.disposable = new AwaitingDisposable(source.run(this, scheduler));
this.disposable = dispose.once(source.run(this, scheduler));
this.active = true;

@@ -35,0 +35,0 @@ }

@@ -6,3 +6,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

var Stream = require('../Stream');
var resolve = require('../Promise').resolve;
var Promise = require('../Promise');
var fatal = require('../fatalError');

@@ -13,2 +13,9 @@

/**
* Create a stream containing only the promise's fulfillment
* value at the time it fulfills.
* @param {Promise<T>} p promise
* @return {Stream<T>} stream containing promise's fulfillment value.
* If the promise rejects, the stream will error
*/
function fromPromise(p) {

@@ -32,3 +39,3 @@ return new Stream(new PromiseSource(p));

var self = this;
resolve(p).then(function(x) {
Promise.resolve(p).then(function(x) {
self._emit(self.scheduler.now(), x);

@@ -61,2 +68,9 @@ }).catch(function(e) {

/**
* Turn a Stream<Promise<T>> into Stream<T> by awaiting each promise.
* Event order is preserved.
* @param {Stream<Promise<T>>} stream
* @return {Stream<T>} stream of fulfillment values. The stream will
* error if any promise rejects.
*/
function await(stream) {

@@ -77,3 +91,17 @@ return new Stream(new Await(stream.source));

this.scheduler = scheduler;
this.queue = void 0;
this.queue = Promise.resolve();
var self = this;
// Pre-create closures, to avoid creating them per event
this._eventBound = function(x) {
self.sink.event(self.scheduler.now(), x);
};
this._endBound = function(x) {
self.sink.end(self.scheduler.now(), x);
};
this._errorBound = function(e) {
self.sink.error(self.scheduler.now(), e);
};
}

@@ -83,7 +111,5 @@

var self = this;
this.queue = resolve(this.queue).then(function() {
return self._event(t, promise);
}).catch(function(e) {
return self._error(t, e);
});
this.queue = this.queue.then(function() {
return self._event(promise);
}).catch(this._errorBound);
};

@@ -93,7 +119,5 @@

var self = this;
this.queue = resolve(this.queue).then(function() {
return self._end(t, x);
}).catch(function(e) {
return self._error(t, e);
});
this.queue = this.queue.then(function() {
return self._end(x);
}).catch(this._errorBound);
};

@@ -103,29 +127,14 @@

var self = this;
this.queue = resolve(this.queue).then(function() {
return self._error(t, e);
// Don't resolve error values, propagate directly
this.queue = this.queue.then(function() {
return self._errorBound(e);
}).catch(fatal);
};
AwaitSink.prototype._error = function(t, e) {
try {
// Don't resolve error values, propagate directly
this.sink.error(Math.max(t, this.scheduler.now()), e);
} catch(e) {
fatal(e);
throw e;
}
AwaitSink.prototype._event = function(promise) {
return promise.then(this._eventBound);
};
AwaitSink.prototype._event = function(t, promise) {
var self = this;
return promise.then(function(x) {
self.sink.event(Math.max(t, self.scheduler.now()), x);
});
AwaitSink.prototype._end = function(x) {
return Promise.resolve(x).then(this._endBound);
};
AwaitSink.prototype._end = function(t, x) {
var self = this;
return resolve(x).then(function(x) {
self.sink.end(Math.max(t, self.scheduler.now()), x);
});
};

@@ -7,3 +7,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

var Pipe = require('../sink/Pipe');
var CompoundDisposable = require('../disposable/CompoundDisposable');
var dispose = require('../disposable/dispose');
var base = require('../base');

@@ -67,3 +67,3 @@ var invoke = require('../invoke');

return new CompoundDisposable(disposables);
return dispose.all(disposables);
};

@@ -70,0 +70,0 @@

@@ -8,3 +8,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

var core = require('../source/core');
var AwaitingDisposable = require('../disposable/AwaitingDisposable');
var dispose = require('../disposable/dispose');

@@ -61,3 +61,3 @@ exports.take = take;

this.sink = sink;
this.disposable = new AwaitingDisposable(source.run(this, scheduler));
this.disposable = dispose.once(source.run(this, scheduler));
}

@@ -107,3 +107,3 @@

this.active = true;
this.disposable = new AwaitingDisposable(source.run(this, scheduler));
this.disposable = dispose.once(source.run(this, scheduler));
}

@@ -110,0 +110,0 @@

@@ -7,3 +7,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

var Pipe = require('../sink/Pipe');
var CompoundDisposable = require('../disposable/CompoundDisposable');
var dispose = require('../disposable/dispose');
var never = require('../source/core').never;

@@ -44,3 +44,3 @@ var join = require('../combinator/flatMap').join;

return new CompoundDisposable([min, max, disposable]);
return dispose.all([min, max, disposable]);
};

@@ -69,3 +69,3 @@

return new CompoundDisposable([min, max, disposable]);
return dispose.all([min, max, disposable]);
};

@@ -72,0 +72,0 @@

@@ -10,3 +10,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

var IndexSink = require('../sink/IndexSink');
var CompoundDisposable = require('../disposable/CompoundDisposable');
var dispose = require('../disposable/dispose');
var base = require('../base');

@@ -72,3 +72,3 @@ var invoke = require('../invoke');

return new CompoundDisposable(disposables);
return dispose.all(disposables);
};

@@ -75,0 +75,0 @@

@@ -7,5 +7,10 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

function Disposable(f, data) {
this.disposed = false;
this._dispose = f;
/**
* Create a new Disposable which will dispose its underlying resource.
* @param {function} dispose function
* @param {*?} data any data to be passed to disposer function
* @constructor
*/
function Disposable(dispose, data) {
this._dispose = dispose;
this._data = data;

@@ -15,7 +20,3 @@ }

Disposable.prototype.dispose = function() {
if(this.disposed) {
return;
}
this.disposed = true;
return this._dispose(this._data);
};

@@ -39,8 +39,7 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

if(this.disposable === void 0) {
return this.result;
if(this.disposable !== void 0) {
this.result = this.disposable.dispose();
}
this.result = this.disposable.dispose();
return this.result;
};

@@ -7,3 +7,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

var Observer = require('./sink/Observer');
var SettableDisposable = require('./disposable/SettableDisposable');
var dispose = require('./disposable/dispose');
var defaultScheduler = require('./scheduler/defaultScheduler');

@@ -20,3 +20,3 @@

return new Promise(function (resolve, reject) {
var disposable = new SettableDisposable();
var disposable = dispose.settable();
var observer = new Observer(f, resolve, reject, disposable);

@@ -23,0 +23,0 @@

@@ -10,3 +10,2 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

IndexSink.hasValue = hasValue;
IndexSink.getValue = getValue;

@@ -17,6 +16,2 @@ function hasValue(indexSink) {

function getValue(indexSink) {
return indexSink.value;
}
function IndexSink(i, sink) {

@@ -23,0 +18,0 @@ this.index = i;

@@ -7,4 +7,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

var ValueSource = require('../source/ValueSource');
var Disposable = require('../disposable/Disposable');
var EmptyDisposable = require('../disposable/EmptyDisposable');
var dispose = require('../disposable/dispose');
var PropagateTask = require('../scheduler/PropagateTask');

@@ -44,6 +43,6 @@

return new Disposable(dispose, task);
return dispose.newDisposable(disposeEmpty, task);
};
function dispose(task) {
function disposeEmpty(task) {
return task.dispose();

@@ -65,5 +64,5 @@ }

NeverSource.prototype.run = function() {
return new EmptyDisposable();
return dispose.empty();
};
var NEVER = new Stream(new NeverSource());

@@ -27,7 +27,10 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

this.active = true;
this._unsubscribe = this._init(subscribe);
}
Subscription.prototype._init = function(subscribe) {
var s = this;
try {
this._unsubscribe = subscribe(add, end, error);
return subscribe(add, end, error);
} catch(e) {

@@ -46,3 +49,3 @@ error(e);

}
}
};

@@ -72,3 +75,3 @@ Subscription.prototype._add = function(x) {

if(typeof this._unsubscribe === 'function') {
return this._unsubscribe();
return this._unsubscribe.call(void 0);
}

@@ -91,2 +94,2 @@ };

}
}
}

@@ -8,2 +8,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

var fromIterable = require('./fromIterable').fromIterable;
var isArrayLike = require('../base').isArrayLike;

@@ -13,3 +14,3 @@ exports.from = from;

function from(a) {
if(Array.isArray(a)) {
if(Array.isArray(a) || isArrayLike(a)) {
return fromArray(a);

@@ -16,0 +17,0 @@ }

@@ -12,3 +12,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

this.source = source;
this.sink = new MulticastSink();
this.sinks = [];
this._disposable = void 0;

@@ -18,5 +18,5 @@ }

MulticastSource.prototype.run = function(sink, scheduler) {
var n = this.sink.add(sink);
var n = this.add(sink);
if(n === 1) {
this._disposable = this.source.run(this.sink, scheduler);
this._disposable = this.source.run(this, scheduler);
}

@@ -28,3 +28,5 @@

MulticastSource.prototype._dispose = function() {
return resolve(this._disposable).then(dispose);
var disposable = this._disposable;
this._disposable = void 0;
return resolve(disposable).then(dispose);
};

@@ -46,11 +48,7 @@

var s = this.source;
var remaining = s.sink.remove(this.sink);
var remaining = s.remove(this.sink);
return remaining === 0 && s._dispose();
};
function MulticastSink() {
this.sinks = [];
}
MulticastSink.prototype.add = function(sink) {
MulticastSource.prototype.add = function(sink) {
this.sinks = base.append(sink, this.sinks);

@@ -60,3 +58,3 @@ return this.sinks.length;

MulticastSink.prototype.remove = function(sink) {
MulticastSource.prototype.remove = function(sink) {
this.sinks = base.remove(base.findIndex(sink, this.sinks), this.sinks);

@@ -66,3 +64,3 @@ return this.sinks.length;

MulticastSink.prototype.event = function(t, x) {
MulticastSource.prototype.event = function(t, x) {
var s = this.sinks;

@@ -78,3 +76,3 @@ if(s.length === 1) {

MulticastSink.prototype.end = function(t, x) {
MulticastSource.prototype.end = function(t, x) {
var s = this.sinks;

@@ -90,3 +88,3 @@ if(s.length === 1) {

MulticastSink.prototype.error = function(t, e) {
MulticastSource.prototype.error = function(t, e) {
var s = this.sinks;

@@ -100,2 +98,2 @@ if(s.length === 1) {

}
};
};

@@ -6,3 +6,3 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

var Stream = require('../Stream');
var Disposable = require('../disposable/Disposable');
var dispose = require('../disposable/dispose');
var MulticastSource = require('./MulticastSource');

@@ -30,3 +30,3 @@ var PropagateTask = require('../scheduler/PropagateTask');

var task = scheduler.periodic(this.period, new PropagateTask(emit, this.value, sink));
return new Disposable(cancelTask, task);
return dispose.newDisposable(cancelTask, task);
};

@@ -33,0 +33,0 @@

@@ -57,14 +57,2 @@ /** @license MIT License (c) copyright 2010-2015 original author or authors */

//-----------------------------------------------------------------------
// Lifting functions
var lift = require('./lib/combinator/lift').lift;
/**
* Lift a function that accepts values and returns a value, and return a function
* that accepts streams and returns a stream.
* @type {function(f:function(...args):*):function(...streams):Stream<*>}
*/
exports.lift = lift;
//-----------------------------------------------------------------------
// Observing

@@ -160,3 +148,3 @@

exports.generate = generate.generate;
exports.concat = build.cycle;
exports.cycle = build.cycle;
exports.concat = build.concat;

@@ -284,2 +272,3 @@ exports.startWith = build.cons;

exports.continueWith = flatMapEnd;
exports.flatMapEnd = flatMapEnd;

@@ -294,3 +283,3 @@

*/
Stream.prototype.flatMapEnd = function(f) {
Stream.prototype.continueWith = Stream.prototype.flatMapEnd = function(f) {
return flatMapEnd(f, this);

@@ -308,2 +297,22 @@ };

//-----------------------------------------------------------------------
// Concurrent merging
var mergeConcurrently = require('./lib/combinator/mergeConcurrently');
exports.mergeConcurrently = mergeConcurrently.mergeConcurrently;
/**
* Flatten a Stream<Stream<X>> to Stream<X> by merging inner
* streams to the outer, limiting the number of inner streams that may
* be active concurrently.
* @param {number} concurrency at most this many inner streams will be
* allowed to be active concurrently.
* @return {Stream<X>} new stream containing all events of all inner
* streams, with limited concurrency.
*/
Stream.prototype.mergeConcurrently = function(concurrency) {
return mergeConcurrently.mergeConcurrently(concurrency, this);
};
//-----------------------------------------------------------------------
// Merging

@@ -642,2 +651,3 @@

exports.recoverWith = errors.flatMapError;
exports.flatMapError = errors.flatMapError;

@@ -655,3 +665,3 @@ exports.throwError = errors.throwError;

*/
Stream.prototype.flatMapError = function(f) {
Stream.prototype.recoverWith = Stream.prototype.flatMapError = function(f) {
return errors.flatMapError(f, this);

@@ -658,0 +668,0 @@ };

{
"name": "most",
"version": "0.16.0",
"version": "0.17.0",
"description": "Monadic streams",
"main": "most.js",
"files": [
"most.js", "lib/**/*.js"
"most.js",
"lib/**/*.js"
],

@@ -9,0 +10,0 @@ "scripts": {

@@ -92,3 +92,3 @@ [![Build Status](https://travis-ci.org/cujojs/most.svg?branch=master)](https://travis-ci.org/cujojs/most)

## Iteroperability
## Interoperability

@@ -95,0 +95,0 @@ <a href="http://promises-aplus.github.com/promises-spec"><img width="82" height="82" alt="Promises/A+" src="http://promises-aplus.github.com/promises-spec/assets/logo-small.png"></a>

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc