Skip to content

Instantly share code, notes, and snippets.

@cevek
Created February 9, 2015 10:02
Show Gist options
  • Save cevek/9bd2a35f8be288a182a3 to your computer and use it in GitHub Desktop.
Save cevek/9bd2a35f8be288a182a3 to your computer and use it in GitHub Desktop.
update emitMemberFunctions
function emitMemberFunctions(node) {
ts.forEach(node.members, function (member) {
if (member.kind === 126){
var par = member.parent;
while(par.parent && (par = par.parent));
var txt = par.text.substr(member.pos, member.end).trim();
var observable = '//@observable';
if (txt.substr(0, observable.length) !== observable)
return;
writeLine();
emitStart(member);
var memberName = member.name.text;
var owner = node.name.text;
var ownerName = node.name.text;
var proto = node.name.text;
if (!(member.flags & 128 /* Static */)) {
owner = 'this';
proto += '.prototype';
}
write("var getter = function(){return __observableGet("+owner+"."+memberName+"_, "+owner+", '"+memberName+"', "+member.symbol.id+")};");
writeLine();
write("getter.displayName = '"+ownerName+"."+memberName+".get';");
writeLine();
//write(proto + ".__defineGetter__('"+memberName+"', getter);");
writeLine();
write("var setter = function(value){"+owner+".changes__."+memberName+" = "+owner+"."+memberName+"_;" +
"/* "+owner+"."+memberName+"_ = __observableSet("+owner+"."+memberName+"_, "+owner+", '"+memberName+"', "+member.symbol.id+", value)*/};");
writeLine();
write("setter.displayName = '"+ownerName+"."+memberName+".set';");
writeLine();
//write(proto + ".__defineSetter__('"+memberName+"', setter);");
writeLine();
write("Object.defineProperty(");
emitStart(member.name);
emitNode(node.name);
if (!(member.flags & 128)) {
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