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