Event Emitter

You are here:
< Back

Installation

yarn add @arkecosystem/core-event-emitter

Alias

event-emitter

Implementation

core-event-emitter

Notable Dependencies

Summary

core-event-emitter wraps around NodeJS’s native Event class to provide event functionality across an Qredit Core node. While Qredit Core uses eventemitter3 to utilize fully asynchronous event handling, the eventemitter3 API mirrors that of NodeJS’s Event API, allowing Node developers to build Qredit packages using familiar and extensible conventions.

Behind the Scenes

Events are used inside Qredit Core to trigger blockchain actions and the delivery of webhook payloads. Additionally, custom plugins can utilize the event emitter package to trigger their own actions in response to blockchain events.

Conceptually, this feature is similar to the Hooks implementation in WordPress, as well as to the lifecycle hook access provided by JavaScript frameworks such as Vue and React. All of these systems expose The primary difference is that, because of the need for strict protocols around blockchain data creation and retrieval, Qredit events are strictly reactionary. In other words, Qredit Core events are not capable of changing data at runtime. The transaction.applied event, for instance, passes a complete transaction instance, not raw transaction data that can be altered in the style of a WordPress Filter.

Another way to think of the Event API is in the context of a publish-subscribe pattern. In this pattern, Qredit Core packages can act both as publishers and subscribers of events.

The list of events published by Qredit Core packages can be found in core-blockchain‘s getEventsmethod:

getEvents() {
  return [
    'block.applied',
    'block.forged',
    'block.reverted',
    'delegate.registered',
    'delegate.resigned',
    'forger.failed',
    'forger.missing',
    'forger.started',
    'peer.added',
    'peer.removed',
    'round.created',
    'state:started',
    'transaction.applied',
    'transaction.expired',
    'transaction.forged',
    'transaction.reverted',
    'wallet.saved',
    'wallet.created.cold',
  ]
}

 

Last Updated On January 26, 2019