|
| 1 | +import ODataStore from 'devextreme/data/odata/store'; |
| 2 | +import CustomStore from 'devextreme/data/custom_store'; |
| 3 | +import { Store } from 'devextreme/data/store'; |
| 4 | +import { LoadOptions } from 'devextreme/data'; |
| 5 | + |
| 6 | +// Remove the 'ts-expect-error' below to see the current issue: |
| 7 | +// Entity is not compatible with DeepPartial<Entity> |
| 8 | +function initCustomStore<Entity, Id>(oDataStore: ODataStore<Entity, Id>): Store<Entity, Id> { |
| 9 | + const customStore = new CustomStore<Entity, Id>({ |
| 10 | + key: 'id', |
| 11 | + byKey: (key: Id) => oDataStore.byKey(key), |
| 12 | + insert: (e: Entity) => oDataStore.insert(e), |
| 13 | + load: (options: LoadOptions<Entity>) => oDataStore.load(options), |
| 14 | + remove: (key: Id) => oDataStore.remove(key), |
| 15 | + totalCount: (obj) => oDataStore.totalCount(obj), |
| 16 | + update: (key: Id, updated: Entity) => oDataStore.update(key, updated), |
| 17 | + }); |
| 18 | + return customStore; |
| 19 | +} |
| 20 | + |
| 21 | +// If this TS issue is fixed: https://github.com/microsoft/TypeScript/issues/23132 |
| 22 | +// there will be a good workaround to use type constraints to make such an assignment possible |
| 23 | +function initCustomStore3<Entity extends object, Id>( |
| 24 | + oDataStore: ODataStore<Entity, Id>, |
| 25 | +): Store<Entity, Id> { |
| 26 | + const customStore = new CustomStore<Entity, Id>({ |
| 27 | + key: 'id', |
| 28 | + byKey: (key: Id) => oDataStore.byKey(key), |
| 29 | + insert: (e: Entity) => oDataStore.insert(e), |
| 30 | + load: (options: LoadOptions<Entity>) => oDataStore.load(options), |
| 31 | + remove: (key: Id) => oDataStore.remove(key), |
| 32 | + totalCount: (obj) => oDataStore.totalCount(obj), |
| 33 | + update: (key: Id, updated: Entity) => oDataStore.update(key, updated), |
| 34 | + }); |
| 35 | + return customStore; |
| 36 | +} |
0 commit comments