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

@most/disposable

Package Overview
Dependencies
Maintainers
4
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@most/disposable - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

267

dist/index.es.js

@@ -5,14 +5,143 @@ import { curry2, curry3, reduce } from '@most/prelude';

var dispose = function (disposable) { return disposable.dispose(); };
var dispose = function dispose(disposable) {
return disposable.dispose();
};
var asyncGenerator = function () {
function AwaitValue(value) {
this.value = value;
}
function AsyncGenerator(gen) {
var front, back;
function send(key, arg) {
return new Promise(function (resolve, reject) {
var request = {
key: key,
arg: arg,
resolve: resolve,
reject: reject,
next: null
};
if (back) {
back = back.next = request;
} else {
front = back = request;
resume(key, arg);
}
});
}
function resume(key, arg) {
try {
var result = gen[key](arg);
var value = result.value;
if (value instanceof AwaitValue) {
Promise.resolve(value.value).then(function (arg) {
resume("next", arg);
}, function (arg) {
resume("throw", arg);
});
} else {
settle(result.done ? "return" : "normal", result.value);
}
} catch (err) {
settle("throw", err);
}
}
function settle(type, value) {
switch (type) {
case "return":
front.resolve({
value: value,
done: true
});
break;
case "throw":
front.reject(value);
break;
default:
front.resolve({
value: value,
done: false
});
break;
}
front = front.next;
if (front) {
resume(front.key, front.arg);
} else {
back = null;
}
}
this._invoke = send;
if (typeof gen.return !== "function") {
this.return = undefined;
}
}
if (typeof Symbol === "function" && Symbol.asyncIterator) {
AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
return this;
};
}
AsyncGenerator.prototype.next = function (arg) {
return this._invoke("next", arg);
};
AsyncGenerator.prototype.throw = function (arg) {
return this._invoke("throw", arg);
};
AsyncGenerator.prototype.return = function (arg) {
return this._invoke("return", arg);
};
return {
wrap: function (fn) {
return function () {
return new AsyncGenerator(fn.apply(this, arguments));
};
},
await: function (value) {
return new AwaitValue(value);
}
};
}();
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
/** @license MIT License (c) copyright 2010-2017 original author or authors */
var disposeNone = function () { return NONE; };
var NONE = new ((function () {
function DisposeNone () {}
var disposeNone = function disposeNone() {
return NONE;
};
var NONE = /*#__PURE__*/new (function () {
function DisposeNone() {
classCallCheck(this, DisposeNone);
}
DisposeNone.prototype.dispose = function dispose () {};
DisposeNone.prototype.dispose = function dispose() {};
return DisposeNone;
}()))();
}())();

@@ -23,21 +152,31 @@ /** @license MIT License (c) copyright 2010-2017 original author or authors */

