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

types for localstorage wrong #352

Open
macrozone opened this issue Oct 29, 2020 · 1 comment
Open

types for localstorage wrong #352

macrozone opened this issue Oct 29, 2020 · 1 comment

Comments

@macrozone
Copy link

vorpal.localstorage has wrong type on the instance. It does not have setItem and getItem

@DominicChm
Copy link

I was experiencing this issue (.getItem is not a function). My mistake was assuming that .localStorage("id") retrieved a "channel" object of some type that setItem and getItem could be used on. What it actually does is set the localstorage ID for the entire vorpal instance.

Doesn't work:

...
vorpal.localStorage("test").getItem("t")

> TypeError: vorpal.localStorage(...).getItem is not a function

If you look at the src of the localStorage function:

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

when called it extends the localStorage instance but returns the vorpal instance, meaning that to make that one-liner work, you'd need to access localStorage again after calling it as a function:

vorpal.localStorage("test").localStorage.getItem("t")

Not just returning the localStorage instance is unintuitive for this specific use case, so I assume the function is meant to be used in a setup chain like so:

vorpal
    .delimiter('test$')
    .localStorage("test")
    .show();

vorpal.localStorage.getItem("t")

tl;dr: You can't chain .getItem() or .setItem() onto a localStorage(id) function call

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

No branches or pull requests

2 participants