Skip to content
Flupsi edited this page Nov 17, 2022 · 4 revisions

Backend and Sync

Database

see Firebase Console

Synchronisation

The admin edits data. A service updates the database according to the edits. The visitors download the latest data from the database. We have some design considerations to inform the implementation:

  • What if the admin uses two tabs or two devices simultaneously?
    • (a) The latest save overrides everything
    • (b) Edits are accumulated from all sources in the order they arrive at the database
    • (c) Offline-first: Edits are intelligently merged when the admin goes online; otherwise local storage has a working draft.
  • Does Elm need to inspect the edits?
    • (1) If no, we just render a sync-hypertext element that handles database synchronisation at its leaf.
    • (2) If yes, we are collecting edits in the global update loop and push them via a singleton append-log element.

Preset articles are not synced. Custom articles are stored in plain Html, indexed by unique id. Every edit is immediately synced. The last overwrite 'wins' (a).

(1) Body sync (a)

Segment.view =
   ...
   Html.node "sync-hypertext"

See sync-hypertext in append-log.js

(2) Article sync (b)

type alias Article =
    { id : String
    , caption : { text : String, showsDate : Bool }
    , info : Maybe InfoChoice
    , body : BodyChoice
    , shape : Shape
    , fab : Maybe Fab
    , additionalClasses : List String
    }

This record can be edited with controls. Each individual edit generates an Action:

type Article.Action
    = WithCaption { text : String, showsDate : Bool }
    | WithInfo (Maybe InfoChoice)
    | WithBody BodyChoice
    | WithShape Shape
    | WithFab (Maybe Fab)
    | WithClasses (List String)

These Actions are encoded and stored in a history list. With Undo and Redo, you can reorder it.

The History is accumulated at the level of the Accordion.elm and interwoven with its Actions:

type Accordion.Action
    = Name String
    | Modify Article.Action
    | Go Direction
    | Insert Direction
    | Delete
    | Reset String
    | Undo IntentId

On loading the page, all actions are replayed to recreate the initial state before rendering the Accordion.

Conceptual flow

Articles and the Accordion are orthogonal to each other. One can imagine to load a different set of Articles or a different data-type than the Accordion loading Articles. They are connected by unique ids.

Problem: id impermanence.

Perhaps a functionality rename would be useful: renaming an article hypertext HTML. Need Workflow design.