Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

67 #5

wants to merge 4 commits into from

Conversation

hazer-hazer
Copy link

No description provided.

Copy link

@KyNorthstar KyNorthstar left a 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

Comment on lines 75 to 87
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
}

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));

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?

Comment on lines -1 to -12
{
"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"
}

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');

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.

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants