Event Emitter

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 Ark Core node. While Ark Core uses eventemitter3 to utilize fully asynchronous event handling, the eventemitter3 API mirrors that of NodeJS's Event API, allowing Node developers to build Ark packages using familiar and extensible conventions.

Behind the Scenes

Events are used inside Ark 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, Ark events are strictly reactionary. In other words, Ark 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, Ark Core packages can act both as publishers and subscribers of events.

The list of events published by Ark Core packages can be found in core-blockchain's getEvents method:

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: 12/7/2018, 1:31:47 AM