OlivierBlanvillain / monadic-html

Tiny DOM binding library for Scala.js
https://olivierblanvillain.github.io/monadic-html/examples/
MIT License
225 stars 24 forks source link

Standardize router solution #55

Open OlivierBlanvillain opened 7 years ago

OlivierBlanvillain commented 7 years ago

The mini website showing the example has keeps a bijection between URL and active example, it's a bit of a crude implementation but it works. There is definitely room for standardization here, and unlike the FutureRx thing, router require non trivial amount of engineering.

bbarker commented 7 years ago

I've been working on a simple Router (referenced in #77), which may be good enough for me (and may not be also - we shall see). Which router implementation are you referring to when you say FutureRx (assuming there's a concrete example somewhere that I missed)?

I sort of like how this style of router (which can likely be simplified) can easily be plugged into a component (see below), since it has its own isolated view. The component's view just becomes the router's view, so the router is simply used as a light formalism. Not much to it - monadic-html does all the hard work.

Components are also a fairly light formalism, for example:

  sealed abstract class AbstractComponent[D](view: Node, model: Rx[D])
  case class Component[D](view: Node, model: Rx[D]) extends AbstractComponent[D](view, model)

  /**
    * TaggedComponent is useful for updating a collection of components where one would want to
    * sometimes alter Component[D] based on input data of type T
    */
  case class TaggedComponent[D,T](view: Node, model: Rx[D], tag: T) extends AbstractComponent[D](view, model)