Skip to content

Commit

Permalink
feat: support promise in qref fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-capellari committed Apr 20, 2023
1 parent fd6ef4a commit 6fe26ca
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
7 changes: 6 additions & 1 deletion packages/aegis/.swcrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"parser": {
"syntax": "typescript"
},
"target": "es2022"
"target": "es2022",
"baseUrl": "./",
"paths": {
"@/src/*": ["./src/*"],
"@/tools/*": ["./tools/*"]
}
},
"module": {
"type": "es6"
Expand Down
4 changes: 2 additions & 2 deletions packages/aegis/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jujulego/aegis",
"version": "2.0.0-alpha.1",
"version": "2.0.0-alpha.2",
"license": "MIT",
"author": "Julien Capellari <julien.capellari@google.com>",
"repository": {
Expand Down Expand Up @@ -34,7 +34,7 @@
},
"dependencies": {
"@jujulego/event-tree": "^2.6.1",
"@jujulego/utils": "^1.3.1"
"@jujulego/utils": "^1.3.2"
},
"devDependencies": {
"@jujulego/flow": "1.1.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/aegis/src/query/q-ref.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { group, IListenable, IObservable, OffGroup, offGroup, once, source, waitFor } from '@jujulego/event-tree';
import { Query, QueryState, QueryStateDone, QueryStateFailed, QueryStatePending } from '@jujulego/utils';
import { $queryfy, Query, QueryState, QueryStateDone, QueryStateFailed, QueryStatePending } from '@jujulego/utils';

// Types
export type Fetcher<D> = () => Query<D>;
export type Fetcher<D> = () => PromiseLike<D>;
export type Strategy = 'keep' | 'replace';

export type QRefEventMap<D> = {
Expand Down Expand Up @@ -51,7 +51,7 @@ export class QRef<D> implements IObservable<QueryState<D>>, IListenable<QRefEven
this.cancel();

// Create new query
this._query = fetcher();
this._query = $queryfy(fetcher());

if (this._query.status === 'pending') {
this._off = offGroup();
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@ __metadata:
dependencies:
"@jujulego/event-tree": ^2.6.1
"@jujulego/flow": 1.1.0
"@jujulego/utils": ^1.3.1
"@jujulego/utils": ^1.3.2
"@swc/cli": 0.1.62
"@swc/core": 1.3.50
"@swc/helpers": 0.5.0
Expand Down Expand Up @@ -1388,12 +1388,12 @@ __metadata:
languageName: node
linkType: hard

"@jujulego/utils@npm:^1.3.1":
version: 1.3.1
resolution: "@jujulego/utils@npm:1.3.1"
"@jujulego/utils@npm:^1.3.2":
version: 1.3.2
resolution: "@jujulego/utils@npm:1.3.2"
dependencies:
"@jujulego/event-tree": ^2.5.0
checksum: c1d69e74b37c14b2ba04f8ae7e41e4745f1862b39ab1a61c3da8e3abb8a0581ca35ae6d47fa79e6785dae666c5da614eb16825bf31996c07e7b7c55c4315cbfc
checksum: 2d647f0bcf6960f35a837242f1fc66f602964e7ceb8c2698cfb2958a508a88bf271070580f18f480dfd6e4b777700e71923aa95ce2c3fe539d61901a0a1c654c
languageName: node
linkType: hard

Expand Down

0 comments on commit 6fe26ca

Please sign in to comment.