r/javascript • • May 15 '17

Don't Overcomplicate Javascript #0

https://bits.ristic.io/dont-overcomplicate-javascript-0
35 Upvotes

34 comments sorted by

View all comments

74

u/markzzy May 15 '17 edited May 15 '17

To save some people an unnecessary click, this article is not necessarily about the vague topic of overly-complicated JavaScript patterns as the title suggests. It is more about constants that are used in redux with the React framework. If you dont use react, or arent familiar with it, this probably wouldnt matter much to you.

10

u/eddieSullivan May 15 '17

Yes, and it really just points up the lack of decent enum types in JavaScript. It's unfortunate that Redux has to use string constants like this.

1

u/phoenixmatrix May 17 '17

Enums are not the solution here. That would just reduce the need for strings in action creators. But action creators + action constants are constructs that together replace type structure of the kind you see in Elm. String enums are just a way to make the work around less verbose. Just being able to create types that you can pattern match on (even if it's not static typing) would actually add value (reducing bugs, etc), not just how many times I have to smack the keyboard (which is overrated anyway)

1

u/alleycat5 May 15 '17

Luckily this is looking to get fixed in 2.4 with proper enum support. https://github.com/Microsoft/TypeScript/wiki/Roadmap#24

11

u/ns0 May 16 '17

Typescript!=JavaScript

2

u/alleycat5 May 16 '17

Sorry, for some reason I misread.

1

u/Master_Rux May 15 '17

Yes more enum support! I have so many JS projects that could use enums.

Fun fact. Every class of constants is an enum. Granted things vary a little from language to language. Some languages inherit from an enum type. Enums are just syntax sugar that get compiled down to static classes with constants. That said, proper enum syntax would be nice though. They really do add a lot to readability and maintainability.