Created
December 20, 2014 16:11
-
-
Save andrejewski/6b85cf1eeab5a7f20dd0 to your computer and use it in GitHub Desktop.
Extended EMF Actor class with generateActions()
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
/* | |
Example: Extended EMF Actor Class | |
This is not in the core package because | |
(1) it is trivial to implement and everyone should | |
be using their own base classes, and | |
(2) it sets a couple bad presidences mainly that | |
(a) methods and actions are 1:1 and | |
(b) calls to Actor should only have one arg, and | |
(3) makes debugging and type-checking tough as functions | |
are created at runtime. | |
All that said, use it if it works for you. | |
Usage: | |
myGenActor = new GenActor(myDispatcher); | |
myGenActor.generateActions('view', ['addDog', 'removeDog']); | |
myGenActor.generateActions(['updateDog']); | |
*/ | |
var Actor = require('emf').Actor; | |
class GenActor extends Actor { | |
generateActions(source, actions) { | |
if(actions === void 0) { | |
actions = source; | |
source = null; | |
} | |
var _this = this; | |
if(source) { | |
actions.forEach(function(action) { | |
_this[action] = function(x) { | |
_this.fire(source, action, x); | |
} | |
}); | |
} else { | |
actions.forEach(function(action) { | |
_this[action] = function(x) { | |
_this.fire(action, x); | |
} | |
}); | |
}; | |
} | |
} | |
module.exports = GenActor; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment