npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@condenast/quick-bus

v0.2.0

Published

A tiny and fast event bus with AMQP and Postal.js-like functionality

Downloads

2,994

Maintainers

joshcondenastjoshcondenastvikas-scvikas-scvishu_1007vishu_1007vmishra2305vmishra2305skumar7skumar7cyrilpanicker-condenastcyrilpanicker-condenastsreenu-condenastsreenu-condenastronjr_owlbearronjr_owlbearboygao1992boygao1992saikat_condesaikat_condeashanateshashanateshpriyadarshinitaopriyadarshinitaonaresh.kandhannaresh.kandhandeepakmohandeepakmohanhusnabushrahusnabushraramjeetmramjeetmimleodcimleodcskumar3condeskumar3condemounika-boyapatimounika-boyapatinagaraja_hnagaraja_hjasonmarlinjasonmarlinaruncondearunconderoberlanderroberlanderjosemanuel.barea.ortizjosemanuel.barea.ortiznprabhu-cnnprabhu-cnsahildshah1sahildshah1jmundycnjmundycnjuliendevlinjuliendevlinsheetalparsasheetalparsaunviradiyaunviradiyassingh417ssingh417dev-anand-94dev-anand-94vinitha_thiagarajanvinitha_thiagarajanprasil1107prasil1107swarupshankarswarupshankarareadmanareadmanabhishek_pandey_cnabhishek_pandey_cnvchand-cnvchand-cnharsh_condenastharsh_condenastswati_versoswati_versosamruddhidube24samruddhidube24gapurdevgapurdevakshayjain10akshayjain10utkarsh24utkarsh24suma_ksuma_kmohnish_vuritymohnish_vuritypiyush_daspiyush_daskshitiz_choudharykshitiz_choudharycnmanjucnmanjuvvkudachivvkudachivijeshrjvijeshrjjkrausjkrausvaseemakramvaseemakramsharvanipatilsharvanipatilcn-rahul-tiwaricn-rahul-tiwaridhanashri027dhanashri027mukarthikmukarthikblue-rigelblue-rigelmguyromellemguyromellebharathikarunanithibharathikarunanithicn_priyanka14cn_priyanka14mehulpirukamehulpirukakishor-kumar07kishor-kumar07ngsangeetangsangeetaprashant_singhpariharprashant_singhpariharsnehaksnehakshrutiniveditashrutiniveditasandhya_ranisandhya_ranicedric_mascarenhascedric_mascarenhasm-mallikarjunam-mallikarjunaimran-condeimran-condesmantricondesmantricondemachelslackatcondenastmachelslackatcondenastsachin-nssachin-nsjorge_guerra2jorge_guerra2pratima_cnpratima_cnharsha_mahadevaiahharsha_mahadevaiahricha_cnricha_cnkarthik_cnkarthik_cnmuthuprakashvelumanimuthuprakashvelumaniimleo_condeimleo_condeissanjanaissanjanaa-renaa-renacolin-alexacolin-alexabxh-io-cnbxh-io-cnbenknowlesnewsbenknowlesnewstimklimowicztimklimowiczramkunramkunkamal_condekamal_condeaditijhacnaditijhacnnamansingh_bhandarinamansingh_bhandarimax-prinmax-princnarkhedecnarkhedenrajeshnpmnrajeshnpmvinothkumar_balavinothkumar_balaaksingh5aksingh5shashank_jaiswalshashank_jaiswalsaicharan7766saicharan7766vineethdvineethdhebsibal_selvarajhebsibal_selvarajakeshavamurthyakeshavamurthypriyanka_jhapriyanka_jhasaniyashksaniyashkjbs-cnjbs-cngargi-cgargi-chippolinhippolinklnarayananklnarayanancn_joy_sencn_joy_sencn-andrescn-andresganavi_jganavi_jsellapandi1998sellapandi1998jsharma-cnjsharma-cnspoorthi.chandrashekarspoorthi.chandrashekarvenkatesh547venkatesh547dinakar25dinakar25hegdemhegdemerikvelanderikvelandasinghcondeasinghcondejoselee43joselee43eunianinaeunianinagchaithragchaithrapatternwisepatternwiseomar.wlomar.wlandrixbandrixbraxsraxsvivekansvivekanssusel_retanasusel_retanapraveenppkpraveenppkrafalpucherafalpucheconde_jodeconde_jodesubbiah_ramakrishnasubbiah_ramakrishnafernandolara23fernandolara23sarahshincnsarahshincnjordi.escudejordi.escudennasirovnnasirovunnatikunnatiktania.delatorretania.delatorrevinayashreeramvinayashreerammohitsharma-newsmohitsharma-newsaaaantiaaaantipsundarpsundarwljoelwljoelarhovalearhovalesgdurhamsgdurhamfsanchezvilelafsanchezvilelaalfonsocondenastalfonsocondenastrashmicnrashmicnslarty667slarty667christinaharachristinaharananjacnnanjacnsiddhu-23siddhu-23atp-engineeringatp-engineeringkatiasfihikatiasfihiluisenriquegutierrezluisenriquegutierrezakhil_npm_condenastakhil_npm_condenastdanj-cndanj-cnsudeshna_cnsudeshna_cnvikash_cnvikash_cnlakshmi.priyalakshmi.priyasumanth_cnsumanth_cnshahu_cnshahu_cnutsav_cnutsav_cnmmorris9mmorris9maila-labibmaila-labibmala-shanbhagmala-shanbhaganilc93anilc93lavishgambhirlavishgambhirvmanzanillavmanzanillatdscondenasttdscondenastnitish-tandianitish-tandiamurali-condenastmurali-condenastalejandroaltf4devalejandroaltf4devomsun22omsun22ksriniva2ksriniva2aleccuster_cnaleccuster_cnandregcabandregcabbhoopaltbhoopaltniclasborkniclasborkpramita21pramita21tchathurtchathurkangkanborakangkanborasuhas-cnsuhas-cnvinay-prvinay-prrjcnrjcnvikramchowdary_parimivikramchowdary_parimisugumarvsugumarvjosephrussell-cnjosephrussell-cnseking31seking31eliza.nieveseliza.nievesanaedzmanaedzmnaveen1601naveen1601kajal-sikkakajal-sikkacn-connorbrannigancn-connorbranniganprajwal_keshavprajwal_keshavarjunpaarjunpasharique10sharique10babincondenastbabincondenastcn-oramirezcn-oramirezguru05111984guru05111984subinjoecondesubinjoecondeedisteledistelsaahithisrisaahithisribalar20balar20s_dwivedis_dwivedinhrqznhrqzmonicarmonicarrichsanchorichsanchotanya-sahtanya-sahcn_jenkinscn_jenkinsfrandevinneyfrandevinneyrenovaterenovatejyoti_3009jyoti_3009r0r71zr0r71zjaemegajaemegaaman-shinde-07aman-shinde-07condenastadmincondenastadminangrymongooseangrymongoosecopilot-robotcopilot-robotcry4dawn_2000cry4dawn_2000fennen529fennen529fmadriefmadriegkiliangkiliangmedinagmedinabigzedbigzedraagul-conderaagul-condestanstanstanleystanleyandi.anderson522andi.anderson522tamal_banerjeetamal_banerjeedavidkofahldavidkofahlbikubikutaniabhullartaniabhullardkorenblyumdkorenblyumtollmanztollmanzamalamchtalamalamchtaltdshaptdshapnidhi-tcsnidhi-tcsrishutcsrishutcssayeedcnsayeedcnpitchfork-devpitchfork-devdanhallerdanhallerrajasinghcondenastrajasinghcondenastderrickatcnderrickatcntcetcelboylanlboylancnid_engineeringcnid_engineeringlilyhealeylilyhealeyvarun9110varun9110megrymomegrymoprajaktakprajaktakmanthanbhoslemanthanbhoslerutujavetalrutujavetalniharanilniharanilpsharma2psharma2bhumikakhatribhumikakhatrisarthak_mohantysarthak_mohantyigostuigosturajashreearvikar19rajashreearvikar19tobe998tobe998cwoldtcwoldtndindinishkalanishkalasahana2104sahana2104mladhanemladhanemtzhangmtzhangmanthanrautmanthanrautjfrederick12jfrederick12rajashree-devarajrajashree-devarajsdcondesdconderigelsongrigelsongdrosenbaumdrosenbaumroopeshrknroopeshrknaswani_guptaaswani_guptagarryyaogarryyaocharuagrawalcharuagrawalsabarni-condenastsabarni-condenastyakshitayakshitakalyanikasarkalyanikasartalk2rajeevtalk2rajeevshreyapashreyapastefanpennerstefanpennernatelawscnnatelawscnbbuibbuialexlialexlibrian_mathewsbrian_mathewscrmartincrmartinleahzxxzleahzxxzhmehta06hmehta06srigurutcssrigurutcshusherichusherickatemontkatemonteddlestoneddlestonrttrtteshnoeshnojcorcinojcorcinoanwaukonianwaukonirichardsjustindrichardsjustindeduardoveraseduardoverasmrgentaxmrgentaxthehiddenhakuthehiddenhakucl4mcl4mspollinispollinifedeavafedeavasasha04sasha04guidop91guidop91gostfieldgostfieldnithya10nithya10satnam_gandhisatnam_gandhiabigaild45abigaild45mb_devmb_devrmohammarmohammaemilyatkemilyatkasolovyevasolovyevvaishnavisenthilvelvaishnavisenthilvelstefano-sariolistefano-sariolisarah-chekfasarah-chekfaluis_gomezluis_gomezdanielbaldwindanielbaldwinkarmennkarmennkhiaraortizkhiaraortizdmitriy_komarov-cndmitriy_komarov-cnjhrauejhrauesviatoslav_maslovsviatoslav_maslovhcethcetjmcamachojmcamachoishita_tiwariishita_tiwarisanjana_ssanjana_shariprasath_cnhariprasath_cnharinikirubaharinikirubacondenastfrcondenastfriamsuneethiamsuneethsuhitrathi-condenastsuhitrathi-condenastzeeshan-wanizeeshan-waniimakshathimakshathsrikanthnssrikanthnsmitchellstewartmitchellstewartpushp-1992pushp-1992anoopk-cnanoopk-cnmithunsathyanmitsmithunsathyanmitssurbhi_cnsurbhi_cnvikasshettyvikasshettymidhunmurali001midhunmurali001sudiptacondenastsudiptacondenastsalvador-ahumadasalvador-ahumadasuba56suba56skt-devskt-devganeshncaganeshncabelal_kazmibelal_kazmirszmacinskirszmacinskiprakashn37prakashn37utkarsh_sanjivan-condeutkarsh_sanjivan-condemallicamallicashobithshobithrashmi-raorashmi-raosahoo.sandhyasahoo.sandhyasardendusardenduagururajanagururajanskumariskumarisikindar_mirzasikindar_mirzaankitkumar02ankitkumar02avinash_iitbavinash_iitbupenpangingupenpangingspelurispelurianubalakrishnananubalakrishnansbhattacsbhattacrjain198rjain198ashwini_upparashwini_upparpmasadepmasadejbergdoljbergdolsuresharamsuresharamvnallasavnallasadhanraj_cndhanraj_cnpratik-guptapratik-guptaanita-yanita-yarvipandeyarvipandeysandesh4777sandesh4777vishnusimvisfearvishnusimvisfearilankumaranilankumaransamtiffinsamtiffinharsha-condenastharsha-condenastadityaanand534adityaanand534rkamblerkamblechandan-condenastchandan-condenastpratham7674pratham7674alokreddycnalokreddycnanurag-cnanurag-cnodtoribioodtoribiopranjal_sharma306500pranjal_sharma306500vijayalakshmi-sunagarvijayalakshmi-sunagarhelena-onghelena-ongnamankumarsinhanamankumarsinhagrannitsejdiugrannitsejdiurkharecondenastrkharecondenastsumitmaurya21sumitmaurya21pashokapashokashubham_condenastshubham_condenastsourav_condenastsourav_condenasttanmoy_condenasttanmoy_condenastnidhiarya-condenastnidhiarya-condenastvmehrotrvmehrotrsmita2022smita2022pariharcondenastpariharcondenastsubiabresubiabresnehadgsnehadgsourav909sourav909surabhidesaisurabhidesaisyed_faizansyed_faizanraveena-ramraveena-ramstatavarstatavarjatinbabbarcondenastjatinbabbarcondenastankushvijay93ankushvijay93likhitalikhitaindu-sagiindu-sagijakir-coderjakir-coderpriyankanandipriyankanandinikhilcondenastnikhilcondenaststahirahstahirahsparganiha-cnsparganiha-cnaswanth_condenastaswanth_condenastvinay_kumarvinay_kumarrajeswari-cnrajeswari-cnsoumyagundusoumyagunducnrahulrkrcnrahulrkrramya-cnramya-cndikshita_khandkedikshita_khandkesomsekhardashsomsekhardashambay_chaurasiaambay_chaurasiamanikandancnmanikandancnrghvndr99rghvndr99shubhamkheracnshubhamkheracnakhil_pashamakhil_pashammulla2mulla2spandey10spandey10srawat-cnsrawat-cn

