Created
February 8, 2015 18:21
-
-
Save cevek/f6bf5d833f2320baab7c to your computer and use it in GitHub Desktop.
fixed observable
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) { | |
if (member.kind === 126){ | |
writeLine(); | |
emitStart(member); | |
var memberName = member.name.text; | |
var owner = node.name.text; | |
var ownerName = node.name.text; | |
if (!(member.flags & 128 /* Static */)) { | |
owner = 'this'; | |
} | |
write("var getter = function(){return __observableGet("+owner+"."+memberName+"_, "+owner+", '"+memberName+"', "+member.symbol.id+")};"); | |
writeLine(); | |
write("getter.displayName = '"+ownerName+"."+memberName+".get';"); | |
writeLine(); | |
write("var setter = function(value){"+owner+"."+memberName+"_ = __observableSet("+owner+"."+memberName+"_, "+owner+", '"+memberName+"', "+member.symbol.id+", value)};"); | |
writeLine(); | |
write("setter.displayName = '"+ownerName+"."+memberName+".set';"); | |
writeLine(); | |
write("Object.defineProperty("); | |
emitStart(member.name); | |
emitNode(node.name); | |
if (!(member.flags & 128 /* Static */)) { | |
write(".prototype"); | |
} | |
write(", "); | |
emitExpressionForPropertyName(member.name); | |
emitEnd(member.name); | |
write(", {"); | |
increaseIndent(); | |
writeLine(); | |
write("get: getter,"); | |
writeLine(); | |
write("set: setter,"); | |
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