JS Events

Communication between different parts of the application is necessary sometimes. For instance, when a user interacts with a button and somewhere else, the application must callback, in terms of displaying some result.

Javascript provides the Event API to deal with such casuistics, but it's always a good practice to gather all the application events in order to track/reuse/refactor/remove them.

That file is app/javascript/lib/events/index.js. The events are arranged by the different modules.


export const GOBIERTO_DASHBOARDS = {
  CREATE: "create-dashboard-maker",
  // rest of the module declared events...
// another module events...
export const GOBIERTO_MODULE....


// emitter
import { GOBIERTO_DASHBOARDS } from "lib/events"
const event = new Event(GOBIERTO_DASHBOARDS.CREATE)
// listener
import { GOBIERTO_DASHBOARDS } from "lib/events"
document.addEventListener(GOBIERTO_DASHBOARDS.CREATE, callback)