Readme

Quick Bus 🚌

A tiny event bus with AMQP and Postal.js-like functionality meant to be used on the client-side.

license

Proudly built by:

What is it?

This is a simple event bus that replicates the basics of Postal.js in about 80 lines of code (minified to 773 bytes)

It doesn't use lists of regex like Postal does but uses a directed graph instead, which is much faster.

It adds a history for automatic metrics collection, which brings the line count to about 150 lines of code (minified to 1258 bytes)

It has no dependencies.

How to use

Use the emit and on methods, just like a regular event emitter.

var channel = new Bus();

channel.on('metrics.#', function (msg) {
  console.log(msg);
});

channel.emit('metrics.page.loaded', 'hello world');

In imitation of Postal.js, use the returned function to stop the events.

var off = channel.on('page.load.justOnce', function (msg) {
  console.log(msg);
  off();
});

Also in imitation of Postal.js, use the second parameter to get the topic that triggered the event.

var off = channel.on('page.ad.*.filled', function (msg, meta) {
  console.log(meta.topic + 'just happened');
});

If you like the pub/sub model better, we've aliased subscribe and publish as well:

var channel = new Bus();

channel.subscribe('metrics.#', function (msg) {
  console.log(msg);
});

channel.publish('metrics.page.loaded', 'hello world');

