UNPKG

mframejs

Version:
142 lines 6.33 kB
Object.defineProperty(exports, "__esModule", { value: true }); var exported_1 = require("../binding/exported"); var ArrayMethodCallHandler = (function () { function ArrayMethodCallHandler(repeat) { this.repeat = repeat; this.name = 'repeat' + this.repeat.value; } ArrayMethodCallHandler.prototype.call = function (events) { var _this = this; var sort = true; events.forEach(function (event) { switch (event.event) { case 'push': var i = 0; while (i < event.args.length) { _this.repeat.push(event.args[i]); i++; } _this.repeat.updateInternals(); break; case 'reverse': case 'sort': if (sort) { sort = false; var array = _this.repeat.$array; if (array) { array.forEach(function (ctx, i) { _this.repeat.templateArray[i].ctx.$context[_this.repeat.rowInstanceName] = ctx; }); } } break; case 'shift': _this.repeat.shift(); break; case 'pop': _this.repeat.pop(); break; case 'splice': _this.repeat.splice(event.args); break; default: } }); }; return ArrayMethodCallHandler; }()); exports.ArrayMethodCallHandler = ArrayMethodCallHandler; var ArrayPropertyChange = (function () { function ArrayPropertyChange(repeat, expression) { this.repeat = repeat; this.expression = expression; this.name = 'repeat' + this.repeat.value; } ArrayPropertyChange.prototype.call = function () { var _this = this; if (this.repeat.isAttached) { var array = exported_1.BindingEngine.evaluateExpression(this.repeat.arrayExpression, this.repeat.$bindingContext); if (Array.isArray(array) && this.repeat.templateArray.length !== array.length) { this.repeat.$array = array; if (this.repeat.templateArray.length !== 0 && array.length !== 0) { if (this.repeat.templateArray.length > array.length) { this.repeat.loopBinded(true, this.repeat.templateArray.length - array.length, 0); } else { this.repeat.loopBinded(true, 0, array.length - this.repeat.templateArray.length); } exported_1.BindingEngine.unSubscribeClassArray(this.repeat.$bindingContext, this.repeat.arrayMethodCallHandler); this.repeat.subscribeArray(); } else { this.repeat.clearTemplateArray(); var array_1 = exported_1.BindingEngine.evaluateExpression(this.repeat.arrayExpression, this.repeat.$bindingContext); if (Array.isArray(array_1)) { array_1.forEach(function (ctx) { _this.repeat.push(ctx); }); exported_1.BindingEngine.unSubscribeClassArray(this.repeat.$bindingContext, this.repeat.arrayMethodCallHandler); this.repeat.subscribeArray(); array_1 = null; } } } else { if (Array.isArray(array)) { this.repeat.$array = array; this.repeat.loopBinded(); exported_1.BindingEngine.unSubscribeClassArray(this.repeat.$bindingContext, this.repeat.arrayMethodCallHandler); if (array) { this.repeat.subscribeArray(); } } else { this.repeat.$array = Array.isArray(array) ? array : []; this.repeat.clearTemplateArray(); exported_1.BindingEngine.unSubscribeClassArray(this.repeat.$bindingContext, this.repeat.arrayMethodCallHandler); if (array) { this.repeat.subscribeArray(); } } } } }; return ArrayPropertyChange; }()); exports.ArrayPropertyChange = ArrayPropertyChange; var PropertyChangeSimple = (function () { function PropertyChangeSimple(repeat) { this.repeat = repeat; this.name = 'repeat' + this.repeat.value; } PropertyChangeSimple.prototype.call = function (newValue) { if (this.repeat.isAttached) { if (this.repeat.arrayType === 'string') { var stringLength = typeof newValue === 'string' ? newValue.length : 0; if (this.repeat.templateArray.length !== stringLength) { this.repeat.clearTemplateArray(); for (var i = 0; i < stringLength; i++) { this.repeat.push(newValue[i]); } } } if (this.repeat.arrayType === 'number') { if (typeof newValue !== 'number') { console.warn('repeat not number:', newValue); newValue = 0; } if (this.repeat.templateArray.length !== newValue) { if (this.repeat.templateArray.length < newValue) { this.repeat.loopArrayNumber(true, 0, newValue - this.repeat.templateArray.length); } else { this.repeat.loopArrayNumber(true, this.repeat.templateArray.length - newValue, 0); } } } } }; return PropertyChangeSimple; }()); exports.PropertyChangeSimple = PropertyChangeSimple; //# sourceMappingURL=repeatAttributeSubscriberHelpers.js.map