Skip to content

Destructuring Objects At Top Level #48

Open
@lsh

Description

@lsh

Problem statement: Destructuring is incredibly useful when writing legible code, especially when the notebook user only wants several methods from a parent library. Currently, if one wants methods { A, B } from library lib, they would write:

// cell 1
lib = require('lib');

// cell 2
A = lib.A;

// cell 3
B = lib.B;

Current workaround:
One way Observable users have achieved similar functionality when dealing with libraries is by creating a separate notebook that serves as a representation of the restructured cells. So assuming the above snippet was stored in a notebook called @lsh/lib, it could be imported as:

import { A, B } from '@lsh/lib';

Alternatively, some users push these management cells to an appendix section.

Prior art:
There is a pull request for this functionality at observablehq/parser#88, however it seems to have been abandoned due to possible lack of backwards compatibility with mutable cells.

Ideal functionality:

The ideal solution would be a single cell that allows:

{ A, B } = require('lib');

however, as is referenced in the parser PR, wrapping the braces in parenthesis might be needed.

({ A, B }) = require('lib');

Originally laid out at talk/4738.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions