Skip to content

Instantly share code, notes, and snippets.

@tlrobinson
Last active September 30, 2019 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tlrobinson/5d3870292e4a7b0769ba803fcef72927 to your computer and use it in GitHub Desktop.
Save tlrobinson/5d3870292e4a7b0769ba803fcef72927 to your computer and use it in GitHub Desktop.
Metabase immutable wrapper classes

metabase-lib/lib/metadata:

  • "Base" base class
  • copies properties
  • also includes "_plainObject"
  • external logic sets up references, lame: "metabase/selectors/metadata"

metabase-lib/lib/Dimension.js:

  • "Dimension" base class, encode each clause as a different subclass
  • also includes optional "_parent" (actually a child in the tree, i.e. ["field-id", 1] is a _parent in ["datetime-field", ["field-id", 1], "month"]) and "_args" which are rest of clause args (month the datetime-field or 1 in the field-id)
  • also includes "_metadata" and "_query" properties
  • has basic parseMBQL functionality

metabase-lib/lib/queries/structured: "MBQLArrayClause" and "MBQLObjectClause" base classes inherit from Array and Object

  • also includes "_index" and "_query" private properties
  • can be treated as original objects or wrappers, JSON.stringify(wrapper) works
  • support immutable updates

tlrobinson/vanilla

  • https://github.com/tlrobinson/vanilla/blob/master/src/vanilla.test.ts
  • "VanillaArray" and "VanillaObject" base classes inherit from Array and Object
  • also includes "_parser", "_parent", "_key", "_meta" private properties
  • can be treated as original objects or wrappers, JSON.stringify(wrapper) works
  • has advanced parse functionality
  • support immutable updates
  • TypeScript support

tlrobinson/vanilla/mbql:

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