@pilotlab/lux-attributes
Version:
A luxurious user experience framework, developed by your friends at Pilot.
121 lines • 6.01 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var lux_is_1 = require("@pilotlab/lux-is");
var lux_result_1 = require("@pilotlab/lux-result");
var lux_progress_1 = require("@pilotlab/lux-progress");
var attributeEnums_1 = require("./attributeEnums");
var attributeChangeOptions_1 = require("./attributeChangeOptions");
var lux_animation_1 = require("@pilotlab/lux-animation");
var AttributeUpdateTracker = (function () {
function AttributeUpdateTracker(attributesNew, changeOptions, progressTracker, attributesChanged) {
if (changeOptions === void 0) { changeOptions = attributeChangeOptions_1.default.default; }
this.p_isChanged = false;
this.attributesNew = attributesNew;
this.changeOptions = changeOptions;
this.p_result = new lux_result_1.Result();
if (lux_is_1.default.notEmpty(progressTracker))
this.progressTracker = progressTracker;
this.p_attributesChanged = lux_is_1.default.notEmpty(attributesChanged) ? attributesChanged : attributesNew.create.collection.instance();
this.animation = new lux_animation_1.AnimationBatch(lux_animation_1.Animation.animate, [], false);
}
Object.defineProperty(AttributeUpdateTracker.prototype, "progressTracker", {
get: function () {
if (lux_is_1.default.empty(this.p_progressTracker)) {
this.progressTracker = new lux_progress_1.ProgressTracker();
}
return this.p_progressTracker;
},
set: function (value) {
var _this = this;
if (lux_is_1.default.empty(value))
return;
this.p_progressTracker = value;
this.p_progressTracker.completed.listenOnce(function () {
_this.animation.initialize();
_this.p_result.resolve(_this);
});
},
enumerable: true,
configurable: true
});
Object.defineProperty(AttributeUpdateTracker.prototype, "result", {
get: function () { return this.p_result; },
enumerable: true,
configurable: true
});
Object.defineProperty(AttributeUpdateTracker.prototype, "isChanged", {
get: function () { return this.p_isChanged; },
enumerable: true,
configurable: true
});
Object.defineProperty(AttributeUpdateTracker.prototype, "attributesChanged", {
get: function () { return this.p_attributesChanged; },
enumerable: true,
configurable: true
});
AttributeUpdateTracker.prototype.then = function (onDone, onError) {
return this.p_result.then(onDone, onError);
};
AttributeUpdateTracker.prototype.update = function (attributesToUpdate) {
var _this = this;
this.attributesNew.forEach(function (attributeNew) {
var attributeToUpdate = lux_is_1.default.notEmpty(attributesToUpdate) ? attributesToUpdate.get(attributeNew.key) : null;
if (lux_is_1.default.empty(attributeToUpdate))
return true;
if (attributeToUpdate.dataType === attributeEnums_1.DataType.COLLECTION)
_this.p_queueAttributesUpdate(attributeToUpdate.value, attributeNew);
_this.p_queueAttributeUpdate(attributeToUpdate, attributeNew);
return true;
});
};
AttributeUpdateTracker.prototype.p_queueCommand = function (command, key) {
if (lux_is_1.default.empty(command))
return;
if (lux_is_1.default.empty(key))
this.progressTracker.queueCommand(command, [this.attributesNew, this.changeOptions]);
else {
var dataAttribute = this.attributesNew.get(key);
if (lux_is_1.default.empty(dataAttribute) || dataAttribute.isEmpty)
return;
this.progressTracker.queueCommand(command, [dataAttribute.value, this]);
}
};
AttributeUpdateTracker.prototype.p_queueAttributeUpdate = function (attributeToUpdate, attributeNew) {
var _this = this;
if (lux_is_1.default.empty(attributeNew))
attributeNew = this.attributesNew.get(attributeToUpdate.key);
if (attributeNew.isEmpty)
return;
this.progressTracker.queue(function (args) {
attributeToUpdate.set(attributeNew.value, _this.changeOptions).then(function (attributeSetReturn) {
if (lux_is_1.default.notEmpty(attributeSetReturn.animation) && attributeSetReturn.animation.animations.size > 0) {
_this.animation.animations.append(attributeSetReturn.animation.animations);
}
if (attributeSetReturn.isChanged) {
_this.p_isChanged = true;
_this.p_attributesChanged.addByPath(attributeToUpdate, attributeToUpdate.path);
}
args.result.resolve();
});
}, this, 'updating ' + attributeToUpdate.key + ' attribute');
};
AttributeUpdateTracker.prototype.p_queueAttributesUpdate = function (attributesToUpdate, attributeNew) {
var _this = this;
if (lux_is_1.default.empty(attributesToUpdate) || lux_is_1.default.empty(attributeNew))
return;
if (attributeNew.isEmpty
|| attributeNew.dataType !== attributeEnums_1.DataType.COLLECTION
|| lux_is_1.default.empty(attributeNew.value)
|| attributeNew.value.size === 0)
return;
this.progressTracker.queue(function (args) {
var updateTracker = new AttributeUpdateTracker(attributeNew.value, _this.changeOptions, args.subTracker, _this.p_attributesChanged);
attributesToUpdate.updateTracked(updateTracker);
return updateTracker.result;
}, this, 'updating ' + attributeNew.key + ' data');
};
return AttributeUpdateTracker;
}());
exports.AttributeUpdateTracker = AttributeUpdateTracker;
exports.default = AttributeUpdateTracker;
//# sourceMappingURL=attributeUpdateTracker.js.map