jw-ng-forward
Version:
Temporary package. The default solution for those that want to write Angular 2.x style code in Angular 1.x
67 lines (66 loc) • 2.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var BIND_STRING = '_bind_string_';
var BIND_ONEWAY = '_bind_oneway_';
var BIND_TWOWAY = '_bind_twoway_';
function isDefined(value) { return typeof value !== 'undefined'; }
function inputsMap(inputs) {
var definition = {};
for (var key in inputs) {
var lowercaseInput = inputs[key];
definition["@" + key] = "@" + lowercaseInput;
definition["[" + inputs[key] + "]"] = "=?";
definition["[(" + inputs[key] + ")]"] = "=?";
}
return definition;
}
exports.inputsMap = inputsMap;
function inputsBuilder(controller, localKey, publicKey) {
var _a;
var stringKey = "@" + localKey;
var oneWayKey = "[" + publicKey + "]";
var twoWayKey = "[(" + publicKey + ")]";
var __stringKey = Symbol();
var __oneWayKey = Symbol();
var __twoWayKey = Symbol();
var __using_binding = Symbol();
Object.defineProperties(controller, (_a = {},
_a[stringKey] = {
enumerable: false, configurable: false,
set: createHiddenPropSetter(BIND_STRING, __stringKey),
get: function () { return this[__stringKey]; }
},
_a[oneWayKey] = {
enumerable: false, configurable: false,
set: createHiddenPropSetter(BIND_ONEWAY, __oneWayKey),
get: function () { return this[__oneWayKey]; }
},
_a[twoWayKey] = {
enumerable: false, configurable: false,
set: createHiddenPropSetter(BIND_TWOWAY, __twoWayKey),
get: function () { return this[localKey]; }
},
_a[__using_binding] = {
enumerable: false, configurable: false, writable: true,
value: controller.__using_binding || {}
},
_a));
function createHiddenPropSetter(BIND_TYPE, __privateKey) {
return function (val) {
this[__privateKey] = val;
if (isDefined(val)) {
setBindingUsed(BIND_TYPE, localKey);
}
if (controller[__using_binding][localKey] === BIND_TYPE) {
this[localKey] = val;
}
};
}
function setBindingUsed(using, key) {
if (controller[__using_binding][key] && controller[__using_binding][key] !== using) {
throw new Error("Can not use more than one type of attribute binding simultaneously: " + key + ", [" + key + "], [(" + key + ")]. Choose one.");
}
controller[__using_binding][key] = using;
}
}
exports.inputsBuilder = inputsBuilder;