Skip to content

Commit

Permalink
Bump
Browse files Browse the repository at this point in the history
  • Loading branch information
nfour committed Oct 26, 2023
1 parent 3e80fef commit 4744998
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 21 deletions.
11 changes: 11 additions & 0 deletions apps/stories/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

### Patch Changes

- Updated dependencies
- @dhi/arsenal[email protected]
- @dhi/arsenal[email protected]
- @dhi/arsenal[email protected]
- @dhi/arsenal[email protected]
- @dhi/arsenal[email protected]

## null

### Patch Changes

- Updated dependencies
- @dhi/arsenal[email protected]

Expand Down
6 changes: 6 additions & 0 deletions libs/date-slider/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @dhi/arsenal.date-slider

## 10.0.0

### Patch Changes

- @dhi/arsenal[email protected]

## 9.0.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion libs/date-slider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhi/arsenal.date-slider",
"version": "9.0.0",
"version": "10.0.0",
"main": "./x/index",
"scripts": {
"build": "tsc",
Expand Down
8 changes: 8 additions & 0 deletions libs/jsonform/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @dhi/arsenal.jsonform

## 16.0.0

### Patch Changes

- Updated dependencies
- @dhi/arsenal[email protected]
- @dhi/arsenal[email protected]

## 15.0.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion libs/jsonform/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhi/arsenal.jsonform",
"version": "15.0.0",
"version": "16.0.0",
"main": "./x/index",
"scripts": {
"build": "tsc",
Expand Down
6 changes: 6 additions & 0 deletions libs/models/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @dhi/arsenal.models

## 4.0.0

### Major Changes

- Add progress to asyncvalue

## 3.10.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion libs/models/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhi/arsenal.models",
"version": "3.10.0",
"version": "4.0.0",
"main": "./x/index",
"scripts": {
"build": "tsc",
Expand Down
52 changes: 36 additions & 16 deletions libs/models/src/AsyncValue.ts
Original file line number Diff line number Diff line change
@@ -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<T> = Promise<T> & {
Expand Down Expand Up @@ -42,7 +36,10 @@ type MaybeCancellablePromise<T> = Promise<T> & {
*/
export class AsyncValue<VALUE, PAYLOAD = any> {
constructor(
private _query: (payload: PAYLOAD) => MaybeCancellablePromise<VALUE>,
private _query: (
this: AsyncValue<VALUE, PAYLOAD>,
payload: PAYLOAD,
) => MaybeCancellablePromise<VALUE>,
private config: {
/** Initial value */
value?: VALUE;
Expand All @@ -65,6 +62,9 @@ export class AsyncValue<VALUE, PAYLOAD = any> {
set: action.bound,
reset: action.bound,
setError: action.bound,
setProgress: action.bound,
clearQueue: action.bound,
progress: observable,
});
}

Expand All @@ -77,6 +77,7 @@ export class AsyncValue<VALUE, PAYLOAD = any> {

value?: VALUE = undefined;
error?: Error = undefined;
progress?: number = undefined;

/** This is used to ensure the `isPending` boolean works with concurrent queries */
queue = new Set<MaybeCancellablePromise<VALUE>>();
Expand All @@ -92,12 +93,14 @@ export class AsyncValue<VALUE, PAYLOAD = any> {
...[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 {
Expand All @@ -119,20 +122,37 @@ export class AsyncValue<VALUE, PAYLOAD = any> {
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));

Expand Down
9 changes: 9 additions & 0 deletions libs/scenarios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @dhi/arsenal.scenarios

## 21.0.0

### Patch Changes

- Updated dependencies
- @dhi/arsenal[email protected]
- @dhi/arsenal[email protected]
- @dhi/arsenal[email protected]

## 20.0.0

### Major Changes
Expand Down
2 changes: 1 addition & 1 deletion libs/scenarios/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 7 additions & 0 deletions libs/ui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @dhi/arsenal.ui

## 14.0.0

### Patch Changes

- Updated dependencies
- @dhi/arsenal[email protected]

## 13.0.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion libs/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhi/arsenal.ui",
"version": "13.0.0",
"version": "14.0.0",
"main": "./x/index",
"scripts": {
"build": "tsc",
Expand Down

0 comments on commit 4744998

Please sign in to comment.