-
-
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
28 changed files
with
436 additions
and
110 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
87 changes: 87 additions & 0 deletions
87
packages/core/src/controller/__tests__/__snapshots__/query.ts.snap
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,87 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Controller.query() Query based on args 1`] = ` | ||
[ | ||
Tacos { | ||
"id": "1", | ||
"type": "foo", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`Controller.query() Query based on args 2`] = ` | ||
[ | ||
Tacos { | ||
"id": "1", | ||
"type": "foo", | ||
}, | ||
Tacos { | ||
"id": "2", | ||
"type": "bar", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`Controller.query() Query+All based on args 1`] = ` | ||
[ | ||
Tacos { | ||
"id": "1", | ||
"type": "foo", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`Controller.query() Query+All based on args 2`] = ` | ||
[ | ||
Tacos { | ||
"id": "1", | ||
"type": "foo", | ||
}, | ||
Tacos { | ||
"id": "2", | ||
"type": "bar", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`Controller.query() query All 1`] = ` | ||
[ | ||
Tacos { | ||
"id": "1", | ||
"type": "foo", | ||
}, | ||
Tacos { | ||
"id": "2", | ||
"type": "bar", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`Controller.query() query Collection based on args 1`] = ` | ||
[ | ||
Tacos { | ||
"id": "1", | ||
"type": "foo", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`Controller.query() query Collection based on args 2`] = ` | ||
[ | ||
Tacos { | ||
"id": "1", | ||
"type": "foo", | ||
}, | ||
Tacos { | ||
"id": "2", | ||
"type": "bar", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`Controller.query() query Entity based on pk 1`] = ` | ||
Tacos { | ||
"id": "1", | ||
"type": "foo", | ||
} | ||
`; |
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,147 @@ | ||
import { Entity, schema } from '@data-client/endpoint'; | ||
|
||
import { initialState } from '../../state/reducer/createReducer'; | ||
import Contoller from '../Controller'; | ||
|
||
describe('Controller.query()', () => { | ||
class Tacos extends Entity { | ||
type = ''; | ||
id = ''; | ||
pk() { | ||
return this.id; | ||
} | ||
} | ||
const TacoList = new schema.Collection([Tacos]); | ||
const entities = { | ||
Tacos: { | ||
1: { id: '1', type: 'foo' }, | ||
2: { id: '2', type: 'bar' }, | ||
}, | ||
[TacoList.key]: { | ||
[TacoList.pk(undefined, undefined, '', [{ type: 'foo' }])]: ['1'], | ||
[TacoList.pk(undefined, undefined, '', [{ type: 'bar' }])]: ['2'], | ||
[TacoList.pk(undefined, undefined, '', [])]: ['1', '2'], | ||
}, | ||
}; | ||
|
||
it('query Entity based on pk', () => { | ||
const controller = new Contoller(); | ||
const state = { | ||
...initialState, | ||
entities, | ||
}; | ||
const taco = controller.query(Tacos, { id: '1' }, state); | ||
expect(taco).toBeDefined(); | ||
expect(taco).toBeInstanceOf(Tacos); | ||
expect(taco).toMatchSnapshot(); | ||
const taco2 = controller.query(Tacos, { id: '2' }, state); | ||
expect(taco2).toBeDefined(); | ||
expect(taco2).toBeInstanceOf(Tacos); | ||
expect(taco2).not.toEqual(taco); | ||
// should maintain referential equality | ||
expect(taco).toBe(controller.query(Tacos, { id: '1' }, state)); | ||
|
||
// @ts-expect-error | ||
() => controller.query(Tacos, { id: { bob: 5 } }, state); | ||
// @ts-expect-error | ||
expect(controller.query(Tacos, 5, state)).toBeUndefined(); | ||
// @ts-expect-error | ||
() => controller.query(Tacos, { doesnotexist: 5 }, state); | ||
}); | ||
|
||
it('query Collection based on args', () => { | ||
const controller = new Contoller(); | ||
const state = { | ||
...initialState, | ||
entities, | ||
}; | ||
const tacos = controller.query(TacoList, { type: 'foo' }, state); | ||
expect(tacos).toBeDefined(); | ||
expect(tacos?.[0]).toBeInstanceOf(Tacos); | ||
expect(tacos).toMatchSnapshot(); | ||
const tacosBars = controller.query(TacoList, { type: 'bar' }, state); | ||
expect(tacosBars).toBeDefined(); | ||
expect(tacosBars?.[0]).toBeInstanceOf(Tacos); | ||
expect(tacosBars).not.toEqual(tacos); | ||
// should maintain referential equality | ||
expect(tacos).toBe(controller.query(TacoList, { type: 'foo' }, state)); | ||
|
||
const allTacos = controller.query(TacoList, state); | ||
expect(allTacos).toBeDefined(); | ||
expect(allTacos).toHaveLength(2); | ||
expect(allTacos).toMatchSnapshot(); | ||
|
||
// @ts-expect-error | ||
() => controller.query(TacoList, 5, state); | ||
}); | ||
|
||
it('query All', () => { | ||
const controller = new Contoller(); | ||
const state = { | ||
...initialState, | ||
entities, | ||
}; | ||
const AllTacos = new schema.All(Tacos); | ||
|
||
const allTacos = controller.query(AllTacos, state); | ||
expect(allTacos).toBeDefined(); | ||
expect(allTacos).toHaveLength(2); | ||
expect(allTacos).toMatchSnapshot(); | ||
// should maintain referential equality | ||
// TODO: (add infer cache) expect(allTacos).toBe(controller.query(TacoList, state)); | ||
|
||
// TODO: @ts-expect-error (we have a hack to make this not break other things now) | ||
() => controller.query(AllTacos, 5, state); | ||
}); | ||
|
||
it('Query+All based on args', () => { | ||
const controller = new Contoller(); | ||
const state = { | ||
...initialState, | ||
entities, | ||
}; | ||
const QueryTacos = new schema.Query( | ||
new schema.All(Tacos), | ||
(tacos, { type }: { type?: string } = {}) => { | ||
if (!type) return tacos; | ||
return tacos.filter(taco => taco.type === type); | ||
}, | ||
); | ||
|
||
const tacos = controller.query(QueryTacos, { type: 'foo' }, state); | ||
expect(tacos).toBeDefined(); | ||
expect(tacos?.[0]).toBeInstanceOf(Tacos); | ||
expect(tacos).toMatchSnapshot(); | ||
const tacosBars = controller.query(QueryTacos, { type: 'bar' }, state); | ||
expect(tacosBars).toBeDefined(); | ||
expect(tacosBars?.[0]).toBeInstanceOf(Tacos); | ||
expect(tacosBars).not.toEqual(tacos); | ||
// should maintain referential equality | ||
// TODO: (add infer cache) expect(tacos).toBe(controller.query(QueryTacos, { type: 'foo' }, state)); | ||
|
||
const allTacos = controller.query(QueryTacos, state); | ||
expect(allTacos).toBeDefined(); | ||
expect(allTacos).toHaveLength(2); | ||
expect(allTacos).toMatchSnapshot(); | ||
|
||
// @ts-expect-error | ||
() => controller.query(QueryTacos, 5, state); | ||
}); | ||
|
||
it('Query+Collection based on args', () => { | ||
const controller = new Contoller(); | ||
const state = { | ||
...initialState, | ||
entities, | ||
}; | ||
const tacoCount = new schema.Query(TacoList, tacos => { | ||
return tacos.length; | ||
}); | ||
|
||
expect(controller.query(tacoCount, { type: 'foo' }, state)).toBe(1); | ||
expect(controller.query(tacoCount, { type: 'bar' }, state)).toBe(1); | ||
expect(controller.query(tacoCount, state)).toBe(2); | ||
}); | ||
|
||
// TODO: test Union | ||
}); |
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
Oops, something went wrong.
48e27c5
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
441
ops/sec (±2.00%
)447
ops/sec (±1.68%
)1.01
infer All
9786
ops/sec (±1.01%
)9629
ops/sec (±1.67%
)0.98
denormalizeLong
314
ops/sec (±2.61%
)321
ops/sec (±2.22%
)1.02
denormalizeLong donotcache
843
ops/sec (±0.56%
)888
ops/sec (±0.46%
)1.05
denormalizeShort donotcache 500x
1353
ops/sec (±0.35%
)1351
ops/sec (±0.13%
)1.00
denormalizeShort 500x
947
ops/sec (±0.40%
)958
ops/sec (±0.24%
)1.01
denormalizeLong with mixin Entity
292
ops/sec (±0.46%
)303
ops/sec (±0.26%
)1.04
denormalizeLong withCache
7124
ops/sec (±0.32%
)6836
ops/sec (±0.26%
)0.96
denormalizeLongAndShort withEntityCacheOnly
1580
ops/sec (±0.70%
)1562
ops/sec (±0.31%
)0.99
denormalizeLong All withCache
5817
ops/sec (±0.19%
)6337
ops/sec (±0.17%
)1.09
denormalizeLong Query-sorted withCache
6238
ops/sec (±0.30%
)6647
ops/sec (±0.38%
)1.07
getResponse
5470
ops/sec (±1.60%
)4951
ops/sec (±0.88%
)0.91
getResponse (null)
2957637
ops/sec (±2.14%
)2888601
ops/sec (±0.21%
)0.98
getResponse (clear cache)
296
ops/sec (±0.56%
)292
ops/sec (±1.10%
)0.99
getSmallResponse
2235
ops/sec (±0.96%
)2328
ops/sec (±0.30%
)1.04
getSmallInferredResponse
1796
ops/sec (±0.32%
)1765
ops/sec (±0.34%
)0.98
getResponse Query-sorted
731
ops/sec (±1.63%
)687
ops/sec (±1.09%
)0.94
getResponse Collection
5229
ops/sec (±1.76%
)5124
ops/sec (±1.06%
)0.98
setLong
428
ops/sec (±2.13%
)437
ops/sec (±2.25%
)1.02
setLongWithMerge
186
ops/sec (±0.62%
)189
ops/sec (±0.36%
)1.02
setLongWithSimpleMerge
197
ops/sec (±0.62%
)202
ops/sec (±0.27%
)1.03
This comment was automatically generated by workflow using github-action-benchmark.