maestro-cli-roku
Version:
command line tools for maestro-roku projects
76 lines (75 loc) • 3.55 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var BindingProperties_1 = require("./BindingProperties");
var BindingType_1 = require("./BindingType");
var Binding = /** @class */ (function () {
function Binding() {
this.isValid = false;
this.isFunctionBinding = false;
this.isTopBinding = false;
this.properties = new BindingProperties_1.BindingProperties();
}
Binding.prototype.validate = function () {
this.isValid = this.validateImpl();
};
Binding.prototype.validateImpl = function () {
if (!this.nodeId) {
this.errorMessage = 'node Id is not defined';
return false;
}
if (!this.nodeField) {
this.errorMessage = 'node field is not defined';
return false;
}
if (!this.observerId && this.properties.type !== BindingType_1.BindingType.code) {
this.errorMessage = 'observer.id is not defined';
return false;
}
if (!this.observerField && this.properties.type !== BindingType_1.BindingType.code) {
this.errorMessage = 'observer.field is not defined';
return false;
}
if (this.isFunctionBinding && this.properties.type !== BindingType_1.BindingType.oneWayTarget) {
this.errorMessage = 'observer callbacks on functions are only supported for oneWayTarget (i.e. node to vm) bindings';
return false;
}
return true;
};
Binding.prototype.getInitText = function () {
var text = '';
switch (this.properties.type) {
case BindingType_1.BindingType.oneWaySource:
text += "MOM_bindObservableField(m." + this.observerId + ", \"" + this.observerField + "\", m." + this.nodeId + ", \"" + this.nodeField + "\", " + this.properties.getBrsText() + ")";
break;
case BindingType_1.BindingType.oneWayTarget:
text += "MOM_bindNodeField(m." + this.nodeId + ", \"" + this.nodeField + "\", m." + this.observerId + ", \"" + this.observerField + "\", " + this.properties.getBrsText() + ")";
break;
case BindingType_1.BindingType.twoWay:
text += "MOM_bindFieldTwoWay(m." + this.observerId + ", \"" + this.observerField + "\", m." + this.nodeId + ", \"" + this.nodeField + "\", " + this.properties.getBrsText() + ")";
break;
case BindingType_1.BindingType.static:
//not part of init
break;
}
return text;
};
Binding.prototype.getStaticText = function () {
var text = '';
if (this.properties.type === BindingType_1.BindingType.code) {
text += "m." + this.nodeId + "." + this.nodeField + " = " + this.rawValueText;
}
else if (this.properties.type === BindingType_1.BindingType.static) {
var valueText = this.observerField.split('.').length > 1 ?
"MU_getContentField(m." + this.observerId + ",\"" + this.observerField + "\")" : "m." + this.observerId + "." + this.observerField;
if (this.properties.transformFunction) {
text += "m." + this.nodeId + "." + this.nodeField + " = " + this.properties.transformFunction + "(" + valueText + ")";
}
else {
text += "m." + this.nodeId + "." + this.nodeField + " = " + valueText;
}
}
return text;
};
return Binding;
}());
exports.default = Binding;