Giter Site home page Giter Site logo

pubsub's Introduction

pubsub

A simple Pub/Sub module for chrome extension

크롬 익스텐션 개발 시,
익스텐션과 컨텐트 스크립트 간의 메시지 전달을 위한 Pub/Sub 모듈입니다.

크롬에서 이미 메시징 API를 제공하고 있지만,
(http://developer.chrome.com/extensions/messaging.html)
백그라운드와 컨텐트 스크립트에서의 호출 방식이 달라 약간 혼란스럽습니다.

pubsub는 백그라운드와 컨텐트 스크립트의 구분 없이,
간편하게 메시지를 전달할 수 있는 간단한 Pub/Sub 방식의 모듈입니다.

사용하기

pubsub.js 를 백그라운드와 컨텐트 스크립트 양쪽에 모두 추가합니다.
모듈은 window.pubsub 로 할당하며,
RequireJS를 사용하고 있다면 전역변수 대신 모듈로 define 합니다.

pubsub.pub(msg, data)

메시지를 발행(publish)합니다.
메시지는 백그라운드와 컨텐트 스크립트 양쪽으로 전달됩니다.
단, 컨텐트 스크립트로는, 탭이 활성화되어 있는 경우에만 전달합니다.

Parameters

  • msg {string} 메시지명
  • data {any} 전달할 데이터

Usage

pubsub.pub('foo', {
  'bar': 'abc'
});

pubsub.sub(msg, callback)

메시지를 구독(subscribe)합니다.

Parameters

  • msg {string} 메시지명
  • callback {function(data)} 메시지를 받은 경우 실행할 콜백

Usage

pubsub.sub('foo', function (data) {
  console.log(data); //--> { 'bar': 'abc' }
});

pubsub's People

Contributors

ohgyun avatar

Watchers

 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.