Nested components and access to global data in Elm

I have an elm application designed with elm architecture in mind. I used it for all the samples in the tutorial and they work great. I have the following components

  • ContainerListView
  • Containerview
  • Addressview
  • RegistrationView
  • ...

The ContainerView component is a very formatted div structure that is used to store other views (but so far only one at a time)

ContainerListView can contain multiple containers. He handles their presentation and positioning. You can think of it as an MDI surface

The menu from the main ui is used to add new container views to the container watch list.

I am presented with three main questions. Two of them are

  • How to create such components so that the container view can contain any other element, I pass, for example, the init, update and view functions and expect all things to be connected correctly? At the moment, the samle looks that I have have been hard-coded. They know exactly who the children are.

  • Some components require access to things like url, access token, etc. Should it always be passed from main to the individual components, or can it come from another source, which will essentially be read-only and possibly updated only from the main?

I am not sure that these two questions should be individual. Any information on how to architect larger applications with a welcome world will also be appreciated.

+5
source share
1 answer

I'm working on something similar! Nested controls. I also have a container object that knows about all the types that it can handle, and has basically case instructions for processing each type. Therefore, I can’t refuse the new type of control and expect that it will handle it, which requires a change in the container.

As far as I know, elm does not have type classes, and I would try to process this abstraction in haskell or purescript. There is more about this:

https://github.com/elm-lang/elm-compiler/issues/38

and here:

https://github.com/elm-lang/elm-compiler/issues/1039

It seems that the problem is that they do not know how they want to solve this problem, so they did not.

+1
source

Source: https://habr.com/ru/post/1240840/


All Articles