npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

bloody-tube

0.2.1 • Public • Published

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)
})

Keywords

none

install

npm i bloody-tube

Downloadsweekly downloads

21

version

0.2.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability