UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

79 lines (78 loc) • 2.18 kB
/** * DevExtreme (esm/__internal/data/array_store.js) * Version: 26.1.6 * Build date: Fri Oct 16 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import { applyBatch, indexByKey, insert, remove, update } from "../../common/data/array_utils"; import { errors } from "../../common/data/errors"; import query from "../../common/data/query"; import { rejectedPromise, trivialPromise } from "../../common/data/utils"; import Store from "../data/abstract_store"; class ArrayStore extends Store { constructor(options) { const storeOptions = Array.isArray(options) ? { data: options } : options || {}; super(storeOptions); const initialArray = storeOptions.data; if (initialArray && !Array.isArray(initialArray)) { throw errors.Error("E4006") } this._array = initialArray || [] } createQuery() { const result = query(this._array, { errorHandler: this._errorHandler }); return result } _byKeyImpl(key) { const index = indexByKey(this, this._array, key); if (-1 === index) { const rejected = rejectedPromise(errors.Error("E4009")); return rejected } const resolved = trivialPromise(this._array[index]); return resolved } _insertImpl(values) { const result = insert(this, this._array, values); return result } _pushImpl(changes) { applyBatch({ keyInfo: this, data: this._array, changes: changes }) } _updateImpl(key, values) { const result = update(this, this._array, key, values); return result } _removeImpl(key) { const result = remove(this, this._array, key); return result } clear() { this._eventsStrategy.fireEvent("modifying", []); this._array = []; this._eventsStrategy.fireEvent("modified", []) } } Store.registerClass(ArrayStore, "array"); export default ArrayStore;