@ahanapediatrics/ahana-fp
Advanced tools
Comparing version 3.0.3 to 3.1.0
@@ -72,2 +72,6 @@ import { Optional } from '.'; | ||
/** | ||
* Check whether the data errored out | ||
*/ | ||
isErrored(): boolean; | ||
/** | ||
* Checks whether the data that was loaded is empty. | ||
@@ -108,2 +112,3 @@ * | ||
orElse(v: D | readonly D[]): typeof v; | ||
append(v: D[]): AsyncData<D>; | ||
/** | ||
@@ -110,0 +115,0 @@ * Standard response for mapping this AsyncData to a new one |
@@ -124,2 +124,8 @@ "use strict"; | ||
/** | ||
* Check whether the data errored out | ||
*/ | ||
isErrored() { | ||
return this.is(RemoteDataStatus.Failed); | ||
} | ||
/** | ||
* Checks whether the data that was loaded is empty. | ||
@@ -198,2 +204,6 @@ * | ||
} | ||
append(v) { | ||
const currentData = this.containsData() ? this.internal.getRight() : []; | ||
return AsyncData.loaded(currentData.concat(v)); | ||
} | ||
/** | ||
@@ -200,0 +210,0 @@ * Standard response for mapping this AsyncData to a new one |
@@ -161,2 +161,26 @@ "use strict"; | ||
}); | ||
describe('.append', () => { | ||
it('returns a loaded value, if called on a not asked', () => { | ||
const ad = AsyncData_1.AsyncData.notAsked(); | ||
chai_1.expect(ad.isLoaded()).to.be.false; | ||
const newAd = ad.append([1]); | ||
chai_1.expect(newAd.isLoaded()).to.be.true; | ||
chai_1.expect(newAd.value()).to.deep.equal([1]); | ||
}); | ||
it('returns a loaded value, if called on an error', () => { | ||
const ad = AsyncData_1.AsyncData.errored(new Error()); | ||
chai_1.expect(ad.isErrored()).to.be.true; | ||
const newAd = ad.append([1]); | ||
chai_1.expect(newAd.isErrored()).to.be.false; | ||
chai_1.expect(newAd.value()).to.deep.equal([1]); | ||
}); | ||
it('returns an updated value', () => { | ||
const ad = AsyncData_1.AsyncData.loaded([1]); | ||
chai_1.expect(ad.isLoaded()).to.be.true; | ||
chai_1.expect(ad.value()).to.deep.equal([1]); | ||
const newAd = ad.append([2]); | ||
chai_1.expect(newAd.isLoaded()).to.be.true; | ||
chai_1.expect(newAd.value()).to.deep.equal([1, 2]); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "@ahanapediatrics/ahana-fp", | ||
"version": "3.0.3", | ||
"version": "3.1.0", | ||
"description": "FP-friendly classes for Typescript", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
112883
2911