And of course to unsubscribe, use the returned function:

var unsubscribe = channel.subscribe('#', function (msg) {
  console.log(Date.now(), msg);
});

for (var i = 0; i < 10; i++) {
  channel.publish('welcome.' + i, 'hello world!');
}

unsubscribe();

How it works

A Bus builds a directed graph of subscriptions. As event topics are published, the graph discovers all the subscribers to notify and then caches the results for faster message publishing in the future. When a new subscriber is added, the graph is modified and the subscriber cache is reset.

Wildcard subscriptions

Supports same wildcards as Postal.js, such as:

Zero or more words using #

channel.subscribe('#.changed', function (msg) {
  // ...
});
channel.emit('what.has.changed', event);
channel.subscribe('metrics.#.changed', function (msg) {
  // ...
});
channel.emit('metrics.something.important.has.changed', event);

Single word using *

channel.subscribe('ads.slot.*.filled', function (msg) {
  // ...
});
channel.emit('ads.slot.post-nav.filled', {data, msg});

History

We keep a history of the events that have been emitted. They can be queried with the history method:

var channel = new Bus();

channel.emit('ads.slot.post-nav.filled', {data, msg});
channel.emit('ads.slot.side-rail.filled', {thing, stuff});
channel.emit('ads.slot.instream-banner-0.filled', {a, b});
channel.emit('metrics.component.absdf2324.render.start', {etc, ie});
channel.emit('metrics.component.absdf2324.render.end', {etc, ie});

