Comparing version 2.2.1 to 2.3.0
@@ -12,3 +12,3 @@ export interface Handler<T> { | ||
*/ | ||
handlersOf(state: State): Handler<any>[]; | ||
handlersOf(state: State): Array<Handler<any>>; | ||
/** | ||
@@ -15,0 +15,0 @@ * Remove every handler for every state. This is behaviorally equivalent to |
@@ -1,2 +0,2 @@ | ||
import { Success, Pending, Failure } from '../common'; | ||
import { Failure, Pending, Success } from '../common'; | ||
import { Handler } from '../dispatcher'; | ||
@@ -3,0 +3,0 @@ /** |
@@ -19,3 +19,3 @@ "use strict"; | ||
pending: function () { return dispatch('pending', undefined); }, | ||
failure: function (data) { return dispatch('failure', data); } | ||
failure: function (data) { return dispatch('failure', data); }, | ||
}; | ||
@@ -22,0 +22,0 @@ /** |
import { Future } from './future'; | ||
import { Lazy } from './lazy'; | ||
/** | ||
@@ -75,2 +76,16 @@ * Failable is a reactive MobX counterpart to a Promise. It has three states: | ||
accept(promise: PromiseLike<T>): this; | ||
/** | ||
* Returns this Failable's success value if it is a success, or the provided | ||
* default value if it is not. | ||
* @param defaultValue A possibly lazy value to use in case of non-success | ||
* @returns This Future's success value or the provided default value | ||
*/ | ||
successOr<U>(defaultValue: Lazy<U>): T | U; | ||
/** | ||
* Returns this Failable's error value if it is a failure, or the provided | ||
* default value if it is not. | ||
* @param defaultValue A possibly lazy value to use in case of non-failure | ||
* @returns this Failable's failure error or the provided default value | ||
*/ | ||
failureOr<U>(defaultValue: Lazy<U>): Error | U; | ||
} |
@@ -11,2 +11,3 @@ "use strict"; | ||
var future_1 = require("./future"); | ||
var lazy_1 = require("./lazy"); | ||
var State = future_1.Future.State; | ||
@@ -129,2 +130,28 @@ /** | ||
}; | ||
/** | ||
* Returns this Failable's success value if it is a success, or the provided | ||
* default value if it is not. | ||
* @param defaultValue A possibly lazy value to use in case of non-success | ||
* @returns This Future's success value or the provided default value | ||
*/ | ||
Failable.prototype.successOr = function (defaultValue) { | ||
return this.match({ | ||
success: function (v) { return v; }, | ||
failure: function () { return lazy_1.Lazy.force(defaultValue); }, | ||
pending: function () { return lazy_1.Lazy.force(defaultValue); }, | ||
}); | ||
}; | ||
/** | ||
* Returns this Failable's error value if it is a failure, or the provided | ||
* default value if it is not. | ||
* @param defaultValue A possibly lazy value to use in case of non-failure | ||
* @returns this Failable's failure error or the provided default value | ||
*/ | ||
Failable.prototype.failureOr = function (defaultValue) { | ||
return this.match({ | ||
success: function () { return lazy_1.Lazy.force(defaultValue); }, | ||
failure: function (e) { return e; }, | ||
pending: function () { return lazy_1.Lazy.force(defaultValue); }, | ||
}); | ||
}; | ||
return Failable; | ||
@@ -131,0 +158,0 @@ }()); |
import { Enum } from 'typescript-string-enums'; | ||
import { Lazy } from './lazy'; | ||
/** | ||
@@ -55,2 +56,16 @@ * Future is a reactive counterpart to a Promise with MobX semantics. It has | ||
accept(promise: PromiseLike<T>): this; | ||
/** | ||
* Returns this Future's success value if it is a success, or the provided | ||
* default value if it is not. | ||
* @param defaultValue A possibly lazy value to use in case of non-success | ||
* @returns This Future's success value or the provided default value | ||
*/ | ||
successOr<U>(defaultValue: Lazy<U>): T | U; | ||
/** | ||
* Returns this Future's error value if it is a failure, or the provided | ||
* default value if it is not. | ||
* @param defaultValue A possibly lazy value to use in case of non-failure | ||
* @returns this Future's failure error or the provided default value | ||
*/ | ||
failureOr<U>(defaultValue: Lazy<U>): Error | U; | ||
} | ||
@@ -57,0 +72,0 @@ export declare namespace Future { |
export * from './future'; | ||
export * from './lazy'; | ||
export * from './failable'; | ||
export * from './loadable'; |
@@ -7,3 +7,4 @@ "use strict"; | ||
__export(require("./future")); | ||
__export(require("./lazy")); | ||
__export(require("./failable")); | ||
__export(require("./loadable")); |
import { Enum } from 'typescript-string-enums'; | ||
import { Future } from './future'; | ||
import { Lazy } from './lazy'; | ||
/** | ||
@@ -90,2 +91,16 @@ * Loadable is an extension of Failable. It has six states: empty, pending, | ||
accept(promise: PromiseLike<T>): this; | ||
/** | ||
* Returns this Loadable's success value if it is a success, or the provided | ||
* default value if it is not. | ||
* @param defaultValue A possibly lazy value to use in case of non-success | ||
* @returns This Future's success value or the provided default value | ||
*/ | ||
successOr<U>(defaultValue: Lazy<U>): T | U; | ||
/** | ||
* Returns this Loadable's error value if it is a failure, or the provided | ||
* default value if it is not. | ||
* @param defaultValue A possibly lazy value to use in case of non-failure | ||
* @returns this Loadable's failure error or the provided default value | ||
*/ | ||
failureOr<U>(defaultValue: Lazy<U>): Error | U; | ||
} | ||
@@ -92,0 +107,0 @@ export declare namespace Loadable { |
@@ -11,2 +11,3 @@ "use strict"; | ||
var typescript_string_enums_1 = require("typescript-string-enums"); | ||
var lazy_1 = require("./lazy"); | ||
/** | ||
@@ -175,2 +176,28 @@ * Loadable is an extension of Failable. It has six states: empty, pending, | ||
}; | ||
/** | ||
* Returns this Loadable's success value if it is a success, or the provided | ||
* default value if it is not. | ||
* @param defaultValue A possibly lazy value to use in case of non-success | ||
* @returns This Future's success value or the provided default value | ||
*/ | ||
Loadable.prototype.successOr = function (defaultValue) { | ||
return this.match({ | ||
success: function (v) { return v; }, | ||
failure: function () { return lazy_1.Lazy.force(defaultValue); }, | ||
pending: function () { return lazy_1.Lazy.force(defaultValue); }, | ||
}); | ||
}; | ||
/** | ||
* Returns this Loadable's error value if it is a failure, or the provided | ||
* default value if it is not. | ||
* @param defaultValue A possibly lazy value to use in case of non-failure | ||
* @returns this Loadable's failure error or the provided default value | ||
*/ | ||
Loadable.prototype.failureOr = function (defaultValue) { | ||
return this.match({ | ||
success: function () { return lazy_1.Lazy.force(defaultValue); }, | ||
failure: function (e) { return e; }, | ||
pending: function () { return lazy_1.Lazy.force(defaultValue); }, | ||
}); | ||
}; | ||
return Loadable; | ||
@@ -236,3 +263,3 @@ }()); | ||
*/ | ||
retrying: 'retrying' | ||
retrying: 'retrying', | ||
}); | ||
@@ -239,0 +266,0 @@ })(Loadable = exports.Loadable || (exports.Loadable = {})); |
{ | ||
"name": "failable", | ||
"version": "2.2.1", | ||
"version": "2.3.0", | ||
"description": "Simplify error state handling", | ||
@@ -9,3 +9,3 @@ "main": "index.js", | ||
"test": "mocha --require ts-node/register ./src/**/*.spec.ts", | ||
"lint": "globstar --node --nodir -- tslint './src/**/*.ts'", | ||
"lint": "tslint --project tsconfig.json", | ||
"build": "rm -r lib; tsc", | ||
@@ -32,3 +32,2 @@ "package": "npm run build && ts-node prepare.ts" | ||
"fs-extra": "^2.0.0", | ||
"globstar": "^1.0.0", | ||
"mocha": "3.0.2", | ||
@@ -38,3 +37,3 @@ "sinon": "^2.1.0", | ||
"ts-node": "1.3.0", | ||
"tslint": "4.5.1", | ||
"tslint": "5.1.0", | ||
"typescript": "2.2.2" | ||
@@ -41,0 +40,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
import { Success, Failure } from '../common'; | ||
import { Failure, Success } from '../common'; | ||
/** | ||
@@ -3,0 +3,0 @@ * A Result represents a successful value or a failure with an error. |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
46410
13
21
1219
0