question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Move to class-based construction

See original GitHub issue

Issuehunt badges

@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!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Qix-commented, Jan 26, 2019

@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

1reaction
IssueHuntBotcommented, Jan 26, 2019

@tom-sherman has submitted a pull request. See it on IssueHunt

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found