All Projects → NickNaso → hertzy

NickNaso / hertzy

Licence: Apache-2.0 license
Event bus channel

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to hertzy

e
A library which combines a eventBus/emitter, DOM events management, delegated events, and event-based utils into a single lightweight and performant library.
Stars: ✭ 37 (-22.92%)
Mutual labels:  events, eventbus
Alpine
Basic event system framework using functional interfaces
Stars: ✭ 79 (+64.58%)
Mutual labels:  events, eventbus
LiteBus
LiteBus is an easy-to-use and ambitious in-process mediator providing the foundation to implement CQS. It is implemented with minimum reflection usage and streamable query support.
Stars: ✭ 20 (-58.33%)
Mutual labels:  eventbus, mediator
telephone-ts
Telephone-ts: The "Event Emitter-less" TypeScript Event Architecture.
Stars: ✭ 22 (-54.17%)
Mutual labels:  events, eventbus
use-bus
React hook to subscribe and dispatch events accros React components
Stars: ✭ 51 (+6.25%)
Mutual labels:  events, eventbus
evon
Fast and versatile event dispatcher code generator for Golang
Stars: ✭ 15 (-68.75%)
Mutual labels:  events, eventbus
Rabbitevents
Nuwber's events provide a simple observer implementation, allowing you to listen for various events that occur in your current and another application. For example, if you need to react to some event published from another API.
Stars: ✭ 84 (+75%)
Mutual labels:  events, eventbus
pg-pubsub
Reliable PostgreSQL LISTEN/NOTIFY with inter-process lock support
Stars: ✭ 50 (+4.17%)
Mutual labels:  events, eventbus
vertx-vue-keycloak
This repo holds the source codes for the Medium Article "Vert.x + VueJS + OAuth2 in 5 steps"
Stars: ✭ 20 (-58.33%)
Mutual labels:  eventbus
PoShLog
🔩 PoShLog is PowerShell cross-platform logging module. It allows you to log structured event data into console, file and much more places easily. It's built upon great C# logging library Serilog - https://serilog.net/
Stars: ✭ 108 (+125%)
Mutual labels:  events
CEventCenter
一个Android事件分发中心库,基于对象池及接口回调实现。实现类似BroadcastReceiver/RxBus/EventBus等的消息事件传递功能,用于在Activity/Fragment/Service之间的消息传递通讯。
Stars: ✭ 116 (+141.67%)
Mutual labels:  eventbus
dynamic-engine
Monitor events in the background on Android.
Stars: ✭ 24 (-50%)
Mutual labels:  events
public-speaking
🎤 List of presentation, volunteer and initiatives
Stars: ✭ 11 (-77.08%)
Mutual labels:  events
uevloop
A fast and lightweight event loop for embedded platforms.
Stars: ✭ 61 (+27.08%)
Mutual labels:  events
event-emitter
Event Emitter module for Nest framework (node.js) 🦋
Stars: ✭ 102 (+112.5%)
Mutual labels:  events
gancio
a shared agenda for local communities (with activitypub support)
Stars: ✭ 21 (-56.25%)
Mutual labels:  events
MASA.Contrib
The purpose of MASA.Contrib is based on MASA.BuildingBlocks to provide open, community driven reusable components for building mesh applications. These components will be used by the MASA Stack and MASA Labs projects.
Stars: ✭ 102 (+112.5%)
Mutual labels:  eventbus
site
Sources of euregjug.eu
Stars: ✭ 26 (-45.83%)
Mutual labels:  events
continuous-analytics-examples
A collection of examples of continuous analytics.
Stars: ✭ 17 (-64.58%)
Mutual labels:  events
sources-for-knative
VMware-related event sources for Knative.
Stars: ✭ 24 (-50%)
Mutual labels:  events

Hertzy - Event bus channel


Build Status Build status NPM version NPM downloads

Hertzy provides additional messaging pattern for Node.js applications.

Introduction

Node.js includes an event system which is an implementation of the Observer pattern that is the most common used event pattern in Node.js application and for good reasons: it's incredibly simple and useful.

Hertzy adds additional messaging related features called frequency that represent a communication bus through which different parts (modules) of the application can communicate with each other.

Motivations

Anyone who has used Node.js should be familiar with events. This module has the responsability to facilitate the communication between objects of your application.

Much of the Node.js core API modules are built around an idiomatic asynchronous event-driven architecture in which certains kinds of objects (called emitter) periodically emit named events that cause Function objects ("listeners") to be called.

Sometimes you need to promote loose coupling system by ensuring that instead of components (modules) referring to each other explicitly, their interaction is handled through a central point. This can help to decouple the systems and improve the module reusability.

In implementation terms Hertzy use the mediator pattern that is ideal for application level notifications such as the communication between different subsystems that are themselves complex.

The largest benefit of the mediator pattern is that it reduces the communication channels needed between objects or components in a system from many to many to just many to one.

