coinbin
coinbin copied to clipboard
Save Network in a cookie
Related to issue #220
Issue: Refer to #220
What has been done: Created a class for saving cookies to be able to have the choice the user made for his network beyond page reloads.
What has changed: Store the choosen dropdown option in a cookie. Restore the previously choosen option when the page is loaded.
- Why not localStorage?
- Are those ESNext private class fields? Those should be avoided, as browser support is still low.
But even if you were to use them, you declare them but never use them, and instead use the public name. You have to keep the # for every get and set of the field. This will throw a parsing error in any browser that doesn't support it. (unlike other unsupported functions where "if you don't touch the affected code you're fine"... this will break the entire file from being parsed so be careful.)
Example:
class Test {
#name
constructor(name) {
this.name = name;
this.#name = 'PRIVATE ' + name;
}
get privateName() {
return this.#name
}
}
var x = new Test('bob');
console.log(x.name)
// bob
console.log(x.privateName)
// PRIVATE bob
-
Haven't thought about that. What is the advantage of localStorage, apart from being easier to use?
-
Woops, those should not be there anymore... I intented to use ESNext fields, but scratched the Idea due to low browser support. Also the whole class would only with with ES6 Support, which is not widely supported too yet, is it?
Did a bit of research on localStorage and came to the conclusion that in this case, it is the better way to do it. Thanks for pointing that out to me! @junderw
@maxbethke Might worth to check out this PR as well https://github.com/OutCast3k/coinbin/pull/250, have added support for electrum servers as well.