devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
186 lines (184 loc) • 6.59 kB
JavaScript
/**
* DevExtreme (cjs/__internal/data/abstract_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/
*/
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _errors = require("../../common/data/errors");
var _store_helper = _interopRequireDefault(require("../../common/data/store_helper"));
var _utils = require("../../common/data/utils");
var _events_strategy = require("../../core/events_strategy");
var _data = require("../../core/utils/data");
var _deferred = require("../../core/utils/deferred");
var _type = require("../../core/utils/type");
function _interopRequireDefault(e) {
return e && e.__esModule ? e : {
default: e
}
}
const {
queryByOptions: queryByOptions
} = _store_helper.default;
const EVENT_OPTION_NAMES = ["onLoaded", "onLoading", "onInserted", "onInserting", "onUpdated", "onUpdating", "onPush", "onRemoved", "onRemoving", "onModified", "onModifying"];
const storeImpl = {};
class Store {
constructor(options) {
this._langParams = {};
const storeOptions = options || {};
this._eventsStrategy = new _events_strategy.EventsStrategy(this);
EVENT_OPTION_NAMES.forEach(optionName => {
const handler = storeOptions[optionName];
if (handler) {
this.on(optionName.slice(2).toLowerCase(), handler)
}
});
this._key = storeOptions.key;
this._errorHandler = storeOptions.errorHandler;
this._useDefaultSearch = true
}
static create(alias, options) {
if (!(alias in storeImpl)) {
throw _errors.errors.Error("E4020", alias)
}
return new storeImpl[alias](options)
}
static registerClass(type, alias) {
if (alias) {
storeImpl[alias] = type
}
return type
}
_clearCache() {}
_customLoadOptions() {
return null
}
key() {
return this._key
}
keyOf(obj) {
const keyGetter = this._keyGetter ?? (0, _data.compileGetter)(this.key());
this._keyGetter = keyGetter;
const result = keyGetter(obj);
return result
}
_requireKey() {
if (!this.key()) {
throw _errors.errors.Error("E4005")
}
}
load(options) {
const loadOptions = options || {};
this._eventsStrategy.fireEvent("loading", [loadOptions]);
return this._withLock(this._loadImpl(loadOptions)).done(result => {
this._eventsStrategy.fireEvent("loaded", [result, loadOptions])
})
}
_loadImpl(options) {
const loadOptions = options || {};
if (!(0, _type.isEmptyObject)(this._langParams)) {
loadOptions._langParams = Object.assign({}, this._langParams, loadOptions._langParams)
}
const result = queryByOptions(this.createQuery(loadOptions), loadOptions, false).enumerate();
return result
}
_withLock(task) {
const result = (0, _deferred.Deferred)();
task.done(function() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key]
}
_utils.processRequestResultLock.promise().done(() => {
result.resolveWith(this, args)
})
}).fail(function() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2]
}
result.rejectWith(this, args)
});
return result
}
createQuery(options) {
throw _errors.errors.Error("E0001")
}
totalCount(options) {
return this._totalCountImpl(options)
}
_totalCountImpl(options) {
const result = queryByOptions(this.createQuery(options), options, true).count();
return result
}
byKey(key, extraOptions) {
return this._addFailHandlers(this._withLock(this._byKeyImpl(key, extraOptions)))
}
_byKeyImpl(key, extraOptions) {
throw _errors.errors.Error("E0001")
}
insert(values) {
this._eventsStrategy.fireEvent("modifying", []);
this._eventsStrategy.fireEvent("inserting", [values]);
return this._addFailHandlers(this._insertImpl(values).done((callbackValues, callbackKey) => {
this._eventsStrategy.fireEvent("inserted", [callbackValues, callbackKey]);
this._eventsStrategy.fireEvent("modified", [])
}))
}
_insertImpl(values) {
throw _errors.errors.Error("E0001")
}
update(key, values) {
this._eventsStrategy.fireEvent("modifying", []);
this._eventsStrategy.fireEvent("updating", [key, values]);
return this._addFailHandlers(this._updateImpl(key, values).done(() => {
this._eventsStrategy.fireEvent("updated", [key, values]);
this._eventsStrategy.fireEvent("modified", [])
}))
}
_updateImpl(key, values) {
throw _errors.errors.Error("E0001")
}
push(changes) {
const beforePushArgs = {
changes: changes,
waitFor: []
};
this._eventsStrategy.fireEvent("beforePushAggregation", [beforePushArgs]);
(0, _deferred.when)(...beforePushArgs.waitFor).done(() => {
this._pushImpl(changes);
this._eventsStrategy.fireEvent("beforePush", [{
changes: changes
}]);
this._eventsStrategy.fireEvent("push", [changes])
})
}
_pushImpl(changes) {}
remove(key) {
this._eventsStrategy.fireEvent("modifying", []);
this._eventsStrategy.fireEvent("removing", [key]);
return this._addFailHandlers(this._removeImpl(key).done(callbackKey => {
this._eventsStrategy.fireEvent("removed", [callbackKey]);
this._eventsStrategy.fireEvent("modified", [])
}))
}
_removeImpl(key) {
throw _errors.errors.Error("E0001")
}
_addFailHandlers(deferred) {
return deferred.fail(this._errorHandler).fail(_errors.handleError)
}
on(eventName, eventHandler) {
this._eventsStrategy.on(eventName, eventHandler);
return this
}
off(eventName, eventHandler) {
this._eventsStrategy.off(eventName, eventHandler);
return this
}
}
var _default = exports.default = Store;