Skip to content

Instantly share code, notes, and snippets.

@cevek
Created February 8, 2015 15:50
Show Gist options
  • Save cevek/39596b12a0cd7545910b to your computer and use it in GitHub Desktop.
Save cevek/39596b12a0cd7545910b to your computer and use it in GitHub Desktop.
observe every property
function emitMemberFunctions(node) {
ts.forEach(node.members, function (member) {
//console.log(member.kind, member);
if (member.kind === 126){
writeLine();
emitStart(member);
write("Object.defineProperty(");
emitStart(member.name);
emitNode(node.name);
var memberName = member.name.text;
var owner = node.name.text;
if (!(member.flags & 128 /* Static */)) {
write(".prototype");
owner = 'this';
}
write(", ");
emitExpressionForPropertyName(member.name);
emitEnd(member.name);
write(", {");
increaseIndent();
writeLine();
write("get: function(){return __observableGet("+owner+"."+memberName+"_, "+owner+", '"+memberName+"')},");
writeLine();
write("set: function(value){"+owner+"."+memberName+"_ = __observableSet("+owner+"."+memberName+"_, "+owner+", '"+memberName+"', value)},");
writeLine();
write("enumerable: true,");
writeLine();
write("configurable: true");
decreaseIndent();
writeLine();
write("});");
emitEnd(member);
}
if (member.kind === 128 /* MethodDeclaration */ || node.kind === 127 /* MethodSignature */) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment