Feature Request: Top Level Multi Definitions or Destructured Requires

Hi,

I think having the ability to define multiple values at a top level or destructured requires would be useful for certain notebooks. I’ll use TidyJS as an example to demonstrate part of why I think this would be a helpful feature.

I could require it in a cell directly from the distrubtion with:

T = require('@tidyjs/tidy/dist/umd/tidy.min.js')

Then I could use it like so:

T.tidy(
  data,
  T.groupBy('key', [
    T.summarize({ total: T.sum('value') })
  ])
)

Alternatively I could wrap the cell in braces and destructure the functions I want:

{
  const { tidy, groupBy, summarize, sum } = T;
  tidy(
    data,
    groupBy('key', [
      summarize({ total: sum('value') })
    ])
  )
}

Thankfully, there exists a Tidy notebook so I can call

import { tidy, groupBy, summarize, sum } from '@pbeshai/tidyjs'

However, if new functions are added to the library, but are not added to the notebook above, I would rely on the earlier methods.
Therefore, I think it would be valuable for writing clean notebooks to be able to at least write the destructured import:

{ tidy, groupBy, summarize, sum } = require('@tidyjs/tidy/dist/umd/tidy.min.js')

Thank you,

Lukas

This would be possible with “destructable cells,” where something like this could be done with any function/cell body, not just with require:

({foo, bar}) = ({foo: 1, bar: 2})

It looks like a PR for this was started in the Observable parser, but seems abandoned after it became clear it wouldn’t be backwards compatible (and would probably need a lot of work to get right)

Hopefully it can come back!

1 Like