Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tntmarket/eef674b604d5e081e46def812a5efeef to your computer and use it in GitHub Desktop.
Save tntmarket/eef674b604d5e081e46def812a5efeef to your computer and use it in GitHub Desktop.

Candidate data models for panels and focused blocks

Panel references vs. Numeric Indices

"Panel references" means we using a unique identifier to track which panel we've selected, whether that be the page name, an element reference, or a panel reference.

"Numeric indices" means we use an integer index.

Panel Owns Focused Block vs. Seperate Map

"Panel owns focused block" means the panel objects have internal state tracking which block is selected.

"Seperate map" means a seperate map associates panel ids with the focused block.

Use Cases

Syntax for use cases:

  • [pages open before] => [pages open after]
  • * means the page is focused

Opening a page

[Main*, PageA] => [Main*, PageB, PageA]

Panel references + Panel owns focused block

{
    focusedPanel: main,
    panels: [
        { id: main, focusedBlock: 777 },
++      { id: pageB, focusedBlock: null },
        { id: pageA, focusedBlock: 888 },
    ]
}

Numeric index + Panel owns focused block

Inserting specific panel:

{
    focusedPanel: 0,
    panels: [
        { id: main, focusedBlock: 777 },
++      { id: pageB, focusedBlock: null },
        { id: pageA, focusedBlock: 888 },
    ]
}

"Rehydrating":

{
    focusedPanel: 0,
--  panels: [
--      { id: main, focusedBlock: 777 },
--      { id: pageA, focusedBlock: 888 },
--  ]
++  panels: [
++      { id: main, focusedBlock: 777 },
++      { id: pageB, focusedBlock: null },
++      { id: pageA, focusedBlock: 888 },
++  ]
}

Numeric index + Seperate map

{
    focusedPanel: 0,
-   panels: [main, pageA],
+   panels: [main, pageB, pageA],
    panelToBlock: { main: 777, pageA: 888 },
}

Closing a page

[Main, PageA*, PageB] => [Main, PageB*]

Panel references + Panel owns focused block

{
--  focusedPanel: pageA,
++  focusedPanel: whateverSlidIntoTheHolePageALeft,
    panels: [
        { id: main, focusedBlock: 777 },
--      { id: pageA, focusedBlock: 888 },
        { id: pageB, focusedBlock: 999 },
    ]
}

Numeric index + Seperate map

{
    focusedPanel: 1,
-   panels: [main, pageA, pageB],
+   panels: [main, pageB],
    panelToBlock: { main: 777, pageA: 888 },
}

Bumping a page to the top

[Main*, PageA, PageB] => [Main*, PageB, PageA]

Panel references + Panel owns focused block

{
    focusedPanel: main,
    panels: [
        { id: main, focusedBlock: 777 },
--      { id: pageA, focusedBlock: 888 },
++      { id: pageB, focusedBlock: 999 },
--      { id: pageB, focusedBlock: 999 },
++      { id: pageA, focusedBlock: 888 },
    ]
}

Numeric index + Seperate map

{
    focusedPanel: 0,
-   panels: [main, pageA, pageB],
+   panels: [main, pageB, pageA],
    panelToBlock: { main: 777, pageA: 888 },
}

Thoughts

When observing side panel mutations, it's easy to get the entire DOM of the side panel. It seems more tricky to get the specific pages that appear/disappear.

If we can assume there will only ever be main/side panels, then I guess the Seperate map doesn't offer anything. https://github.com/tntmarket/roam-toolkit/pull/5/files seems easier with a Seperate map, and I plan to work on it after the core Vim stuff + hints.

@Stvad
Copy link

Stvad commented Jul 5, 2020

Assumptions

  • I think it's implicit here, but from what I can see - the order is important here
  • h1 page name are not sufficient to uniquely identify the panel (the case of mentions and of duplicate panels in sidebar)
  • to remediate that we're gonna assign each panel object a uid (they lack any id atm), or use the actual object reference as dicussed
{
    focusedPanel: main,
    panelOrder: [main, uid1, uid2]
    panels: {
        "main": mainPanel,
        "uid1": panel1, 
        "uid2": panel2
    }
}

On update:

  • Discard panelOrder
  • Re-create panels map by:
    • For each panel discovered - if it has UID - look it up in the old map and copy
    • If it has no uid - give it one and add to the map
  • Re-create the panelOrder along the way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment