Created
February 8, 2015 15:50
-
-
Save cevek/39596b12a0cd7545910b to your computer and use it in GitHub Desktop.
observe every property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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