Adding support for enums

Peter Hoddie peter at moddable.tech
Tue Jun 12 18:46:54 UTC 2018


Kai --

Thank you for sharing for your thoughts.

> there are existing javascript

> design-patterns using dicts/lists that are superior to enums.  the
> primary reason (which was implied) is because they can be easily
> stored/shared/parsed as json config-settings,


You could use JSON, but it is really quite different. Syntax is more verbose, the values may be changed, and it requires runtime parsing. For the places we would use enums, this example of JSON is not superior.

> you can also save/update these configs to a github-repo (with
> encryption like this real-world example [1]), and perhaps have your
> iot device poll it every 5 minutes for effortless config-updates in
> near-realtime.

The use of enums I described is for true constants. These are values carved in stone as part of a Standard. The values will never change, certainly not every five minutes. ;)

-- Peter

> 
> On Jun 12, 2018, at 6:40 AM, kai zhu <kaizhu256 at gmail.com> wrote:
> 
> hi @peter, appreciate your perspective for embedded-device use-case.
> however, as @isiah mentions, there are existing javascript
> design-patterns using dicts/lists that are superior to enums.  the
> primary reason (which was implied) is because they can be easily
> stored/shared/parsed as json config-settings, e.g.:
> 
> ```json
> {
>   "DEVICE_LIST": [
>       {
>           "TYPE": "ARDUINO",
>           "ADFlag": {
>               "LE_LIMITED_DISCOVERABLE_MODE": 1,
>               "LE_GENERAL_DISCOVERABLE_MODE": 2,
>               "LE_GENERAL_DISCOVERABLE_MODE_ARDUINO": 3,
>               "NO_BR_EDR": 4
>           },
>           "ADType": {
>               "INCOMPLETE_UUID16_LIST": 2,
>               "COMPLETE_UUID16_LIST": 3,
>               "INCOMPLETE_UUID128_LIST": 6,
>               "COMPLETE_UUID128_LIST": 7
>           }
>       },
>       {
>           "TYPE": "RASPBERRY_PI",
>           "ADFlag": {
>               "LE_LIMITED_DISCOVERABLE_MODE": 1,
>               "LE_GENERAL_DISCOVERABLE_MODE": 2,
>               "NO_BR_EDR": 4
>           },
>           "ADType": {
>               "INCOMPLETE_UUID16_LIST": 2,
>               "COMPLETE_UUID16_LIST": 3,
>               "INCOMPLETE_UUID128_LIST": 6,
>               "COMPLETE_UUID128_LIST": 7
>           }
>       }
>   ]
> }
> ```
> 
> you can also save/update these configs to a github-repo (with
> encryption like this real-world example [1]), and perhaps have your
> iot device poll it every 5 minutes for effortless config-updates in
> near-realtime.
> 
> -kai
> 
> [1] encrypted travis-ci-config-settings hosted on github
> https://github.com/kaizhu256/node-utility2/blob/gh-pages/CRYPTO_AES_SH_ENCRYPTED_kaizhu256
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list