M
M
Michael2017-05-31 17:52:22
JavaScript
Michael, 2017-05-31 17:52:22

How to implement the mediator pattern in this case?

I have three independent modules: working with Redis, working with a database and working with a telegram bot. I want to connect them with each other using the mediator pattern and I don’t quite understand how to do it correctly.
The bot receives a message from the user, and I need to:
1) write data to the database ( db.save(data, table))
2) write data to Redis ( redis.saveSession(id, level))
3) reply to the user ( ) And how to do this? The standard option is not suitable, since you need to pass three different functions that take a different number of input parametersapp.sendMessage(id, 'text')

const mediator = new Mediator();
mediator.on('event', someFunc); //не подходит

So how to be? Pass an array of functions? Or am I doing something wrong at all?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas, 2017-05-31
@mak_ufo

The mediator didn’t rest on you here at all. Some sort of command/middleware pipeline would do.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question