3 ms·
By the way, what the hell is the $() thing? Why would we need that?
by huydotnet 7y ago
By the way, what the hell is the $() thing? Why would we need that?
- dvkndn3 7y agoThere are many reasons actually: First is because I don't want to return a string as soon as you apply a value like "textRed()", because it prevents chaining, or I need to add those methods to the String prototype (right?). Therefore, when you call "textRed()", it just updates the current instance. Second is that I actually wanted to use `[Symbol.toPrimitive]`, because it allows keeping the instance but still returns a string when expected (e.g. inside a `className` prop). However, TypeScript hasn't have good support for it yet (https://github.com/microsoft/TypeScript/issues/4538 https://github.com/microsoft/TypeScript/issues/4538) so we still need an explicit method to convert the instance to string.
- huydotnet 7y agoDoes $() a semantics requirement from TS/JS? Any chance for a better/meaningful name?
- WorldMaker 7y ago$ is just an ordinary JS name. It almost, sort of makes sense here in the builder because $ is also the Regex symbol for "end of string". But other names could be possible, they just likely won't be as short to be meaningful. (`buildString()` or `toClassnames()` are two common forms of names I've seen in these sorts of "fluent" APIs for finalizers/builders.)
- dvkndn3 7y ago`toString()` actually works here :D