Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
jdanyow committed May 5, 2015
1 parent ee8e225 commit 32b74a7
Show file tree
Hide file tree
Showing 11 changed files with 594 additions and 696 deletions.
220 changes: 98 additions & 122 deletions dist/amd/analyzer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
define(['exports'], function (exports) {
'use strict';

Object.defineProperty(exports, '__esModule', {
value: true
});
exports.__esModule = true;

var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } };

var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

var Analyzer = (function () {
function Analyzer() {
Expand All @@ -17,127 +13,107 @@ define(['exports'], function (exports) {
this.reason = '';
}

_createClass(Analyzer, [{
key: 'visitArgs',
value: function visitArgs(args) {
var i, length;
for (i = 0, length = args.length; i < length; ++i) {
args[i].accept(this);
}
}
}, {
key: 'visitChain',
value: function visitChain(chain) {
var expressions = chain.expressions,
length = expressions.length,
i;

for (i = 0; i < length; ++i) {
expressions[i].accept(this);
}
}
}, {
key: 'visitValueConverter',
value: function visitValueConverter(converter) {}
}, {
key: 'visitAssign',
value: function visitAssign(assign) {
assign.target.accept(this);
assign.value.accept(this);
}
}, {
key: 'visitConditional',
value: function visitConditional(conditional) {
conditional.condition.accept(this);
conditional.yes.accept(this);
conditional.no.accept(this);
}
}, {
key: 'visitAccessScope',
value: function visitAccessScope(access) {
if (access.name !== 'this') {
this.canObserve = false;
this.reason += '\'' + access.name + '\' can\'t be accessed from the binding scope. ';
}
}
}, {
key: 'visitAccessMember',
value: function visitAccessMember(access) {
access.object.accept(this);
}
}, {
key: 'visitAccessKeyed',
value: function visitAccessKeyed(access) {
access.object.accept(this);
access.key.accept(this);
}
}, {
key: 'visitCallScope',
value: function visitCallScope(call) {
this.visitArgs(call.args);
}
}, {
key: 'visitCallFunction',
value: function visitCallFunction(call) {
call.func.accept(this);
this.visitArgs(call.args);
}
}, {
key: 'visitCallMember',
value: function visitCallMember(call) {
call.object.accept(this);
this.visitArgs(call.args);
}
}, {
key: 'visitPrefix',
value: function visitPrefix(prefix) {
prefix.expression.accept(this);
Analyzer.analyze = function analyze(expression) {
var visitor = new Analyzer();
expression.accept(visitor);
return {
expression: expression,
canObserve: visitor.canObserve,
reason: visitor.reason
};
};

Analyzer.prototype.visitArgs = function visitArgs(args) {
var i, length;
for (i = 0, length = args.length; i < length; ++i) {
args[i].accept(this);
}
}, {
key: 'visitBinary',
value: function visitBinary(binary) {
binary.left.accept(this);
binary.right.accept(this);
};

Analyzer.prototype.visitChain = function visitChain(chain) {
var expressions = chain.expressions,
length = expressions.length,
i;

for (i = 0; i < length; ++i) {
expressions[i].accept(this);
}
}, {
key: 'visitLiteralPrimitive',
value: function visitLiteralPrimitive(literal) {}
}, {
key: 'visitLiteralArray',
value: function visitLiteralArray(literal) {
var elements = literal.elements,
length = elements.length,
i;
for (i = 0; i < length; ++i) {
elements[i].accept(this);
}
};

Analyzer.prototype.visitValueConverter = function visitValueConverter(converter) {};

Analyzer.prototype.visitAssign = function visitAssign(assign) {
assign.target.accept(this);
assign.value.accept(this);
};

Analyzer.prototype.visitConditional = function visitConditional(conditional) {
conditional.condition.accept(this);
conditional.yes.accept(this);
conditional.no.accept(this);
};

Analyzer.prototype.visitAccessScope = function visitAccessScope(access) {
if (access.name !== 'this') {
this.canObserve = false;
this.reason += '\'' + access.name + '\' can\'t be accessed from the binding scope. ';
}
}, {
key: 'visitLiteralObject',
value: function visitLiteralObject(literal) {
var keys = literal.keys,
values = literal.values,
length = keys.length,
i;
for (i = 0; i < length; ++i) {
values[i].accept(this);
}
};

Analyzer.prototype.visitAccessMember = function visitAccessMember(access) {
access.object.accept(this);
};

Analyzer.prototype.visitAccessKeyed = function visitAccessKeyed(access) {
access.object.accept(this);
access.key.accept(this);
};

Analyzer.prototype.visitCallScope = function visitCallScope(call) {
this.visitArgs(call.args);
};

Analyzer.prototype.visitCallFunction = function visitCallFunction(call) {
call.func.accept(this);
this.visitArgs(call.args);
};

Analyzer.prototype.visitCallMember = function visitCallMember(call) {
call.object.accept(this);
this.visitArgs(call.args);
};

Analyzer.prototype.visitPrefix = function visitPrefix(prefix) {
prefix.expression.accept(this);
};

Analyzer.prototype.visitBinary = function visitBinary(binary) {
binary.left.accept(this);
binary.right.accept(this);
};

Analyzer.prototype.visitLiteralPrimitive = function visitLiteralPrimitive(literal) {};

Analyzer.prototype.visitLiteralArray = function visitLiteralArray(literal) {
var elements = literal.elements,
length = elements.length,
i;
for (i = 0; i < length; ++i) {
elements[i].accept(this);
}
}, {
key: 'visitLiteralString',
value: function visitLiteralString(literal) {}
}], [{
key: 'analyze',
value: function analyze(expression) {
var visitor = new Analyzer();
expression.accept(visitor);
return {
expression: expression,
canObserve: visitor.canObserve,
reason: visitor.reason
};
};

Analyzer.prototype.visitLiteralObject = function visitLiteralObject(literal) {
var keys = literal.keys,
values = literal.values,
length = keys.length,
i;
for (i = 0; i < length; ++i) {
values[i].accept(this);
}
}]);
};

Analyzer.prototype.visitLiteralString = function visitLiteralString(literal) {};

return Analyzer;
})();
Expand Down
121 changes: 55 additions & 66 deletions dist/amd/getter-observer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
define(["exports"], function (exports) {
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.__esModule = true;

var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };

var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var GetterObserver = (function () {
function GetterObserver(object, propertyName, descriptor, expression, binding) {
Expand All @@ -20,76 +16,69 @@ define(["exports"], function (exports) {
this.binding = binding;
}

_createClass(GetterObserver, [{
key: "getValue",
value: function getValue() {
return this.object[this.propertyName];
}
}, {
key: "setValue",
value: function setValue(newValue) {
if (this.descriptor.set) {
this.object[this.propertyName] = newValue;
} else {
throw new Error("" + this.propertyName + " does not have a setter function.");
}
GetterObserver.prototype.getValue = function getValue() {
return this.object[this.propertyName];
};

GetterObserver.prototype.setValue = function setValue(newValue) {
if (this.descriptor.set) {
this.object[this.propertyName] = newValue;
} else {
throw new Error("" + this.propertyName + " does not have a setter function.");
}
}, {
key: "subscribe",
value: function subscribe(callback) {
var _this = this;
};

GetterObserver.prototype.subscribe = function subscribe(callback) {
var _this = this;

var callbacks = this.callbacks || (this.callbacks = []),
info;
var callbacks = this.callbacks || (this.callbacks = []),
info;

if (callbacks.length === 0) {
info = this.expression.connect(this.binding, { "this": this.object });
this.oldValue = info.value;
if (info.observer) {
this.observer = info.observer;
info.observer.subscribe(function () {
return _this.notify();
});
}
if (callbacks.length === 0) {
info = this.expression.connect(this.binding, { "this": this.object });
this.oldValue = this.getValue();
if (info.observer) {
this.observer = info.observer;
info.observer.subscribe(function () {
return _this.notify();
});
}
}

callbacks.push(callback);
callbacks.push(callback);

return this.unsubscribe.bind(this, callback);
return this.unsubscribe.bind(this, callback);
};

GetterObserver.prototype.notify = function notify() {
var i,
ii,
newValue = this.getValue(),
oldValue = this.oldValue,
callbacks = this.callbacks;
if (newValue === oldValue) {
return;
}
}, {
key: "notify",
value: function notify() {
var i,
ii,
newValue = this.getValue(),
oldValue = this.oldValue,
callbacks = this.callbacks;
if (newValue === oldValue) {
return;
}
this.oldValue = newValue;
for (i = 0, ii = callbacks.length; i < ii; i++) {
callbacks[i](newValue, oldValue);
}
this.oldValue = newValue;
for (i = 0, ii = callbacks.length; i < ii; i++) {
callbacks[i](newValue, oldValue);
}
}, {
key: "unsubscribe",
value: function unsubscribe(callback) {
var callbacks = this.callbacks,
index = callbacks.indexOf(callback);
if (index === -1) {
return;
}
callbacks.splice(index, 1);
if (callbacks.length === 0 && this.observer) {
if (this.observer.dispose) {
this.observer.dispose();
}
this.observer = null;
};

GetterObserver.prototype.unsubscribe = function unsubscribe(callback) {
var callbacks = this.callbacks,
index = callbacks.indexOf(callback);
if (index === -1) {
return;
}
callbacks.splice(index, 1);
if (callbacks.length === 0 && this.observer) {
if (this.observer.dispose) {
this.observer.dispose();
}
this.observer = null;
}
}]);
};

return GetterObserver;
})();
Expand Down
Loading

0 comments on commit 32b74a7

Please sign in to comment.