-
Notifications
You must be signed in to change notification settings - Fork 12
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
67 #5
base: master
Are you sure you want to change the base?
67 #5
Conversation
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 love what you've done to simplify this! I just have a few questions and requests
lib/micro-enum-DOCUMENTED.js
Outdated
var Enum = // the name of the "class" | ||
function() // this is what the arguments are passed to | ||
{ | ||
var values = arguments; // get the varargs and save them to a 'values' variable. | ||
var self = { // prepare a 'self' object to return, so we work with an object instead of a function | ||
all : [], // prepare a list of all indices | ||
keys : values // create the list of all keys | ||
}; | ||
|
||
for(var i = 0; i < values.length; i++) // for all enum names given | ||
{ | ||
self[values[i]] = i; // add the variable to this object | ||
self.all[i] = i; // add the index to the list of all indices | ||
} | ||
|
||
return self; // return the 'self' object, instead of this function | ||
const Enum = (...elements) => { | ||
const s = { | ||
all: [], | ||
keys: elements | ||
} | ||
; No newline at end of file | ||
|
||
elements.map((el, i) => { | ||
s[el] = s.all[i] = i | ||
}) | ||
|
||
return s | ||
} |
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.
Thanks for modernizing this! The changes make a lot of sense!
However, this "DOCUMENTED" file is overly-compacted. It was originally unrolled and commented to help explain how the code works, so removing the comments, shortening variable names (s
, el
), and combining assignments (s[el] = s.all[i] = i
) makes it more difficult to understand what's going on
@@ -1 +1 @@ | |||
Enum=function(){let v=arguments,s={all:[],keys:v};for(let i=v.length;i--;)s[v[i]]=s.all[i]=i;return s;} | |||
module.exports=Enum=((...l)=>(s={all:[],keys:l},l.map((l,a)=>s[l]=s.all[a]=a),s)); |
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.
This is awesome!
Can you help me understand why you reassign module.exports
here as well as in index.js
?
{ | ||
"name": "simple-enum", | ||
"version": "1.0.0", | ||
"description": "A very, very tiny JavaScript enum implementation", | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/tolgaek/node-enum" | ||
}, | ||
"author": "Tolga Ekmen <tolga.ekmen@gmail.com>", | ||
"license": "MIT" | ||
} |
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.
Can you help me understand why this metadata was removed? It seems useful to maintain attribution and description
module.exports = require('./lib/micro-enum.js'); | ||
module.exports=require('./lib/micro-enum.js'); |
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.
This is only used on the developer side, right? So the user doesn't download this, if I understand correctly. What do these whitespace removals improve?
A **94-byte** JavaScript enum implementation. | ||
A **67-byte** JavaScript enum implementation. | ||
|
||
Hazer-hazer version of `tolgaek` 94-byte JavaScript enum implementation. |
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.
This downplays the original creators. It'd be kinder to say that @tolgaek and I originally wrote this, and you improved upon 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.
:)
No description provided.