victorb / trymodule

âž° It's never been easier to try nodejs modules!
1.14k stars 29 forks source link

Assign module to a custom variable in REPL #19

Closed shockey closed 8 years ago

shockey commented 8 years ago

Hey all 👋

I saw the discussion in #17 and decided to jump in.

Let's talk about these changes, and hopefully get them merged.

Changes:

victorb commented 8 years ago

Amazing! Thanks a lot for contributing this, it's a good feature and I like the implementation!

However, I would like to change one thing.

const packages = []; // data looks like [moduleName, as]

The snippet above seems a bit weird. Instead of having an array where the even entries are module names and the odd entries are the aliases, could we have an map with object instead?

Right now, it would look like this:

packages = ['lodash', '_', 'colors', 'c']

I would like it to be more like this:

packages = {
  'lodash': '_',
  'colors': 'c'
}

Makes sense?

shockey commented 8 years ago

Hey @VictorBjelkholm,

Actually, that inline comment isn't quite clear- the data in packages ends up being a nested array, like so:

packages = [ ['lodash', '_'], ['colors', 'c'] ]

That being said, I agree- using an object here is the best way forward. This is what associative arrays are made for! 😃

I'll set that up and push the changes in a bit.

shockey commented 8 years ago

@VictorBjelkholm bump 😃

victorb commented 8 years ago

Sweet! Seems to work fine :) Thanks a lot for adding this feature @kyleshockey! (Also added you as a collaborator in this repo)