Hi everyone,

Last week I coded a NATS [1] client, which is a PUB/SUB messaging
system, in Elm [2]. It was very instructive and the result is pretty
satisfying so far.

Along the way I learned a few things that might be of use for others
wanting to do this kind of client.

* The WebSocket API is a little short for this use-case:
  - we need an API for being informed when the connection is
    opened/closed.
  - it lacks an API for sending ordered messages. It could be
    Task-based, allowing to interrupt it one of the send fails,
    or it could be a "sendAll" Cmd that takes a list of messages
    to send.

  Both this issues were fortunately worked-around in my case, but it
  is only because the protocol allowed it. Others may not be so lucky.

* Using an effect module is not mandatory...

* ... but I had to mimick Cmd and Sub, which adds a lot of boilerplate
  for the user (see the project README)

* not being an effect module has clear pros :
  - we can rely on other effect modules (in my case: WebSocket and
    Random)
  - Implementation is somehow easier, and more friendly to maintain
  - The module can be published on package.elm-lang.org

* Being an effect module would allow a much simpler and natural API.
  But then we could not use WebSocket or Random


Finally, I would like to discuss a notion of middleware (which I think
is what I did with elm-nats):

We could simplify the API as much as with an effect module if we could
manipulate the Cmd and Sub.

I suspect that being able to filter a Cmd to extract all Cmd of a given
type in it would permit to implement some kind of middleware component.
Such a component would be explicitely inserted by the user between its
program and its TEA entry points.

It could define some custom Cmd and Sub, and would transform them to
other effect modules commands and subs just before returning them to the
program.

Has anything like this been attempted already?

Am I making any sense?


Best regards,

Christophe

[1] https://nats.io
[2] https://github.com/orus-io/elm-nats

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to