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

fix caching of styles #33

Merged
merged 2 commits into from Jul 9, 2014
Merged

fix caching of styles #33

merged 2 commits into from Jul 9, 2014

Conversation

seanmonstar
Copy link
Contributor

If you choose to go with option 2 that I listed in #32, this is the PR.

var argsLen = args.length;
var str = argsLen !== 0 && String(arguments[0]);
if (argsLen > 1) {
for (var a = 0; a < argsLen; a++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

L43 already sets str to args[0]. The index in this loop should start at var a = 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Woops, I had this originally, and a must have lost it in a clean up.

@jbnicolai
Copy link
Contributor

Fantastic pull-request! 🌟

return applyStyle.apply(builder, arguments);
};
builder._styles = _styles;
builder.__proto__ = proto;
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Do the Object.create dance instead 💃

Copy link
Member

Choose a reason for hiding this comment

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

Oh, just saw your issue comment.

- defines the getters onto a proto
- the function returned has its __proto__ set to our proto

fixes chalk#32
~21% increase with multiple arguments
@seanmonstar
Copy link
Contributor Author

I fixed the for the loop, and add a couple comments as to why these changes exist, for a better future!

jbnicolai pushed a commit that referenced this pull request Jul 9, 2014
fix caching of styles, fixes #32
@jbnicolai jbnicolai merged commit ca250ab into chalk:master Jul 9, 2014
@jbnicolai
Copy link
Contributor

@seanmonstar 👍 thanks for both the fantastic pull request, and your explanation of the steps you took to fix the bug!

@jbnicolai jbnicolai mentioned this pull request Jul 9, 2014
@sindresorhus
Copy link
Member

@seanmonstar you're awesome!

5fa79994-b5ee-11e3-9a4d-b19557d7480b

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.

None yet

4 participants