dthree / vorpal

Node's framework for interactive CLIs
http://vorpal.js.org
MIT License
5.64k stars 280 forks source link

Update lib/local-storage.js to ES2015 #242

Open Nathan-Schwartz opened 7 years ago

Nathan-Schwartz commented 7 years ago

Tests and linter pass. Runs in Node without babel.

milesj commented 7 years ago

@Nathan-Schwartz @dthree

I feel like this entire file can be removed. It's almost a 1:1 map of the native LocalStorage, with the addition of validate(). We can easily move all this logic into Vorpal#localStorage.

For example, this is the current code:

vorpal.localStorage = function (id) {
  var ls = Object.create(LocalStorage);
  ls.setId(id);
  _.extend(this.localStorage, ls);
  return this;
};

Which can be changed to:

vorpal.localStorage = function (id) {
  if (!id) {
    throw new Error('vorpal.localStorage() requires a unique key to be passed in.');
  }

  Object.assign(this.localStorage, new LocalStorage(DEFAULT_STORAGE_PATH + id));

  return this;
};

I haven't tested it yet, but worth a shot.

dthree commented 7 years ago

Agreed. Go for it.

Nathan-Schwartz commented 7 years ago

Sounds good to me. Seems like we can close this.

@milesj Would you like to take a crack at reusing Vorpal#localStorage? Not sure what kind of time I'll have in the near future.

milesj commented 7 years ago

Yeah I can take a look at it. I'll leave this PR open in case it doesn't work.