Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions e2e/compilation-cases/T1316896.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { ArrayStore } from 'devextreme/common/data';

interface Entity {
id?: string;
name?: string;
}

type Change<TItem, TKey> = {
type: 'insert' | 'update' | 'remove';
data?: TItem;
key?: TKey;
index?: number;
};

function notify(changes: Array<Change<Entity, string>>): void {
const change = changes[0];
if (change?.data?.id && change.key) {
const identifier: string = change.key;
const newId: string = change.data.id;

const ensureString: string = `${identifier}:${newId}`;
// eslint-disable-next-line no-console
// console.log(ensureString);
}
}

const store = new ArrayStore<Entity, string>({
key: 'id',
data: [{ id: '1', name: 'Initial' }],
onPush: notify,
});

function load(items: Entity[]): void {
const changes: Array<Change<Entity, string>> = items.map((data): Change<Entity, string> => ({
key: data.id,
data,
type: 'insert',
}));

store.push(changes);
}

function pushSingle(): void {
store.push([
{
key: '2',
data: { id: '2', name: 'New entity' },
type: 'insert',
},
]);
}

load([{ id: '3', name: 'Batch load' }]);
pushSingle();
12 changes: 10 additions & 2 deletions packages/devextreme/js/data/store.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { DxPromise, DxExtendedPromise } from '../core/utils/deferred';
import { DeepPartial } from '../core';
import { FilterDescriptor, GroupDescriptor, LoadOptions } from '../common/data';

type StoreChange<TItem = any, TKey = any > = {
type: 'insert' | 'update' | 'remove';
data?: DeepPartial<TItem>;
key?: TKey;
index?: number;
};

/**
* @docid StoreOptions
* @namespace DevExpress.common.data
Expand Down Expand Up @@ -57,10 +64,11 @@ export type StoreOptions<
onModifying?: Function;
/**
* @docid StoreOptions.onPush
* @type_function_param1 changes:Array<any>
* @action
* @public
*/
onPush?: ((changes: Array<TItem>) => void);
onPush?: ((changes: Array<StoreChange<TItem, TKey>>) => void);
/**
* @docid StoreOptions.onRemoved
* @type_function_param1 key:object|string|number
Expand Down Expand Up @@ -166,7 +174,7 @@ export class Store<
* @param1 changes:Array<any>
* @public
*/
push(changes: Array<{ type: 'insert' | 'update' | 'remove'; data?: DeepPartial<TItem>; key?: TKey; index?: number }>): void;
push(changes: Array<StoreChange<TItem, TKey>>): void;
/**
* @docid
* @publicName remove(key)
Expand Down
20 changes: 11 additions & 9 deletions packages/devextreme/ts/dx.all.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4094,14 +4094,7 @@ declare module DevExpress.common.data {
/**
* [descr:Store.push(changes)]
*/
push(
changes: Array<{
type: 'insert' | 'update' | 'remove';
data?: DevExpress.core.DeepPartial<TItem>;
key?: TKey;
index?: number;
}>
): void;
push(changes: Array<DevExpress.data.StoreChange<TItem, TKey>>): void;
/**
* [descr:Store.remove(key)]
*/
Expand Down Expand Up @@ -4157,7 +4150,7 @@ declare module DevExpress.common.data {
/**
* [descr:StoreOptions.onPush]
*/
onPush?: (changes: Array<TItem>) => void;
onPush?: (changes: Array<DevExpress.data.StoreChange<TItem, TKey>>) => void;
/**
* [descr:StoreOptions.onRemoved]
*/
Expand Down Expand Up @@ -7858,6 +7851,15 @@ declare module DevExpress.data {
* @deprecated Attention! This type is for internal purposes only. If you used it previously, please submit a ticket to our {@link https://supportcenter.devexpress.com/ticket/create Support Center}. We will check if there is an alternative solution.
*/
export type SortDescriptor<T> = KeySelector<T> | OrderingDescriptor<T>;
/**
* @deprecated Attention! This type is for internal purposes only. If you used it previously, please submit a ticket to our {@link https://supportcenter.devexpress.com/ticket/create Support Center}. We will check if there is an alternative solution.
*/
type StoreChange<TItem = any, TKey = any> = {
type: 'insert' | 'update' | 'remove';
data?: DevExpress.core.DeepPartial<TItem>;
key?: TKey;
index?: number;
};
/**
* @deprecated Attention! This type is for internal purposes only. If you used it previously, please submit a ticket to our {@link https://supportcenter.devexpress.com/ticket/create Support Center}. We will check if there is an alternative solution.
*/
Expand Down
Loading