0.2.1 • Published 10 years ago

bloody-tube v0.2.1

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

tube

browser support

Install

$ npm install bloody-tube

Require

var tube = require("bloody-tube")

Definition

Tube is a communication manager.
It helps you to publish and subsribe to messages, and separated communication lines. It can help you managing communication between modules in medium to big applications.

Methods

tube.create() -> tube network

Creates a channel to centralise all the messages within your app.

tube.line(name) -> line

Gets or creates the name communication tunnel.

line.receive(message, callback) -> id

Executes callback each item message is sent.

line.stopReceiving(message[, id])

Stops receiving id callback, or all messages if no id is precised.

line.send(message[, args…])

Sends asynchronously a message with arguments in the line.

line.sendSync(message[, args…])

Sends synchronously a message with arguments in the line.

Usage

// tube.js
var tube = require("bloody-tube")
module.exports = tube.create()
// loginView.js
var loginLine = require("../tube").line("login")

// some code
nameInput.on("blur", function(){
  if(!this.value) return
  loginLine.send("name", this.value)
})

loginLine.receive("name:check", function(name){
  nameElement.html(name)
})
// login.js
var loginLine = require("../tube").line("login")

// some code
loginLine.receive("name", function(name){
  if(login.verify("name", name)) {
    login.set("name", name)
  }
  loginLine.send("name:check", name)
})
0.2.1

10 years ago

0.2.0

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago