devextreme
Version:
HTML5 JavaScript Component Suite for Responsive Web Development
76 lines (75 loc) • 2.08 kB
JavaScript
/**
* DevExtreme (esm/__internal/data/m_array_store.js)
* Version: 24.2.6
* Build date: Mon Mar 17 2025
*
* Copyright (c) 2012 - 2025 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";
const ArrayStore = Store.inherit({
ctor(options) {
if (Array.isArray(options)) {
options = {
data: options
}
} else {
options = options || {}
}
this.callBase(options);
const initialArray = options.data;
if (initialArray && !Array.isArray(initialArray)) {
throw errors.Error("E4006")
}
this._array = initialArray || []
},
createQuery() {
return Query(this._array, {
errorHandler: this._errorHandler
})
},
_byKeyImpl(key) {
const index = indexByKey(this, this._array, key);
if (-1 === index) {
return rejectedPromise(errors.Error("E4009"))
}
return trivialPromise(this._array[index])
},
_insertImpl(values) {
return insert(this, this._array, values)
},
_pushImpl(changes) {
applyBatch({
keyInfo: this,
data: this._array,
changes: changes
})
},
_updateImpl(key, values) {
return update(this, this._array, key, values)
},
_removeImpl(key) {
return remove(this, this._array, key)
},
clear() {
this._eventsStrategy.fireEvent("modifying");
this._array = [];
this._eventsStrategy.fireEvent("modified")
}
}, "array");
export default ArrayStore;