/** * @requirefiles {Event.js} */ function BindableArray() { this._eventQueue = []; /** * Cancelable event triggered before items are added to the BindableArray. * @event BindableArray#BeforeAddItems * @param {Event#EventObject} eventObject Standard cancellable event object. */ this.BeforeAddItems = new Event(this, { Cancellable: true, Queue: this._eventQueue }); this.AfterItemsAdded = new Event(this, { Queue: this._eventQueue }); this.BeforeRemoveItems = new Event(this, { Cancellable: true, Queue: this._eventQueue }); this.AfterItemsAdded = new Event(this, { Queue: this._eventQueue }); this.BeforeEditItems = new Event(this, { Cancellable: true, Queue: this._eventQueue }); this.AfterItemsEdited = new Event(this, { Queue: this._eventQueue }); this.BeforeReplaceItems = new Event(this, { Cancellable: true, Queue: this._eventQueue }); this.AfterItemsReplaced = new Event(this, { Queue: this._eventQueue }); if (arguments.length > 0) { BindableArray.prototype.push.apply(this, arguments); } } function BindableArray__unwire(item) { } function BindableArray__wire(item) { } function BindableArray_map(item) { return (Array.prototype.map.apply(this, arguments)); } function BindableArray_pop() { return (new Promise((resolve, reject) => { if (this.length > 0) { let itemList = [Array.prototype.pop.apply(this, arguments)]; let workList = itemList.slice(); this.BeforeAddItems.call(workList).then((result) => { }).catch((reason) => { if (reason === 'cancelled') { } }); return (item); } else { resolve(undefined); } })); } /** * @return {number} */ function BindableArray_push(item) { return (Array.prototype.push.apply(this, arguments)); } function BindableArray_reverse(item) { return (Array.prototype.reverse.apply(this, arguments)); } function BindableArray_shift(item) { return (Array.prototype.shift.apply(this, arguments)); } function BindableArray_slice(item) { return (Array.prototype.slice.apply(this, arguments)); } function BindableArray_sort(item) { return (Array.prototype.sort.apply(this, arguments)); } function BindableArray_splice(item) { return (Array.prototype.splice.apply(this, arguments)); } /** * @return {number} */ function BindableArray_unshift(item) { return (Array.prototype.unshift.apply(this, arguments)); } function BindableArray_from(arrayLike, mapFn) { if ((arguments.length < 1) || (arrayLike === undefined) || (arrayLike === null)) { return (new BindableArray()); } let ret = new (Function.prototype.bind.apply(BindableArray, [null].concat(arrayLike))); if (arguments.length > 1) { return (ret.map(mapFn)); } return (ret); } function BindableArray_isBindableArray(value) { return (value.__proto__.constructor === BindableArray); } BindableArray.prototype = new Array(); BindableArray.prototype.constructor = BindableArray; BindableArray.prototype._unwire = BindableArray__unwire; BindableArray.prototype._wire = BindableArray__wire; BindableArray.prototype.map = BindableArray_map; BindableArray.prototype.pop = BindableArray_pop; BindableArray.prototype.push = BindableArray_push; BindableArray.prototype.reverse = BindableArray_reverse; BindableArray.prototype.shift = BindableArray_shift; BindableArray.prototype.slice = BindableArray_slice; BindableArray.prototype.sort = BindableArray_sort; BindableArray.prototype.splice = BindableArray_splice; BindableArray.prototype.unshift = BindableArray_unshift; BindableArray.from = BindableArray_from; BindableArray.isBindableArray = BindableArray_isBindableArray;