Skip to content
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

Documentation obfuscates Quill.import usage, making it unclear e.g. how to import non-default exports #2938

Closed
natevw opened this issue Feb 20, 2020 · 1 comment · May be fixed by #2939
Closed

Comments

@natevw
Copy link

natevw commented Feb 20, 2020

The API documentation for Quill.import is misleading (emphasis mine):

Static method returning Quill library, format, module, or theme. In general the path should map exactly to Quill source code directory structure.

And the example has a comment that using Quill.import is…

// Similar to ES6 syntax import Link from 'quill/formats/link';

No other discussion is provided regarding exceptions to the "in general". So when I needed to get a non-default export that exists inside the "Quill source code directory structure" at blots/block I guessed I would have to do something like

let { BlockEmbed } = Quill.import('blots/block');    // WRONG

…and the Quill.import internals would have set things up so that all the other exports would be exposed as properties on the Block as default value it returns. But BlockEmbed gets an undefined value; apparently not much similarity to ES import as claimed.

Elsewhere in the documentation, I found a more helpful note:

You can view a list of Blots and Attributors available by calling console.log(Quill.imports);. Direct modification of this object is not supported. Use Quill.register instead.

So the secret is that Quill.import actually has very little to do with filesystem paths and ES module syntax, and a whole lot more to do with what calls to Quill.register are made internally. Behold, in quill/core.js I found:

Quill.register({
  'blots/block': Block,
  'blots/block/embed': BlockEmbed,
  //…

As it turns out, my code should actually be:

let BlockEmbed = Quill.import('blots/block/embed');

It would have saved me significant time if the API documentation for Quill.import() itself had confessed the connection with Quill.register() and ability to see what Quill.imports exist, instead of conveying the impression that it was more like the real ES module import.

Related: #2659

natevw added a commit to natevw/quill that referenced this issue Feb 20, 2020
Make it more clear that `Quill.import` is just the read to `Quill.register`'s write, and that the relationship between Quill source code and an object's "path" is simply a convention.

I wrote this assuming that `Quill.imports` is internal API but since it was already mentioned elsewhere in the public docs it seemed fitting to share a similar tip here.
@benbro
Copy link
Contributor

benbro commented Feb 3, 2024

Please try v2.0.0-rc.0
https://v2.quilljs.com/docs/installation

@benbro benbro closed this as completed Feb 3, 2024
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 a pull request may close this issue.

2 participants