// so that it will only dispose its underlying resource at most once.
var disposeOnce = function (disposable) { return new DisposeOnce(disposable); };
var DisposeOnce = function DisposeOnce (disposable) {
this.disposed = false;
this.disposable = disposable;
var disposeOnce = function disposeOnce(disposable) {
return new DisposeOnce(disposable);
};
DisposeOnce.prototype.dispose = function dispose () {
if (!this.disposed) {
this.disposed = true;
this.disposable.dispose();
this.disposable = undefined;
var DisposeOnce = /*#__PURE__*/function () {
function DisposeOnce(disposable) {
classCallCheck(this, DisposeOnce);
this.disposed = false;
this.disposable = disposable;
}
};
DisposeOnce.prototype.dispose = function dispose() {
if (!this.disposed) {
this.disposed = true;
this.disposable.dispose();
this.disposable = undefined;
}
};
return DisposeOnce;
}();
/** @license MIT License (c) copyright 2010-2017 original author or authors */
// Create a Disposable that will use the provided
// dispose function to dispose the resource
var disposeWith = curry2(function (dispose, resource) { return disposeOnce(new DisposeWith(dispose, resource)); });
var disposeWith = /*#__PURE__*/curry2(function (dispose, resource) {
return disposeOnce(new DisposeWith(dispose, resource));
});

@@ -48,31 +187,52 @@ // Disposable represents a resource that must be

// that identifies the resource
var DisposeWith = function DisposeWith (dispose, resource) {
this._dispose = dispose;
this._resource = resource;
};
DisposeWith.prototype.dispose = function dispose () {
this._dispose(this._resource);
};
var DisposeWith = /*#__PURE__*/function () {
function DisposeWith(dispose, resource) {
classCallCheck(this, DisposeWith);
this._dispose = dispose;
this._resource = resource;
}
DisposeWith.prototype.dispose = function dispose() {
this._dispose(this._resource);
};
return DisposeWith;
}();
/** @license MIT License (c) copyright 2010-2017 original author or authors */
// Aggregate a list of disposables into a DisposeAll
var disposeAll = function (ds) { return new DisposeAll(ds); };
var disposeAll = function disposeAll(ds) {
return new DisposeAll(ds);
};
// Convenience to aggregate 2 disposables
var disposeBoth = curry2(function (d1, d2) { return disposeAll([d1, d2]); });
var disposeBoth = /*#__PURE__*/curry2(function (d1, d2) {
return disposeAll([d1, d2]);
});
var DisposeAll = function DisposeAll (disposables) {
this.disposables = disposables;
};
var DisposeAll = /*#__PURE__*/function () {
function DisposeAll(disposables) {
classCallCheck(this, DisposeAll);
DisposeAll.prototype.dispose = function dispose () {
throwIfErrors(disposeCollectErrors(this.disposables));
};
this.disposables = disposables;
}
DisposeAll.prototype.dispose = function dispose() {
throwIfErrors(disposeCollectErrors(this.disposables));
};
return DisposeAll;
}();
// Dispose all, safely collecting errors into an array
var disposeCollectErrors = function (disposables) { return reduce(appendIfError, [], disposables); };
var disposeCollectErrors = function disposeCollectErrors(disposables) {
return reduce(appendIfError, [], disposables);
};
// Call dispose and if throws, append thrown error to errors
var appendIfError = function (errors, d) {
var appendIfError = function appendIfError(errors, d) {
try {

@@ -83,41 +243,38 @@ d.dispose();

}
return errors
return errors;
};
// Throw DisposeAllError if errors is non-empty
var throwIfErrors = function (errors) {
var throwIfErrors = function throwIfErrors(errors) {
if (errors.length > 0) {
throw new DisposeAllError(((errors.length) + " errors"), errors)
throw new DisposeAllError(errors.length + ' errors', errors);
}
};
// Aggregate Error type for DisposeAll
var DisposeAllError = (function (Error) {
function DisposeAllError (message, errors) {
var DisposeAllError = /*#__PURE__*/function (Error) {
function DisposeAllError(message, errors) {
Error.call(this, message);
this.message = message;
this.name = this.constructor.name;
this.name = DisposeAllError.name;
this.errors = errors;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
Error.captureStackTrace(this, DisposeAllError);
}
this.stack = "" + (this.stack) + (formatErrorStacks(this.errors));
this.stack = '' + this.stack + formatErrorStacks(this.errors);
}
if ( Error ) DisposeAllError.__proto__ = Error;
DisposeAllError.prototype = Object.create( Error && Error.prototype );
DisposeAllError.prototype.constructor = DisposeAllError;
DisposeAllError.prototype = /*#__PURE__*/Object.create(Error.prototype);
DisposeAllError.prototype.toString = function toString () {
return this.stack
};
return DisposeAllError;
}(Error));
}(Error);
var formatErrorStacks = function (errors) { return reduce(formatErrorStack, '', errors); };
var formatErrorStacks = function formatErrorStacks(errors) {
return reduce(formatErrorStack, '', errors);
};
var formatErrorStack = function (s, e, i) { return s + "\n[" + ((i + 1)) + "] " + (e.stack); };
var formatErrorStack = function formatErrorStack(s, e, i) {
return s + ('\n[' + (i + 1) + '] ' + e.stack);
};

@@ -127,3 +284,3 @@ /** @license MIT License (c) copyright 2010-2017 original author or authors */

// the error to sink.error with the provided Time value
var tryDispose = curry3(function (t, disposable, sink) {
var tryDispose = /*#__PURE__*/curry3(function (t, disposable, sink) {
try {

@@ -130,0 +287,0 @@ disposable.dispose();

@@ -9,14 +9,143 @@ (function (global, factory) {

var dispose = function (disposable) { return disposable.dispose(); };
var dispose = function dispose(disposable) {
return disposable.dispose();
};
var asyncGenerator = function () {
function AwaitValue(value) {
this.value = value;
}
function AsyncGenerator(gen) {
var front, back;
function send(key, arg) {
return new Promise(function (resolve, reject) {
var request = {
key: key,
arg: arg,
resolve: resolve,
reject: reject,
next: null
};
if (back) {
back = back.next = request;
} else {
front = back = request;
resume(key, arg);
}
});
}
function resume(key, arg) {
try {
var result = gen[key](arg);
var value = result.value;
if (value instanceof AwaitValue) {
Promise.resolve(value.value).then(function (arg) {
resume("next", arg);
}, function (arg) {
resume("throw", arg);
});
} else {
settle(result.done ? "return" : "normal", result.value);
}
} catch (err) {
settle("throw", err);
}
}
function settle(type, value) {
switch (type) {
case "return":
front.resolve({
value: value,
done: true
});
break;
case "throw":
front.reject(value);
break;
default:
front.resolve({
value: value,
done: false
});
break;
}
front = front.next;
if (front) {
resume(front.key, front.arg);
} else {
back = null;
}
}
this._invoke = send;
if (typeof gen.return !== "function") {
this.return = undefined;
}
}
if (typeof Symbol === "function" && Symbol.asyncIterator) {
AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
return this;
};
}
AsyncGenerator.prototype.next = function (arg) {
return this._invoke("next", arg);
};
AsyncGenerator.prototype.throw = function (arg) {
return this._invoke("throw", arg);
};
AsyncGenerator.prototype.return = function (arg) {
return this._invoke("return", arg);
};
return {
wrap: function (fn) {
return function () {
return new AsyncGenerator(fn.apply(this, arguments));
};
},
await: function (value) {
return new AwaitValue(value);
}
};
}();
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
/** @license MIT License (c) copyright 2010-2017 original author or authors */
var disposeNone = function () { return NONE; };
var NONE = new ((function () {
function DisposeNone () {}
var disposeNone = function disposeNone() {
return NONE;
};
var NONE = /*#__PURE__*/new (function () {
function DisposeNone() {
classCallCheck(this, DisposeNone);
}
DisposeNone.prototype.dispose = function dispose () {};
DisposeNone.prototype.dispose = function dispose() {};
return DisposeNone;
}()))();
}())();

@@ -27,21 +156,31 @@ /** @license MIT License (c) copyright 2010-2017 original author or authors */

// so that it will only dispose its underlying resource at most once.
var disposeOnce = function (disposable) { return new DisposeOnce(disposable); };
var DisposeOnce = function DisposeOnce (disposable) {
this.disposed = false;
this.disposable = disposable;
var disposeOnce = function disposeOnce(disposable) {
return new DisposeOnce(disposable);
};
DisposeOnce.prototype.dispose = function dispose () {
if (!this.disposed) {
this.disposed = true;
this.disposable.dispose();
this.disposable = undefined;
var DisposeOnce = /*#__PURE__*/function () {
function DisposeOnce(disposable) {
classCallCheck(this, DisposeOnce);
this.disposed = false;
this.disposable = disposable;
}
};
DisposeOnce.prototype.dispose = function dispose() {
if (!this.disposed) {
this.disposed = true;
this.disposable.dispose();
this.disposable = undefined;
}
};
return DisposeOnce;
}();
/** @license MIT License (c) copyright 2010-2017 original author or authors */
// Create a Disposable that will use the provided
// dispose function to dispose the resource
var disposeWith = prelude.curry2(function (dispose, resource) { return disposeOnce(new DisposeWith(dispose, resource)); });
var disposeWith = /*#__PURE__*/prelude.curry2(function (dispose, resource) {
return disposeOnce(new DisposeWith(dispose, resource));
});

@@ -52,31 +191,52 @@ // Disposable represents a resource that must be

// that identifies the resource
var DisposeWith = function DisposeWith (dispose, resource) {
this._dispose = dispose;
this._resource = resource;
};
DisposeWith.prototype.dispose = function dispose () {
this._dispose(this._resource);
};
var DisposeWith = /*#__PURE__*/function () {
function DisposeWith(dispose, resource) {
classCallCheck(this, DisposeWith);
this._dispose = dispose;
this._resource = resource;
}
DisposeWith.prototype.dispose = function dispose() {
this._dispose(this._resource);
};
return DisposeWith;
}();
/** @license MIT License (c) copyright 2010-2017 original author or authors */
// Aggregate a list of disposables into a DisposeAll
var disposeAll = function (ds) { return new DisposeAll(ds); };
var disposeAll = function disposeAll(ds) {
return new DisposeAll(ds);
};
// Convenience to aggregate 2 disposables
var disposeBoth = prelude.curry2(function (d1, d2) { return disposeAll([d1, d2]); });
var disposeBoth = /*#__PURE__*/prelude.curry2(function (d1, d2) {
return disposeAll([d1, d2]);
});
var DisposeAll = function DisposeAll (disposables) {
this.disposables = disposables;
};
var DisposeAll = /*#__PURE__*/function () {
function DisposeAll(disposables) {
classCallCheck(this, DisposeAll);
DisposeAll.prototype.dispose = function dispose () {
throwIfErrors(disposeCollectErrors(this.disposables));
};
this.disposables = disposables;
}
DisposeAll.prototype.dispose = function dispose() {
throwIfErrors(disposeCollectErrors(this.disposables));
};
return DisposeAll;
}();
// Dispose all, safely collecting errors into an array
var disposeCollectErrors = function (disposables) { return prelude.reduce(appendIfError, [], disposables); };
var disposeCollectErrors = function disposeCollectErrors(disposables) {
return prelude.reduce(appendIfError, [], disposables);
};
// Call dispose and if throws, append thrown error to errors
var appendIfError = function (errors, d) {
var appendIfError = function appendIfError(errors, d) {
try {

@@ -87,41 +247,38 @@ d.dispose();

}
return errors
return errors;
};
// Throw DisposeAllError if errors is non-empty
var throwIfErrors = function (errors) {
var throwIfErrors = function throwIfErrors(errors) {
if (errors.length > 0) {
throw new DisposeAllError(((errors.length) + " errors"), errors)
throw new DisposeAllError(errors.length + ' errors', errors);
}
};
// Aggregate Error type for DisposeAll
var DisposeAllError = (function (Error) {
function DisposeAllError (message, errors) {
var DisposeAllError = /*#__PURE__*/function (Error) {
function DisposeAllError(message, errors) {
Error.call(this, message);
this.message = message;
this.name = this.constructor.name;
this.name = DisposeAllError.name;
this.errors = errors;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
Error.captureStackTrace(this, DisposeAllError);
}
this.stack = "" + (this.stack) + (formatErrorStacks(this.errors));
this.stack = '' + this.stack + formatErrorStacks(this.errors);
}
if ( Error ) DisposeAllError.__proto__ = Error;
DisposeAllError.prototype = Object.create( Error && Error.prototype );
DisposeAllError.prototype.constructor = DisposeAllError;
DisposeAllError.prototype = /*#__PURE__*/Object.create(Error.prototype);
DisposeAllError.prototype.toString = function toString () {
return this.stack
};
return DisposeAllError;
}(Error));
}(Error);
var formatErrorStacks = function (errors) { return prelude.reduce(formatErrorStack, '', errors); };
var formatErrorStacks = function formatErrorStacks(errors) {
return prelude.reduce(formatErrorStack, '', errors);
};
var formatErrorStack = function (s, e, i) { return s + "\n[" + ((i + 1)) + "] " + (e.stack); };
var formatErrorStack = function formatErrorStack(s, e, i) {
return s + ('\n[' + (i + 1) + '] ' + e.stack);
};

@@ -131,3 +288,3 @@ /** @license MIT License (c) copyright 2010-2017 original author or authors */

// the error to sink.error with the provided Time value
var tryDispose = prelude.curry3(function (t, disposable, sink) {
var tryDispose = /*#__PURE__*/prelude.curry3(function (t, disposable, sink) {
try {

@@ -134,0 +291,0 @@ disposable.dispose();

{
"name": "@most/disposable",
"version": "1.0.0",
"version": "1.1.0",
"description": "Reactive programming with lean, functions-only, curried, tree-shakeable API",

@@ -14,3 +14,3 @@ "typings": "type-definitions/index.d.ts",

"test": "npm run test:lint && npm run test:unit && npm run test:flow",
"test:unit": "nyc --reporter=text-summary mocha -r buba/register --reporter dot --recursive 'test/**/*-test.js'",
"test:unit": "cross-env NODE_ENV=test nyc --reporter=text-summary mocha -r babel-register --reporter dot --recursive 'test/**/*-test.js'",
"test:lint": "standard --fix 'src/**/*.js' 'test/**/*.js' --verbose | snazzy",

@@ -43,4 +43,9 @@ "test:flow": "flow check",

"@briancavalier/assert": "^3.2.0",
"buba": "^4.0.2",
"babel-core": "^6.26.0",
"babel-plugin-annotate-pure-calls": "^0.2.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-env": "^1.6.0",
"babel-register": "^6.26.0",
"cpy-cli": "^1.0.1",
"cross-env": "^5.0.5",
"flow-bin": "^0.57.3",

@@ -50,3 +55,3 @@ "mocha": "^3.4.2",

"rollup": "^0.50.0",
"rollup-plugin-buble": "^0.16.0",
"rollup-plugin-babel": "^3.0.2",
"sinon": "^1.17.7",

@@ -57,3 +62,3 @@ "snazzy": "^7.0.0",

"dependencies": {
"@most/prelude": "^1.6.4",
"@most/prelude": "^1.7.0",
"@most/types": "^1.0.0"

@@ -60,0 +65,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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