array_store.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * DevExtreme (data/array_store.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var _utils = require("./utils");
  11. var _query = require("./query");
  12. var _query2 = _interopRequireDefault(_query);
  13. var _errors = require("./errors");
  14. var _abstract_store = require("./abstract_store");
  15. var _abstract_store2 = _interopRequireDefault(_abstract_store);
  16. var _array_utils = require("./array_utils");
  17. var _array_utils2 = _interopRequireDefault(_array_utils);
  18. function _interopRequireDefault(obj) {
  19. return obj && obj.__esModule ? obj : {
  20. "default": obj
  21. }
  22. }
  23. var ArrayStore = _abstract_store2.default.inherit({
  24. ctor: function(options) {
  25. if (Array.isArray(options)) {
  26. options = {
  27. data: options
  28. }
  29. } else {
  30. options = options || {}
  31. }
  32. this.callBase(options);
  33. var initialArray = options.data;
  34. if (initialArray && !Array.isArray(initialArray)) {
  35. throw _errors.errors.Error("E4006")
  36. }
  37. this._array = initialArray || []
  38. },
  39. createQuery: function() {
  40. return (0, _query2.default)(this._array, {
  41. errorHandler: this._errorHandler
  42. })
  43. },
  44. _byKeyImpl: function(key) {
  45. var index = _array_utils2.default.indexByKey(this, this._array, key);
  46. if (index === -1) {
  47. return (0, _utils.rejectedPromise)(_errors.errors.Error("E4009"))
  48. }
  49. return (0, _utils.trivialPromise)(this._array[index])
  50. },
  51. _insertImpl: function(values) {
  52. return _array_utils2.default.insert(this, this._array, values)
  53. },
  54. _pushImpl: function(changes) {
  55. _array_utils2.default.applyBatch(this, this._array, changes)
  56. },
  57. _updateImpl: function(key, values) {
  58. return _array_utils2.default.update(this, this._array, key, values)
  59. },
  60. _removeImpl: function(key) {
  61. return _array_utils2.default.remove(this, this._array, key)
  62. },
  63. clear: function() {
  64. this.fireEvent("modifying");
  65. this._array = [];
  66. this.fireEvent("modified")
  67. }
  68. }, "array");
  69. module.exports = ArrayStore;
  70. module.exports.default = module.exports;