We still have our app working here with a timer. It has two parts. It has logic and effects. We need to give some structure to this. It's not generic at the moment. For instance, it only supports one type of effect, which is writing to the DOM.
First, we need to make a function here to contain our logic. We can put our logic in a function called main, for instance. It's where our application lives, and it just returns the stream which is later subscribed to.
We can do something similar with the DOM effect. We can put that in a function called DOM driver. It takes the text stream as input, and it just subscribes to that text stream. Basically, our main is describing logic, and our DOM driver is describing how to perform an effect, given some data.
We need to call these functions in order to make something happen. First, we call main. That will create a stream. We're going to give that name, sink. Then I'm going to pass sink to the DOM driver, like this. Then it's going to work just like before, nothing really fundamentally changed.
Why did I call it a sink? It's because it's a destination. Just like in a kitchen sink, it's where water goes to, and it doesn't come back. Here, we have our logic or data is going to this return value. It's going to this sink, and it's not coming back. That's the idea behind it.
We have some structure now, but let's say we want to have more types of effects, such as for instance, we want to make a console log effect. We just need to do a similar type of function here. We can call that the log driver.
It takes a message stream as input, and we can just subscribe to that. Then every time we get a message, we can put that in the console like that. Then we just need to also pass the sink to the log driver.
Now, let's run this and see if it works. We need to open the console, and there we see both of the types of effects happening at the same time. The DOM is being written, and the console is being written as well.
In general, you want to put each effect in a different driver, and these are separated from your application.