Developing the Polyglot agent
As we have discussed earlier, the job of the Polyglot agent is to find out the changes in the table and then generate an event for the synchronization process.
For finding out the changes in the table, we already have the changefeed by RethinkDB, and for generating events, we can use the inbuilt EventEmitter
class by Node.js.
The event emitter is the class in the Node.js; thus, to use it we need to inherit all the functions and property in our class. We can do this by using the following code:
const events = require('events'); class Polyglot extends events { constructor() { super(); } } module.exports = Polyglot;
Here we are using the ES6 extends
keyword to perform the inheritance. In our constructor, we are calling the super()
method to call the parent constructor, that is, the constructor of the event class.
Next, we need to assign a changefeed to our table and listen for the change. If there is a change in any of the data, we need to determine...