Skip to content

Instantly share code, notes, and snippets.

@appcypher
Last active January 16, 2022 22:22
Show Gist options
  • Save appcypher/8ac582d6d49eb1c762dd2dfed5610c27 to your computer and use it in GitHub Desktop.
Save appcypher/8ac582d6d49eb1c762dd2dfed5610c27 to your computer and use it in GitHub Desktop.
Session State

Current Method

type SessionOpenTab = {
  id: string;
  userId: string;
  tabId: string;
  focus: boolean;
  order: number;
}

let mySessionOpenTabs: SessionOpenTab[] = [
  { id: "1", userId: "5", tabId: "5", focus: false, order: 0 },
  { id: "2", userId: "5", tabId: "1", focus: true, order: 1 },
  { id: "3", userId: "5", tabId: "3", focus: false, order: 2 },
]

Versus a Possible Improvement

type SessionOpenTabs = {
  id: string;
  userId: string;
  focusTabId: string;
  tabIdOrders: [number, string][]; // (preceding_index, actual_id) 
  // A tuple of the index that precedes the tab id and the id itself.
  // This implies tab table must have an auto-incrementing index column. 
}

let mySessionOpenTabs: SessionOpenTabs = {
  id: "1",
  userId: "5",
  focusTabId: "1",
  tabIdOrders: [
    [-1, "5"] // The only one moved by the user to the top
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment