-
-
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
18 changed files
with
122 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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 readonly unknown[] = SchemaArgs<S>, | ||
R = Denormalize<S>, | ||
> implements SchemaSimple<R | undefined, P> | ||
{ | ||
declare schema: S; | ||
declare process: (entries: Denormalize<S>, ...args: P) => R; | ||
|
||
constructor(schema: S, process?: (entries: Denormalize<S>, ...args: P) => R) { | ||
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: P, unvisit: any): R | undefined { | ||
const value = unvisit(input, this.schema); | ||
return typeof value === 'symbol' ? undefined : this.process(value, ...args); | ||
} | ||
|
||
infer( | ||
args: P, | ||
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, | ||
) => R | undefined; | ||
} |
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
Oops, something went wrong.
461e52a
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
430
ops/sec (±2.33%
)447
ops/sec (±1.68%
)1.04
infer All
9805
ops/sec (±0.41%
)9629
ops/sec (±1.67%
)0.98
denormalizeLong
319
ops/sec (±2.54%
)321
ops/sec (±2.22%
)1.01
denormalizeLong donotcache
833
ops/sec (±1.68%
)888
ops/sec (±0.46%
)1.07
denormalizeShort donotcache 500x
1349
ops/sec (±0.37%
)1351
ops/sec (±0.13%
)1.00
denormalizeShort 500x
934
ops/sec (±0.23%
)958
ops/sec (±0.24%
)1.03
denormalizeLong with mixin Entity
304
ops/sec (±0.30%
)303
ops/sec (±0.26%
)1.00
denormalizeLong withCache
7221
ops/sec (±0.21%
)6836
ops/sec (±0.26%
)0.95
denormalizeLongAndShort withEntityCacheOnly
1604
ops/sec (±1.79%
)1562
ops/sec (±0.31%
)0.97
denormalizeLong All withCache
6383
ops/sec (±0.19%
)6337
ops/sec (±0.17%
)0.99
denormalizeLong Query-sorted withCache
6597
ops/sec (±0.34%
)6647
ops/sec (±0.38%
)1.01
getResponse
4826
ops/sec (±0.59%
)4951
ops/sec (±0.88%
)1.03
getResponse (null)
3038083
ops/sec (±0.22%
)2888601
ops/sec (±0.21%
)0.95
getResponse (clear cache)
301
ops/sec (±0.26%
)292
ops/sec (±1.10%
)0.97
getSmallResponse
2258
ops/sec (±0.90%
)2328
ops/sec (±0.30%
)1.03
getSmallInferredResponse
1794
ops/sec (±0.42%
)1765
ops/sec (±0.34%
)0.98
getResponse Query-sorted
761
ops/sec (±1.63%
)687
ops/sec (±1.09%
)0.90
getResponse Collection
4650
ops/sec (±0.54%
)5124
ops/sec (±1.06%
)1.10
setLong
435
ops/sec (±1.99%
)437
ops/sec (±2.25%
)1.00
setLongWithMerge
189
ops/sec (±0.42%
)189
ops/sec (±0.36%
)1
setLongWithSimpleMerge
202
ops/sec (±0.27%
)202
ops/sec (±0.27%
)1
This comment was automatically generated by workflow using github-action-benchmark.