ferngully-aurelia-tools
Version:
Ferngully Tools for Aurelia
79 lines • 3.98 kB
JavaScript
System.register(["aurelia-framework", "aurelia-binding"], function (exports_1, context_1) {
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __moduleName = context_1 && context_1.id;
function _delay(newValue) {
var state = this.throttleState;
var _this = this;
state.newValue = newValue;
if (!state.timeoutId && (state.newValue !== state.currentValue)) {
state.timeoutId = setTimeout(function () {
if (state.newValue !== state.currentValue) {
_this.throttledMethod(state.newValue);
state.currentValue = state.newValue;
}
state.timeoutId = 0;
}, state.delay);
}
}
var aurelia_framework_1, aurelia_binding_1, PersistentBindingBehavior;
return {
setters: [
function (aurelia_framework_1_1) {
aurelia_framework_1 = aurelia_framework_1_1;
},
function (aurelia_binding_1_1) {
aurelia_binding_1 = aurelia_binding_1_1;
}
],
execute: function () {
PersistentBindingBehavior = (function () {
function PersistentBindingBehavior() {
}
PersistentBindingBehavior.prototype.bind = function (binding, scope, delay, currentValue) {
if (delay === undefined) {
delay = 500;
}
var methodToThrottle = 'updateTarget';
if (binding.callSource) {
methodToThrottle = 'callSource';
}
else if (binding.updateSource && binding.mode === aurelia_binding_1.bindingMode.twoWay) {
methodToThrottle = 'updateSource';
}
binding.throttledMethod = binding[methodToThrottle];
binding.throttledMethod.originalName = methodToThrottle;
binding[methodToThrottle] = _delay;
binding.throttleState = {
delay: delay,
timeoutId: null,
currentValue: currentValue,
newValue: undefined
};
};
PersistentBindingBehavior.prototype.unbind = function (binding, scope) {
var methodToRestore = binding.throttledMethod.originalName;
binding[methodToRestore] = binding.throttledMethod;
binding.throttledMethod = null;
clearTimeout(binding.throttleState.timeoutId);
binding.throttleState = null;
};
PersistentBindingBehavior = __decorate([
aurelia_framework_1.autoinject,
__metadata("design:paramtypes", [])
], PersistentBindingBehavior);
return PersistentBindingBehavior;
}());
exports_1("PersistentBindingBehavior", PersistentBindingBehavior);
}
};
});
//# sourceMappingURL=persistent.js.map