Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
lopu879311dFor example at the moment we have to do this..
let rewardPointsContent;
if (isShowMuff && !rewardPointsContent) {
rewardPointsContent = <Muffs />;
}
if (isEaster && !rewardPointsContent) {
rewardPointsContent = <HCBEaster />;
}
if (!rewardPointsContent) {
rewardPointsContent = <IcedCoffee />;
} -
melezorus343336311dsounds like you need to use a feature flag checker which is...
a function that returns the value that should be in the const :P
if (isConst) return skill.issue;
if(isEaster) return egg.issue;
//And more -
Lensflare17558311d@retoor lol, I didn‘t even know that it was allowed. Gotta love JS: It never runs out of little details which are plain idiotic. 😂
-
electrineer29805311d@Lensflare should I tell you about "global" keyword in python and why it is necessary
-
jiraTicket2273310dMaybe I’m not understanding but..
you can always use a global
or define a function as a a child of a another function - which allows acess to parent scope
Beyond stuff like that - do any languages allow more than that? -
melezorus343336305d@lopu look, it sounds good to be able to do that but it's a nightmare on many points.
We can bikeshed everyshit until you are satisfied but the most SIMPLE, closest to what you gave as an example and not "introducing overhead" way probably is this:
const el = flag1 && value1
|| flag2 && value2
//go on until satisfied and PROVIDE A FALLBACK DAMMIT
this way:
- you are not only making the javascript code schrodinger's code++™, where a variable may:
1. not be defined
2. defined once, but for type loving users like me, it's type cannot be determined easily if the flags are tied to runtime conditions
3. defined more than once, which, oh god how do i put this uh, we want PEOPLE to write the compiler for this. please don't make us get two masters degree for fucking working on JS. Pretty please, even.
- still not introducing a new function
- not getting on my and many others' nerves :) -
melezorus343336305dAND NO, BEFORE YOU SAY "but i wanna define my own way, i don't want to be limited by the ugliness of boolean collapsing" OR SOMETHING LIKE THAT
I ALREADY SAID YOU CAN USE A fhucking METHOD FOR THAT PURPOSE.
Now go touch grass before I make a meme about this
Javascript really needs a way to define consts for a block 1 level up.
So instead of
const el = wide ? els.wide : els.tall
You can do
if (wide) const el = els.wide
if (!els) const el = els.tall
// etc..
Just makes chaining and backup values way easier than inline conditionals 🤔
rant
react
typescript
javascript
const