This is an article in a series of articles. An overview of the entire project can be found here.
Until now I have focused on Fibonacci as a function of some input. I have defined a function which returns a value when supplied an argument. This yield a batch processing paradigm. However, the Fibonacci is defined as a series, and as such it makes sense to treat it as a series.
When this function is called it will emit a new event every time a
Fibonacci number has been calculated. But this does not work by itself. We
also need something to consume it. Following is a function that consume the
events and prints a
. on the screen. When we hit n = 10 we write the
corresponding element in the Fibonacci series.
When running the file through node we get following:
As usual, the code is available here.
So what about the Events? When programming user interfaces the interface usually stands still until a button is pressed or an input field is filled. Here the subsystem fires some events whenever something meaningful is happening. It is then possible to add functions to be called on these events.
This approach has been in use for a long time. But has certain disadvantages when working on large systems. It quickly becomes messy when too many events are to be handled and dispatched. But certain solutions already do exists. Later on, we will take a look at Elm, Here we model the complete application and let the system handle what part of the web page is updated. And don’t matter. It is fast.