-
Notifications
You must be signed in to change notification settings - Fork 438
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
feat: add random as a static member of TinyColor #175
Conversation
This got to my expected behavior - thanks! But I don't think it's working exactly how I expected it would. What I expected:
What I think is currently happening:
The reason I expected the former behavior is that so when we load the UMD package - for example, by doing:
Then in the console in that page, if I do |
@@ -16,7 +15,7 @@ const mostReadableEl = document.querySelector<HTMLElement>('#mostReadable'); | |||
const colorBoxEl = document.querySelector<HTMLElement>('#colorBox'); | |||
|
|||
function colorChange(color) { | |||
const tiny = new TinyColor(color); | |||
const tiny = new tinycolor.TinyColor(color); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see the other comment first, but do we need to prefix with tinycolor.
since TinyColor is exposed on the window in line 5?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically it might work, but typescript won't like it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I was wondering if that was the case. No problem.
okay i think what we're looking for is something like this then. Typescript sure doesn't like it very much. I'd never done an export like this before, learn something new every day. This was my small test. class Test {
constructor() { console.log('created test') }
go() { console.log('go') }
}
var _old = Test;
Test = function(...args) { return new _old(...args) };
// can be called either way
Test().go()
new Test().go() |
Codecov Report
@@ Coverage Diff @@
## v2 #175 +/- ##
=========================================
+ Coverage 98.4% 98.56% +0.16%
=========================================
Files 10 10
Lines 626 628 +2
Branches 150 150
=========================================
+ Hits 616 619 +3
+ Misses 10 9 -1
Continue to review full report at Codecov.
|
Yeah TS doesn't seem too happy about it. I think it's nice to have the backwards-compat syntax without new, but I think it'd also be OK to drop the non-new format and just export the class if we tack on |
Specifically, supporting:
|
Revered the optional new tinycolor and added random as a member of the TinyColor class. |
Great, thanks! Could you also expose |
@@ -41,6 +42,7 @@ export class TinyColor { | |||
gradientType?: string; | |||
/** rounded alpha */ | |||
roundA!: number; | |||
random = random; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking this would be a static
, so you could do TinyColor.random()
instead of new TinyColor.random()
. This is basically to support the v1 API (as in https://github.com/bgrins/TinyColor#random)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at TS docs, I think this would be done as:
static random = random;
No description provided.