vorpal
vorpal copied to clipboard
types for localstorage wrong
vorpal.localstorage has wrong type on the instance. It does not have setItem and getItem
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