Created
May 26, 2015 23:56
-
-
Save bobrocke/84e5609afd8f0bc08fcb to your computer and use it in GitHub Desktop.
Atom Command Registration
This file contains hidden or 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
activate: function(state) { | |
this.subscriptions = new CompositeDisposable(); | |
this.subscriptions.add(atom.commands.add('.platform-darwin .tree-view', { | |
'open-a-terminal:openroot': (function(_this) { | |
return function() { | |
return _this.openroot(); | |
}; | |
})(this) | |
})); | |
this.subscriptions.add(atom.commands.add('.platform-darwin .tree-view', { | |
'open-a-terminal:openhere': (function(_this) { | |
return function() { | |
return _this.openhere(); | |
}; | |
})(this) | |
})); | |
}, |
From Michael Bolin:
() => this.openroot()` is sufficient in ES6 when the body of the function is a single expression
This is what worked:
activate: function(state) {
var self = this;
this.subscriptions = new CompositeDisposable();
this.subscriptions.add(
atom.commands.add(
'.tree-view',
{
'open-a-terminal:openroot': function() { return self.openroot();},
'open-a-terminal:openhere': function() { return self.openhere();}
}
)
);
},
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From Thomas Johansen:
I'm 99% sure you can't evaluate functions when creating a object literal; just capture the
this
in the closure. So instead of doing the nested function approach to capture it, dovar self = this;
before adding the commands, and use e.g.self.openroot();
.Thomas Johansen [12:21 AM]
Better yet would be to use ES6 (i.e. Babel), then you could replace that yucky function with an arrow function;
open-a-terminal:openroot
: () => { this.openroot(); }`