// gets the ad slots that were filled
var history = channel.history('ads.slot.*.filled');

// gets history of components rendering
var history = channel.history('metrics.component.*.render.*');

The format is an array of arrays. For example:

[
  ["ads.slot.post-nav.filled", 1515714470550],
  ["ads.slot.side-rail.filled", 1515714470559],
  ["ads.slot.instream-banner-0.filled", 1515714500268],
  ["metrics.component.absdf2324.render.start", 1515714782584],
  ["metrics.component.absdf2324.render.end", 1515714790507],
]

Only the topic and the timestamp of each event is stored. We don't store the message/payload in the history to prevent potential memory leaks and scoping issues.

These events are stored in a ring buffer, so old events will be dropped from the history once it reaches a certain size. The history size is current set to a maximum of 9999 events.

Note that this feature is designed for metrics, and often the information that people are interested in for metrics can be included as part of the topic. For example, if you have a subscriber of on('components.*.render.start'), then you can have an infinite number of component ids such as emit('components.abcdef.render.start') and emit('components.someRandomId.render.start') without any additional complexity or performance penalty to the event bus. If you're trying to access more information that can't be included as part of the topic, then you should make a subscriber and log that information.

Look at our Examples Page for some common code patterns with event buses.

To Do

  • Determine if the "meta" field from Postal.js should be included, or if that's just weight that the Promise API hates
  • Should we expose timing information or the ids of messages?
  • Would an async mechanism that would collect, buffer, or throttle messages be useful? Would an event queue be used?
  • Are there other features of Postal that we actually use?

Future / Related architecture

  • Create helper library specialized in producing events from React
  • Create library to link into Browser events (Boomerang)
  • Create library to collect events and forward them to servers such as Sparrow, GA or BoomCatch.

Related Documents

Related Topics