uupaa.message.js
Version:
MessagePassing implementation.
64 lines (44 loc) • 1.43 kB
Markdown
# Message.js [](http://travis-ci.org/uupaa/Message.js)
[](https://nodei.co/npm/message/)
MessagePassing implementation.
## Document
- [Message.js wiki](https://github.com/uupaa/Message.js/wiki/Message)
- [Development](https://github.com/uupaa/WebModule/wiki/Development)
- [WebModule](https://github.com/uupaa/WebModule) ([Slide](http://uupaa.github.io/Slide/slide/WebModule/index.html))
## How to use
### Browser
```js
<script src="lib/Task.js">
<script src="lib/Message.js">
<script>
function Foo() {
this.inbox = function(task, name, data) {
task.set(name, data.msg + "Foo").pass();
};
}
function Bar() {
this.inbox = function(task, name, data) {
task.set(name, data.msg + "Bar").pass();
};
}
var foo1 = new Foo();
var foo2 = new Foo();
var bar = new Bar();
var msg = new Message({ a: foo1, b: foo2, c: bar });
msg.post({ msg: "Hello" }, function(err, buffer) {
console.log( JSON.stringify( Task.objectize(buffer) ) ); // {"a":"HelloFoo","b":"HelloFoo","c":"HelloBar"}
});
</script>
```
### WebWorkers
```js
importScripts("lib/Task.js");
importScripts("lib/Message.js");
...
```
### Node.js
```js
var Task = require("lib/Task.js");
var Message = require("lib/Message.js");
...
```