Git Product home page Git Product logo

Comments (1)

DominicChm avatar DominicChm commented on June 2, 2024

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

from vorpal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.