Comparing version 0.5.4 to 0.6.0
@@ -20,2 +20,3 @@ // Generated by LiveScript 1.4.0 | ||
this._onIncomingCommand = bind$(this, '_onIncomingCommand', prototype); | ||
this.send = bind$(this, 'send', prototype); | ||
this.commandHandler = new HandlerManager(); | ||
@@ -54,3 +55,4 @@ this.commandSender = new CommandSender({ | ||
return this.commandHandler.handleRequest(requestData, { | ||
reply: this.commandSender.replyMethodFor(requestData.requestId) | ||
reply: this.commandSender.replyMethodFor(requestData.requestId), | ||
send: this.send | ||
}); | ||
@@ -57,0 +59,0 @@ }; |
{ | ||
"name": "exorelay", | ||
"version": "0.5.4", | ||
"version": "0.6.0", | ||
"description": "Communication relay between JavaScript code bases and the Exosphere environment", | ||
@@ -5,0 +5,0 @@ "main": "lib/exorelay.js", |
@@ -28,2 +28,24 @@ # Exosphere Communication Relay for JavaScript | ||
## Handle incoming commands | ||
Register a handler for incoming commands: | ||
```coffeescript | ||
exoRelay.registerHandler 'hello', (name) -> | ||
console.log "Hello #{name}" | ||
``` | ||
More details on how to define command listeners are [here](features/receiving-commands.feature). | ||
If you are implementing services, you want to send outgoing replies to incoming commands: | ||
```coffeescript | ||
exoRelay.registerHandler 'users.create', (userData, {reply}) -> | ||
# on this line we would create a user database record with the attributes given in userData | ||
reply 'users.created', id: 456, name: userData.name | ||
``` | ||
More details and a working example of how to send replies is [here](features/outgoing-replies.feature). | ||
## Send outgoing commands | ||
@@ -49,22 +71,12 @@ | ||
More examples for handling incoming replies are [here](features/incoming-replies.feature). | ||
Command handlers also provide a shortcut to send commands: | ||
## Handle incoming commands | ||
Register a handler for incoming commands: | ||
```coffeescript | ||
exoRelay.registerHandler 'hello', (name) -> | ||
console.log "Hello #{name}" | ||
exoRelay.registerHandler 'users.create', (userData, {send, reply}) -> | ||
send 'passwords.encrypt' userData.password, (encryptedPassword) -> | ||
userData.encryptedPassword = encryptedPassword | ||
# on this line we would create a user database record with the attributes given in userData | ||
reply 'users.created', id: 456, name: userData.name | ||
``` | ||
More details on how to define command listeners are [here](features/receiving-commands.feature). | ||
If you are implementing services, you want to send outgoing replies to incoming commands: | ||
```coffeescript | ||
exoRelay.registerHandler 'users.create', (userData, {reply}) -> | ||
# on this line we would create a user database record with the attributes given in userData | ||
reply 'users.created', id: 456, name: userData.name | ||
``` | ||
More details and a working example of how to send replies is [here](features/outgoing-replies.feature). | ||
More details and a working example of how to send commands from within command handlers is [here](features/sending-from-commands.feature). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18654
374
81