vorpal icon indicating copy to clipboard operation
vorpal copied to clipboard

Update lib/local-storage.js to ES2015

Open Nathan-Schwartz opened this issue 8 years ago • 4 comments

Tests and linter pass. Runs in Node without babel.

Nathan-Schwartz avatar May 28 '17 12:05 Nathan-Schwartz

@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.

milesj avatar May 31 '17 04:05 milesj

Agreed. Go for it.

dthree avatar Jun 01 '17 00:06 dthree

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.

Nathan-Schwartz avatar Jun 01 '17 03:06 Nathan-Schwartz

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

milesj avatar Jun 01 '17 07:06 milesj