2020-05-29 07:20:03 +12:00
|
|
|
const EventEmitter = require("events").EventEmitter
|
2020-12-08 06:23:53 +13:00
|
|
|
const { rowEmission, tableEmission } = require("./utils")
|
2020-05-25 09:54:08 +12:00
|
|
|
|
2020-09-11 02:00:21 +12:00
|
|
|
/**
|
|
|
|
* keeping event emitter in one central location as it might be used for things other than
|
2020-09-22 00:49:34 +12:00
|
|
|
* automations (what it was for originally) - having a central emitter will be useful in the
|
2020-09-11 02:00:21 +12:00
|
|
|
* future.
|
|
|
|
*/
|
2020-06-01 04:12:52 +12:00
|
|
|
|
2020-09-26 05:05:26 +12:00
|
|
|
/**
|
|
|
|
* Extending the standard emitter to some syntactic sugar and standardisation to the emitted event.
|
2021-01-16 03:38:10 +13:00
|
|
|
* This is specifically quite important for handlebars used in automations.
|
2020-09-26 05:05:26 +12:00
|
|
|
*/
|
|
|
|
class BudibaseEmitter extends EventEmitter {
|
2020-10-29 23:28:27 +13:00
|
|
|
emitRow(eventName, appId, row, table = null) {
|
2020-12-08 06:23:53 +13:00
|
|
|
rowEmission({ emitter: this, eventName, appId, row, table })
|
2020-09-26 05:05:26 +12:00
|
|
|
}
|
|
|
|
|
2020-10-29 23:28:27 +13:00
|
|
|
emitTable(eventName, appId, table = null) {
|
2020-12-08 06:23:53 +13:00
|
|
|
tableEmission({ emitter: this, eventName, appId, table })
|
2020-09-26 05:05:26 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const emitter = new BudibaseEmitter()
|
2020-06-01 04:12:52 +12:00
|
|
|
|
|
|
|
module.exports = emitter
|