# Loading Data into an Editor with additional state

**URL:** <https://discourse.elm-lang.org/t/loading-data-into-an-editor-with-additional-state/2898>\
**Category:** Request Feedback\
**Created:** [January 7, 2019, 7:44am UTC](https://discourse.elm-lang.org/t/loading-data-into-an-editor-with-additional-state/2898 "2019-01-07T07:44:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![FranzSkuffka](https://avatars.discourse-cdn.com/v4/letter/f/c4cdca/32.png) [@FranzSkuffka](https://discourse.elm-lang.org/u/FranzSkuffka)\
**Post date:** [January 7, 2019, 7:44am UTC](https://discourse.elm-lang.org/t/loading-data-into-an-editor-with-additional-state/2898/1 "2019-01-07T07:44:00Z")

</div>

Hey there fellows. Lovely Monday to you all.

I need your feedback.

Currently I am developing an editor that edits some data which is stored in some sort of database (which is synced with the backend) while having its own local helper state. The database can be modeled as a `Dict comparable EditableDataStructure`. Which element from the `Dict` is used is determined by the `Url` the user currently visits.

It is important to note that the `Editor` has its own `EditorState` which holds things like an `UndoList` or an `Html5.DragDrop.Model` which obviously not need to be saved in the `EditableDataStructure`.

There are quite a few issues with this problem:

- Loading vs Referencing: When navigating to a Url I can either load the `EditableDataStructure` from my `Dict` into the `EditorModel` or just reference the `comparable`.
  - Advantages of loading:
    - It avoids mapping over `Maybe` for each update
    - The data is right there and slightly more performant to operate on

  - Disadvantages of loading (that referencing does not have)
    - The loaded and the persisted data may get out of sync.
    - It violates the ‘single source of truth’ principle in elm

- Tracking `saved` state. How does the editor ensure that the state currently loaded is already persisted without making complex comparisons to the synced DB? Avoid syncing local and remote DB alltogether?

Did anyone here tackle a similar problem before?

Thank you for your feedback.

---

<div class="post-metadata">

**Author:** ![brasilikum](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/brasilikum/32/524_2.png) [@brasilikum](https://discourse.elm-lang.org/u/brasilikum)\
**Post date:** [January 7, 2019, 3:41pm UTC](https://discourse.elm-lang.org/t/loading-data-into-an-editor-with-additional-state/2898/2 "2019-01-07T15:41:48Z")

</div>

I think the disadvantages of loading far outweigh the advantages here. Are you sure the performance is relevant for your usecase?

In case you have not seen it yet, maybe this talk by Richard can give you some more ideas:  
Immutable Relational Data

---

<div class="post-metadata">

**Author:** ![FranzSkuffka](https://avatars.discourse-cdn.com/v4/letter/f/c4cdca/32.png) [@FranzSkuffka](https://discourse.elm-lang.org/u/FranzSkuffka)\
**Post date:** [January 8, 2019, 10:09pm UTC](https://discourse.elm-lang.org/t/loading-data-into-an-editor-with-additional-state/2898/3 "2019-01-08T22:09:27Z")

</div>

Thank you! I refactored the app right after and it’s a lot more maintainable now.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [January 18, 2019, 10:09pm UTC](https://discourse.elm-lang.org/t/loading-data-into-an-editor-with-additional-state/2898/4 "2019-01-18T22:09:27Z")

</div>

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