Skip to content

Add recommended libraries #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 12, 2021
Merged

Add recommended libraries #207

merged 4 commits into from
May 12, 2021

Conversation

mbostock
Copy link
Member

@mbostock mbostock commented May 5, 2021

This adds a handful of first-party and sanctioned third-party libraries to the Observable standard library for convenient access from notebooks. This set of libraries may grow over time based on demand. The current set is:

In the last case, some additional code is required based on this notebook.

The trickiest part here is version pinning. I chose to hard-code the versions and paths in the standard library for stability and performance, and in particular to guarantee that duplicate versions of D3 and Hypertext Literal are not loaded: Observable Plot depends on D3, and Observable Inputs depends on Hypertext Literal. A consequence of this choice is that we’ll need to upgrade the Observable standard library explicitly, for everyone, when new versions of these libraries are released. However, when Observable supports version pinning natively in the future, we should be able to relax these requirements and give authors control over which version to use. In the meantime, notebook authors can require the libraries explicitly rather than depending on the standard library if they want to specify the version.

@mbostock mbostock requested a review from wiltsecarpenter May 5, 2021 21:29
@shancarter
Copy link

I don't have an solutions to offer, but having both htl and html feels like a bummer. Or does one replace the other?

@mbostock
Copy link
Member Author

mbostock commented May 5, 2021

We can’t change the behavior of html without breaking lots of notebooks. When we support standard library versioning, we can replace the existing html and svg directly instead of introducing htl.

Mutable: () => Mutable,
Plot: () => require("@observablehq/[email protected]/dist/plot.umd.min.js"),
Promises: () => Promises,
_: () => require("[email protected]/lodash.min.js"),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is sort of not-like-the-others in this set. I assume that it is very commonly used and stable in notebooks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lodash is the most popular library on npm according to this analysis:

https://gist.github.com/anvaka/8e8fa57c7ee1350e3491

It appears to be referenced in 2.5K public notebooks according to this query:

https://observablehq.com/search?query=lodash

That’s less than Vega (9K) and D3 (10K+), but still quite popular, and I vouch for its quality.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question regarding evolvability and compatibility: I started out using Ramda because of its elegant “immutable auto-curried iteratee-first data-last methods”. However, including the much more popular lodash library conveniently and lazily by default urges me to switch to lodash. Plus, I just learned that there also is lodash/fp, that enjoys the same feature as Ramda above. Is there a way to include lodash/fp by default the same way as just lodash? Or should I fall back to an explicit require?

@tophtucker
Copy link
Contributor

tophtucker commented May 7, 2021

how much does this increase the size of the bundle? we could add an example to the examples repo showing how to roll your own version-pinning for downloaded notebooks (i.e. the example would just sub in an older or pruned version of stdlib)

@mbostock
Copy link
Member Author

mbostock commented May 7, 2021

It has a negligible increase in the bundle size because everything is loaded lazily. You only load d3 if you reference it.

@tophtucker
Copy link
Contributor

oh wow that's sweet

@mbostock mbostock merged commit f18a7eb into master May 12, 2021
@mbostock mbostock deleted the mbostock/more-libraries branch May 12, 2021 20:20
This was referenced May 13, 2021
@Fil
Copy link
Contributor

Fil commented May 13, 2021

To help the user could you add .version systematically? Currently each library has a different method (if at all): https://observablehq.com/@fil/stdlib-recommended-libraries

@mootari
Copy link
Member

mootari commented May 14, 2021

A consequence of this choice is that we’ll need to upgrade the Observable standard library explicitly, for everyone, when new versions of these libraries are released.

Is the current plan to hold out on BC breaking updates for these libraries until Observable supports version pinning out of the box?

@mbostock
Copy link
Member Author

@mootari Yes, we’re only going to accept patch and minor upgrades until Observable supports version pinning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants