webmodules/jqbus 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

webmodules/jqbus

最新稳定版本:0.0.9

Composer 安装命令:

composer require webmodules/jqbus

包简介

JavaSript based message queue

README 文档

README

#JQBUS

In my module1 in some file module1.js

var bus = jqbus.instance();

bus.on("when_something_happens", function(){
    console.log("I want to be notified, so that i can do something");
});

In my module2, maybe in some other file module.js

var bus = jqbus.instance();

bus.publish("when_something_happens");

Now as you can see module1 has never interacted with mmodule2 or vice-versa, they are not even being discussed, but both modules have knowledge of jqbus and they created their own instances and somehow are able to communicate !!Hurray!!

So we have triggered some function in module1 from inside module2 without even having reference of module1, similarly we can have as many listeneres as we want in as many modules as we can. Optionally we can also pass data along with, triggering the callback function.

bus.on("when_something_happens", function(e,target,data){
    //data sent by trigger function
    console.log("I want to be notified, so that i can do something");
});

bus.publish("when_something_happens", { name : "Hello" });

In addition to passing data to different module, JQBUS is able to send data to different tab also for same domain.

we can remove listeners when we wish, by simply using

bus.off();

统计信息

  • 总下载量: 39
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 8
  • Forks: 1
  • 开发语言: JavaScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-27