let [foo, bar, baz] = jetpack.storage.simple.get(["foo", "bar", "baz"])
jetpack.storage.simple.set({ foo: 1, bar: true, baz: "example" })
jetpack.storage.simple.remove(["foo", "bar", "baz"])
The api could also be simplified a little by handling the arguments
within the methods using the arguments list within the function
scope. So the api would then look like this:
let [foo, bar, baz] = jetpack.storage.simple.get("foo", "bar", "baz")
jetpack.storage.simple.remove("foo", "bar", "baz")
However, we would not be able to assemble long arrays using Array() methods before passing them to get() and remove(). So perhaps this is not a good simplification?
jetpack.storage.simple.get.apply(jetpack.storage.simple, ["foo", "bar", "baz"]);
// equivalent to jetpack.storage.simple.get("foo", "bar", "baz");
let [foo, bar, baz] = jetpack.storage.simple.get("foo", "bar", "baz")
Myk,
I think these are great additions. Would you mind adding them to the JEP https://wiki.mozilla.org/Labs/Jetpack/JEP/11?
My gut feeling is that the suggested syntax:
let [foo, bar, baz] = jetpack.storage.simple.get("foo", "bar", "baz")feels cleaner. The two cons I see are:
(1) Programatically constructing an Array and passing it in becomes harder.
(2) Potential future proofing -- we might want to add an options dictionary or something later.
Neither one of these two cons are insurmountable however.
(1) Is solved by either using .apply as you say (which, while gross looking won't be used very often). The other solution is that if first argument to |get| is an array, it returns as you'd expect.
(2) Because all of the values will be passing in are strings, polymorphism is easy.
callback isn't the only potential addition to the get
call. We should consider adding a default value argument, which
simplifies the common case of wanting to initialize a variable to
either a stored or a default value.arguments array in this way for a variety of reasons,
including these, and we should
do the same.
2)
jetpack.storage.simple.get(["foo", "bar", "baz"], function
(itemsObject) {
// itemsObject = { foo: "foo-value", bar: "bar-value", baz: "baz-
value" }
});
And it also lets us extend |forEachValue| and |forEachItem| like:
jetpack.storage.simple.forEachValue(["foo", "bar", "baz"], function
(val) {
// gets "foo-value", then "bar-value", then "baz-value"
});