Is it possible to use multiple Models(State) in Elm

Hello community.
I want to find some resources for scaling elm application, but had not much time about it.
In a SPA (single page application) the app is separated into multiple views. Then it must have some global state and some local?

In the use case, e.x. i want to have two tabs, to choose between them i want a helper function and not a global state. How can this be achieved.

Resources are welcome.

I do not want to have a global model (used with modules in js) for all instances.

There is just one Model at the top level, but you can compose it of many smaller models. (A model is just a piece of data.)

It sounds like you’re looking for something like this:

type alias Model =
  { tab1 : Tab1.Model
  , tab2 : Tab2.Model
  , currentTab : Tab
  , shared : SharedStuff
  }

type Tab
  = Tab1
  | Tab2

Or, if you want the tabs to reset when you switch between them:

type alias Model =
  { currentTab : Tab
  , shared : SharedStuff
  }

type Tab
  = Tab1 Tab1.Model
  | Tab2 Tab2.Model
1 Like

lydell, You mentioned there’s just one model, so you might answer my question as well, I wonder if is it possible or advisable to have two or more models in the same application, each one of them dealing its own thing and updating its own properties without interfering with another model?

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.