UNPKG

2.73 kBJavaScriptView Raw
1void (function(){var _ion_runtime_OperationExpression_ = function(module,exports,require){'use strict';
2var ion = require('../'), DynamicExpression = require('./DynamicExpression');
3var OperationExpression = ion.defineClass({
4 name: 'OperationExpression',
5 constructor: function OperationExpression(properties) {
6 OperationExpression.super.apply(this, arguments);
7 if (!(this.args != null)) {
8 if (this.type === 'BinaryExpression') {
9 this.args = [
10 this.left,
11 this.right
12 ];
13 } else if (this.type === 'UnaryExpression') {
14 this.args = [this.argument];
15 } else if (this.type === 'ConditionalExpression') {
16 this.args = [
17 this.test,
18 this.consequent,
19 this.alternate
20 ];
21 }
22 }
23 },
24 properties: {
25 args: null,
26 activate: function () {
27 OperationExpression.super.prototype.activate.apply(this, arguments);
28 this.argumentExpressions = this.argumentExpressions != null ? this.argumentExpressions : this.context.createRuntime({
29 type: 'ArrayExpression',
30 elements: this.args,
31 observeElements: this.factory.observe
32 });
33 this.argumentExpressions.watch(this.watcher = this.watcher != null ? this.watcher : ion.bind(function (value) {
34 this.argumentValues = value;
35 this.evaluate();
36 }, this));
37 },
38 deactivate: function () {
39 OperationExpression.super.prototype.deactivate.apply(this, arguments);
40 this.argumentExpressions.unwatch(this.watcher);
41 },
42 evaluate: function () {
43 if (!(this.factory.evaluate != null)) {
44 throw new Error('evaluate method not defined for operation: ' + this.factory);
45 }
46 var value = this.factory.evaluate.apply(this.context, this.argumentValues);
47 this.setValue(value);
48 }
49 }
50 }, DynamicExpression);
51module.exports = OperationExpression;
52 }
53 if (typeof require === 'function') {
54 if (require.register)
55 require.register('ion/runtime/OperationExpression',_ion_runtime_OperationExpression_);
56 else
57 _ion_runtime_OperationExpression_.call(this, module, exports, require);
58 }
59 else {
60 _ion_runtime_OperationExpression_.call(this);
61 }
62}).call(this)
63//# sourceMappingURL=./OperationExpression.map
\No newline at end of file