Skip to content

Modularized TEA structure #58

@paulstadler

Description

@paulstadler

Hi there,

Amazing work in this package. I'm trying to scale it to a SPA here. Initial goals are:

  • Each page contains it's own micro-TEA (msg's, init, update, view)
  • Top-level router that pushes to the right page/layout based on state and/or message type

I think this will help contain changes - it's also what folks in elm-land are doing. So I'm thinking along those lines.

The challenge I'm having is that the messages coming back from each page aren't able to map back up to a global message type.

When messages are attached to an action in the view function, they seem to translate to a JS tag that's typeless and gets unintentionally casted when it comes back in update.

I've tried to solve with something like this:

let view = (m: model): Vdom.t<msg> => {
  let pageView = switch m.path {
  | "/home" => Vdom.map(a => HomeMsg(a), Home.view(m.home))
  | "/payments" => {
    let v = Payments.view(m.payments)
    Js.log("pre map")
    Js.log(v)
    Vdom.map(a => PaymentsMsg(a), v)
  }
  //| "/events" => Vdom.map((a: CoreEvents.msg): msg => CoreEvents(a), CoreEvents.view(CoreEvents.init()))
  | _ => text("undef route: " ++ m.path)
  }

... and that compiles fine. However, the events don't actually get mapped to the correct msg type.

Please forgive me if the solution is obvious -- I'm new to rescript! (Loving it btw...)

I've dug in vdom.res pretty substantially and understand that it's wrapping taggers in there etc.

Would it be possible to show an example of how to handle messages that are variants of msg types in other modules? I'm looking for something like this:

type msg =
  | AppBarMsg(AppBar.msg)
  | HomeMsg(Home.msg)
  | PaymentsMsg(Payments.msg)
  | CoreEventsMsg(CoreEvents.msg)
  | LocationChange(string)

at the top level.

If there were a function in the tea library to help with this it would be most beneficial!

Thanks so much!
Paul

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions