Move to class-based construction
See original GitHub issue@sindresorhus right now, we use a traditional function/prototype build up of the Chalk class.
This has the negative side effect that in order to enable templating on custom contexts, you have to omit new
- which is counterintuitive.
const ctx1 = chalk.constructor();
const ctx2 = new chalk.constructor();
const str1 = ctx1`hello`; // OK
const str2 = ctx2`hello`; // Error
Unless I’m mistaken, we can leverage constructor()
's ability to return a completely different object (even with new
) to allow templates on all new chalk functions.
class Chalk {
constructor(...) {
// ... build up chalk template function ...
return chalkTemplate;
}
// ...
}
const ctx = new Chalk();
const str = ctx`hello!`; // OK
Is this something we should do?
// cc @sindresorhus
tom-sherman earned $60.00 by resolving this issue!
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on Issuehunt to raise funds.
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
c++ - Move construction and assignment of class with constant ...
I have a class with a const member that needs both a move constructor and assignment. I implemented it the following way:
Read more >Class A Vs. B. Vs. C Real Estate: CRE Property Classes [Guide]
As buildings improve or deteriorate over time, they can shift from one class into another. Nonetheless, an ideal location will always add value, ......
Read more >Why should I use a factory class instead of direct object ...
Factory classes are often implemented because they allow the project to follow the SOLID principles more closely. In particular, the interface segregation ...
Read more >Copy and Move Refactorings | IntelliJ IDEA Documentation
The Move refactoring lets you move packages and classes between the source roots of a project, class members to other classes and inner...
Read more >Project Management for Construction: Construction Planning
In forming a construction plan, a useful approach is to simulate the construction process either in the imagination of the planner or with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@issuehuntbot don’t care about seeing funding status - that’s cool and all - but we can already see when people submit PRs. Don’t need you to mirror that data, it just causes noise.
cc @Rokt33r
@tom-sherman has submitted a pull request. See it on IssueHunt