Giter Site home page Giter Site logo

decoupler's Introduction

Decoupler

简介

轻量级发布订阅库。

安装

git

git clone https://github.com/longjiarun/decoupler.git decoupler

npm

npm install decoupler --save

//指定版本
npm install decoupler@version --save

bower

bower install decoupler --save

//指定版本
bower install decoupler#version --save

API

Decoupler 采用UMD的方式。

// 全局变量
decoupler.on('event',function(args){
    //do something
});
decoupler.emit('event',[1,2]);

// commonjs
var decoupler = require('decoupler');
decoupler.on('event',function(args){
    //do something
});
decoupler.emit('event',[1,2]);

方法

on

订阅消息。

参数 名称说明 类型 是否必填 默认值
name 消息名称 String
handler 回调函数 Function
decoupler.on('event',function(args){
    //do something
});

off

取消订阅消息。可取消消息中某个回调或者可取消消息中全部回调。

参数 名称说明 类型 是否必填 默认值
name 消息名称 String
handler 回调函数 Function
// 取消订阅消息中某个回调
decoupler.off('event',handler);

// 取消订阅消息中所有回调
decoupler.off('event');

emit

发布消息。

参数 名称说明 类型 是否必填 默认值
name 消息名称 String
data 消息数据 任意

decoupler's People

Contributors

longjiarun avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.