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

Feature: Allow metalsmith methods to be destructured #357

Open
webketje opened this issue Dec 29, 2021 · 0 comments
Open

Feature: Allow metalsmith methods to be destructured #357

webketje opened this issue Dec 29, 2021 · 0 comments

Comments

@webketje
Copy link
Member

webketje commented Dec 29, 2021

Please add a thumbs up if this is important to you

Allow metalsmith methods to be destructured like

const { use, build } = require('metalsmith')(__dirname)

Currently this is not possible as the this context is not bound to destructured methods, it is inherited from the executing context, in Node's case, module

Binding the methods automatically in the constructor effectively makes the prototype-sharing of the methods useless.
That opens up the path for using the factory-pattern to replace the module.exports function, or alternatively rename it to Metalsmith.create.

Modern (& TS-enabled) packages often allow access to enums & "static class methods" (~ functions that are properties of a constructor) like const { Metalsmith } = require('metalsmith'). Returning Metalsmith.create in 2.4 could be a bridge to that path.
But binding the methods as an opt-out (for the purists among us) in a factory func (in the current codebase Metalsmith func is actually a factory + a constructor in 1) looks cleaner as it allows the Metalsmith prototype to remain pure

@webketje webketje added this to the v3.0 milestone Jan 7, 2022
@webketje webketje pinned this issue Jan 31, 2022
@webketje webketje unpinned this issue Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant