diff --git a/apps/stories/CHANGELOG.md b/apps/stories/CHANGELOG.md index 4e5f81c..5d87a1f 100644 --- a/apps/stories/CHANGELOG.md +++ b/apps/stories/CHANGELOG.md @@ -4,6 +4,17 @@ ### Patch Changes +- Updated dependencies + - @dhi/arsenal.models@4.0.0 + - @dhi/arsenal.jsonform@16.0.0 + - @dhi/arsenal.scenarios@21.0.0 + - @dhi/arsenal.ui@14.0.0 + - @dhi/arsenal.date-slider@10.0.0 + +## null + +### Patch Changes + - Updated dependencies - @dhi/arsenal.scenarios@20.0.0 diff --git a/libs/date-slider/CHANGELOG.md b/libs/date-slider/CHANGELOG.md index 7aa98da..6d2a7a8 100644 --- a/libs/date-slider/CHANGELOG.md +++ b/libs/date-slider/CHANGELOG.md @@ -1,5 +1,11 @@ # @dhi/arsenal.date-slider +## 10.0.0 + +### Patch Changes + +- @dhi/arsenal.ui@14.0.0 + ## 9.0.0 ### Minor Changes diff --git a/libs/date-slider/package.json b/libs/date-slider/package.json index 327f906..4b9af43 100644 --- a/libs/date-slider/package.json +++ b/libs/date-slider/package.json @@ -1,6 +1,6 @@ { "name": "@dhi/arsenal.date-slider", - "version": "9.0.0", + "version": "10.0.0", "main": "./x/index", "scripts": { "build": "tsc", diff --git a/libs/jsonform/CHANGELOG.md b/libs/jsonform/CHANGELOG.md index 4ab782c..827292a 100644 --- a/libs/jsonform/CHANGELOG.md +++ b/libs/jsonform/CHANGELOG.md @@ -1,5 +1,13 @@ # @dhi/arsenal.jsonform +## 16.0.0 + +### Patch Changes + +- Updated dependencies + - @dhi/arsenal.models@4.0.0 + - @dhi/arsenal.ui@14.0.0 + ## 15.0.0 ### Minor Changes diff --git a/libs/jsonform/package.json b/libs/jsonform/package.json index 40b49c8..6cdb11b 100644 --- a/libs/jsonform/package.json +++ b/libs/jsonform/package.json @@ -1,6 +1,6 @@ { "name": "@dhi/arsenal.jsonform", - "version": "15.0.0", + "version": "16.0.0", "main": "./x/index", "scripts": { "build": "tsc", diff --git a/libs/models/CHANGELOG.md b/libs/models/CHANGELOG.md index 0ecc289..72d54de 100644 --- a/libs/models/CHANGELOG.md +++ b/libs/models/CHANGELOG.md @@ -1,5 +1,11 @@ # @dhi/arsenal.models +## 4.0.0 + +### Major Changes + +- Add progress to asyncvalue + ## 3.10.0 ### Minor Changes diff --git a/libs/models/package.json b/libs/models/package.json index 0b112cb..ad97b65 100644 --- a/libs/models/package.json +++ b/libs/models/package.json @@ -1,6 +1,6 @@ { "name": "@dhi/arsenal.models", - "version": "3.10.0", + "version": "4.0.0", "main": "./x/index", "scripts": { "build": "tsc", diff --git a/libs/models/src/AsyncValue.ts b/libs/models/src/AsyncValue.ts index bdfdf7a..87f7363 100644 --- a/libs/models/src/AsyncValue.ts +++ b/libs/models/src/AsyncValue.ts @@ -1,10 +1,4 @@ -import { - action, - makeObservable, - observable, - autorun, - computed, -} from 'mobx'; +import { action, makeObservable, observable, autorun, computed } from 'mobx'; import { Annotation } from 'mobx/dist/internal'; type MaybeCancellablePromise = Promise & { @@ -42,7 +36,10 @@ type MaybeCancellablePromise = Promise & { */ export class AsyncValue { constructor( - private _query: (payload: PAYLOAD) => MaybeCancellablePromise, + private _query: ( + this: AsyncValue, + payload: PAYLOAD, + ) => MaybeCancellablePromise, private config: { /** Initial value */ value?: VALUE; @@ -65,6 +62,9 @@ export class AsyncValue { set: action.bound, reset: action.bound, setError: action.bound, + setProgress: action.bound, + clearQueue: action.bound, + progress: observable, }); } @@ -77,6 +77,7 @@ export class AsyncValue { value?: VALUE = undefined; error?: Error = undefined; + progress?: number = undefined; /** This is used to ensure the `isPending` boolean works with concurrent queries */ queue = new Set>(); @@ -92,12 +93,14 @@ export class AsyncValue { ...[payload]: P ) { this.setError(undefined); + this.setProgress(0); const promise = this._query(payload as PAYLOAD); this.queue.add(promise); try { this.set(await promise); + this.setProgress(100); } catch (err: any) { this.setError(err); } finally { @@ -119,20 +122,37 @@ export class AsyncValue { return this; } + setError = (v: this['error']) => { + this.error = v; + + return this; + }; + + setProgress = (v: this['progress']) => { + this.progress = v; + + return this; + }; + + clearQueue = () => { + if (this.config.disablePromiseCancellingOnReset) return; + + this.queue.forEach((promise) => promise?.cancel?.()); + this.queue.clear(); + + return this; + }; + /** Reset value to undefined */ reset() { - if (!this.config.disablePromiseCancellingOnReset) { - this.queue.forEach((promise) => promise?.cancel?.()); - this.queue.clear(); - } - - this.value = undefined; + this.clearQueue(); + this.setProgress(undefined); + this.setError(undefined); + this.set(undefined); return this; } - setError = (v: this['error']) => (this.error = v); - /** Creates an autorun reaction whenever the error changes */ onError = (cb: (err: this['error']) => void) => autorun(() => cb(this.error)); diff --git a/libs/scenarios/CHANGELOG.md b/libs/scenarios/CHANGELOG.md index 678a2f2..aee5e9b 100644 --- a/libs/scenarios/CHANGELOG.md +++ b/libs/scenarios/CHANGELOG.md @@ -1,5 +1,14 @@ # @dhi/arsenal.scenarios +## 21.0.0 + +### Patch Changes + +- Updated dependencies + - @dhi/arsenal.models@4.0.0 + - @dhi/arsenal.jsonform@16.0.0 + - @dhi/arsenal.ui@14.0.0 + ## 20.0.0 ### Major Changes diff --git a/libs/scenarios/package.json b/libs/scenarios/package.json index 55b05f2..11a63b6 100644 --- a/libs/scenarios/package.json +++ b/libs/scenarios/package.json @@ -1,6 +1,6 @@ { "name": "@dhi/arsenal.scenarios", - "version": "20.0.0", + "version": "21.0.0", "main": "./x/index", "scripts": { "build": "tsc -p tsconfig.lib.json", diff --git a/libs/ui/CHANGELOG.md b/libs/ui/CHANGELOG.md index 2e1624d..d143a2b 100644 --- a/libs/ui/CHANGELOG.md +++ b/libs/ui/CHANGELOG.md @@ -1,5 +1,12 @@ # @dhi/arsenal.ui +## 14.0.0 + +### Patch Changes + +- Updated dependencies + - @dhi/arsenal.models@4.0.0 + ## 13.0.0 ### Minor Changes diff --git a/libs/ui/package.json b/libs/ui/package.json index ed30433..6b65089 100644 --- a/libs/ui/package.json +++ b/libs/ui/package.json @@ -1,6 +1,6 @@ { "name": "@dhi/arsenal.ui", - "version": "13.0.0", + "version": "14.0.0", "main": "./x/index", "scripts": { "build": "tsc",