Both pattern mediator and observer promote loose coupling, however, the mediator achieves this by having objects communicate strictly through it, while observer creates observable objects that publish events of interest of objects that are subscribed to them.

Installation

If you want to use hertzy you have to install it. There are two methods to do that:

In your package.json add the following item:

"hertzy": "version"

then digit:

npm install

Example:

"hertzy": "*" for the latest version
"hertzy": "0.0.1" for the version 0.0.1

OR

launch this command:

npm install hertzy --save

Usage

To start using hertzy you have to import it in you project. After that you need to obtain a frequency or create a new one. A frequency object is a channel where you can emit or listen for an event issued by other modules.

'use strict'

const Hertzy = require('hertzy')

// Obtain or create a new frequency, a channel where you can emit or listen for
// an event issued by other modules
const usr = Hertzy.tune('user')

// Listen for event 'user:add'
usr.on('user:add', function (data) {
    console.log('NEW USER ADDED WITH FOLLOWING DATA:')
    console.log(data)
})

// Emit event 'user:add'
usr.emit('user:add', {
    username: 'NickNaso',
    password: '********',
    email: '[email protected]'
})

Hertzy for browsers

To use Hertzy in the browser, please refer to this specific version.

API

VERSION

This is a String property that represents the version of hertzy

'use strict'

const Hertzy = require('hertzy')

// Get hertzy version and print it
console.log(Hertzy.VERSION)

WARNING

This is a Boolean property. Setting it to true will cause Node.js to print a warning if you add more then defaultMaxListeners listeners on a single event (for more informations about that take a look here event and max listeners number).

Otherwise setting it to false, which is also the default value for hertzy, the number of max listeners will be dynamically updated based on your usage.

'use strict'

const Hertzy = require('hertzy')

// Set hertzy warning value
// Get hertzy warning value and print it
console.log(Hertzy.WARNING = true)

tune (frequency)

The tune method returns a frequency that conceptually is a channel where you can emit or listen for an event and its data. The tune method checks if the parameter frequency is a valid String and creates or returns an instance of Frequency that you can use to intercept or dispatch the event using its methods.

'use strict'

const Hertzy = require('hertzy')

// Get frequency to use
const frequency = Hertzy.tune('user')

How to use Frequency

After you get the right frequency or the bus channel you want, you can start to emit and listen to the events with the methods exposed by Frequency object.

fq ()

The fq method returns the string representing the frequency's name

'use strict'

const Hertzy = require('hertzy')

// Get frequency to use
const frequency = Hertzy.tune('user')

console.log(frequency.fq())
// It prints the String 'user'

emit(evt, [, ...args])

The emit() method allows you to dispatch an event on a selected frequency. It takes as a required parameter evt. Others optional parameters will be passed to the listeners of the specified event. Remember, evt needs to be a valid String otherwise you will get an error.

'use strict'

const Hertzy = require('hertzy')

// Get frequency to use
const frequency = Hertzy.tune('user')

// Emit 'user:add' event on 'user' frequency
frequency.emit('user:add', {
    username: 'NickNaso',
    password: '********',
    email: '[email protected]'
})

on (evt, fn)

The on() method allows you to listen to an event on the selected frequency. It takes as input two parameters, evt and fn which represent the name of the event and the function handler you want to execute when the event happens. Remember, evt and fn need to be a valid String and Function respectively, otherwise you will get an error.

'use strict'

const Hertzy = require('hertzy')

// Get frequency to use
const frequency = Hertzy.tune('user')

// Listen 'user:add' event on 'user' frequency
frequency.on('user:add', function (data) {
    // DO SOMETHING ...
})

off (evt, fn)

The off() method allows you to remove listener on event on the selected frequency. It takes as input two parameters, evt and fn which represent the name of the event and the function handler you want to execute when the event happens. Remember, evt and fn need to be a valid String and Function respectively, otherwise you will get an error.

'use strict'

const Hertzy = require('hertzy')

// Get frequency to use
const frequency = Hertzy.tune('user')

const handler = function (data) {
    // DO SOMETHING ...
}

// Listen 'user:add' event on 'user' frequency
frequency.on('user:add', handler)

// Remove listener for 'user:add' event on 'user' frequency
frequency.off('user:add', handler)

Rererences and articles

Hertzy an event bus channel

The Team

Nicola Del Gobbo

https://github.com/NickNaso/

https://www.npmjs.com/~nicknaso

https://twitter.com/NickNaso

Mauro Doganieri

https://github.com/mauro-d

https://www.npmjs.com/~mauro-d

https://twitter.com/maurodoganieri

Pierluigi Iannarelli

https://github.com/pierluigiiannarelli

https://twitter.com/pierluigiiannar

Acknowledgements

Thank you to all people that encourage me every day.

Mantainers and creators of backbone.radio a module that has inspired my work on hertzy.

License

Licensed under Apache license V2

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].