-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
181 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { useCache } from '@data-client/react'; | ||
import { useQuery } from '@data-client/react'; | ||
import { queryRemainingTodos } from 'resources/TodoResource'; | ||
|
||
export default function TodoStats({ userId }: { userId?: number }) { | ||
const remaining = useCache(queryRemainingTodos, { userId }); | ||
const remaining = useQuery(queryRemainingTodos, { userId }); | ||
|
||
return <div>{remaining} tasks remaining</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import type { | ||
EntityTable, | ||
NormalizedIndex, | ||
Queryable, | ||
SchemaSimple, | ||
} from '../interface.js'; | ||
import type { Denormalize, SchemaArgs } from '../normal.js'; | ||
|
||
/** | ||
* Programmatic cache reading | ||
* @see https://dataclient.io/rest/api/Query | ||
*/ | ||
export default class Query< | ||
S extends Queryable, | ||
P extends (entries: Denormalize<S>, ...args: any) => any = ( | ||
entries: Denormalize<S>, | ||
...args: SchemaArgs<S> | ||
) => Denormalize<S>, | ||
> implements SchemaSimple<ReturnType<P> | undefined, ProcessParameters<P, S>> | ||
{ | ||
declare schema: S; | ||
declare process: P; | ||
declare thingy: ProcessParameters<P, S>; | ||
|
||
constructor(schema: S, process?: P) { | ||
this.schema = schema; | ||
if (process) this.process = process; | ||
// allows for inheritance overrides | ||
else if (!this.process) | ||
this.process = ((entries: Denormalize<S>) => entries) as any; | ||
} | ||
|
||
normalize(...args: any) { | ||
return (this.schema as any).normalize(...args); | ||
} | ||
|
||
denormalize(input: {}, args: any, unvisit: any): ReturnType<P> | undefined { | ||
const value = unvisit(input, this.schema); | ||
return typeof value === 'symbol' ? undefined : this.process(value, ...args); | ||
} | ||
|
||
infer( | ||
args: ProcessParameters<P, S>, | ||
indexes: any, | ||
recurse: ( | ||
schema: any, | ||
args: any, | ||
indexes: NormalizedIndex, | ||
entities: EntityTable, | ||
) => any, | ||
entities: EntityTable, | ||
) { | ||
return recurse(this.schema, args, indexes, entities); | ||
} | ||
|
||
declare _denormalizeNullable: ( | ||
input: {}, | ||
args: readonly any[], | ||
unvisit: (input: any, schema: any) => any, | ||
) => ReturnType<P> | undefined; | ||
} | ||
|
||
type ProcessParameters<P, S extends Queryable> = | ||
P extends (entries: any, ...args: infer Par) => any ? | ||
Par extends [] ? | ||
SchemaArgs<S> | ||
: Par & SchemaArgs<S> | ||
: SchemaArgs<S>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
6430e71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
normalizeLong
424
ops/sec (±2.14%
)447
ops/sec (±1.68%
)1.05
infer All
9559
ops/sec (±1.42%
)9629
ops/sec (±1.67%
)1.01
denormalizeLong
216
ops/sec (±3.28%
)321
ops/sec (±2.22%
)1.49
denormalizeLong donotcache
836
ops/sec (±1.39%
)888
ops/sec (±0.46%
)1.06
denormalizeShort donotcache 500x
1339
ops/sec (±0.13%
)1351
ops/sec (±0.13%
)1.01
denormalizeShort 500x
676
ops/sec (±3.01%
)958
ops/sec (±0.24%
)1.42
denormalizeLong with mixin Entity
204
ops/sec (±3.08%
)303
ops/sec (±0.26%
)1.49
denormalizeLong withCache
7251
ops/sec (±0.25%
)6836
ops/sec (±0.26%
)0.94
denormalizeLongAndShort withEntityCacheOnly
1517
ops/sec (±0.45%
)1562
ops/sec (±0.31%
)1.03
denormalizeLong All withCache
5972
ops/sec (±0.49%
)6337
ops/sec (±0.17%
)1.06
denormalizeLong Query-sorted withCache
6401
ops/sec (±0.27%
)6647
ops/sec (±0.38%
)1.04
getResponse
4869
ops/sec (±1.08%
)4951
ops/sec (±0.88%
)1.02
getResponse (null)
2994599
ops/sec (±0.24%
)2888601
ops/sec (±0.21%
)0.96
getResponse (clear cache)
196
ops/sec (±2.78%
)292
ops/sec (±1.10%
)1.49
getSmallResponse
2223
ops/sec (±1.33%
)2328
ops/sec (±0.30%
)1.05
getSmallInferredResponse
1774
ops/sec (±0.33%
)1765
ops/sec (±0.34%
)0.99
getResponse Query-sorted
703
ops/sec (±1.31%
)687
ops/sec (±1.09%
)0.98
getResponse Collection
4966
ops/sec (±1.37%
)5124
ops/sec (±1.06%
)1.03
setLong
416
ops/sec (±2.22%
)437
ops/sec (±2.25%
)1.05
setLongWithMerge
162
ops/sec (±1.34%
)189
ops/sec (±0.36%
)1.17
setLongWithSimpleMerge
188
ops/sec (±0.87%
)202
ops/sec (±0.27%
)1.07
This comment was automatically generated by workflow using github-action-benchmark.