-
Notifications
You must be signed in to change notification settings - Fork 435
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
Multi-value support for GM_getValues, GM_setValues, GM_deleteValues? #2045
Comments
Makes sense. I'll add support for this in the next BETA version. |
Could there be something "Proxy" ? ( the usage is like Option 1// only one argument. object. the value is the default value if not exist (so this can make sure there is always a default value)
const gmValues = GM_values({
foo: 1,
bar: 2
});
// gmValues is a Proxy
// the values are obtained at each proxy's get
console.log(await gmValues.foo) // 1
gmValues.foo = 3
console.log(await gmValues.foo) // 3 Option 2// only one argument. object. the value is the default value if not exist (so this can make sure there is always a default value)
const gmValues = await GM.values({
foo: 1,
bar: 2
});
// values are all cached in gmValues.
// gmValues is a Proxy. All values inside will have GM_addEvenListener.
// the values will be automatically updated, so getter just read the stored cache value.
console.log(gmValues.foo) // 1 (just the cache)
gmValues.foo = 3
console.log(gmValues.foo) // 3 (the GM.setValue might be not completed at this time, but the setter updated the cache value already)
// if it is changed externally, the gmValues.foo will be also updated. |
With proxy you can't await the result of setting the value. Either way, it's not related to the idea in this issue, so you should open a new one. |
If I may add a word, FM introduced multi-value GM storage option in erosman/support#545 |
I thought about extending the existing singular functions with the new syntax, but I decided it would encourage authors to use it directly without first checking for |
Fixed at 5.3.6207 (crx|xpi in review) I've decided against overloading the old API methods, because it would be difficult to detect whether multi-values are supported or not. |
Maybe something like this?
GM_getValues(['foo', 'bar'])
-> {foo: 1, bar: 2} or {foo: 1} ifbar
is missingGM_getValues({foo: 1, bar: 2})
-> providing the default values.GM_getValues()
orGM_getValues(null)
orGM_getValues(undefined)
-> read the entire storageGM_setValues({foo: 1, bar: 2})
GM_deleteValues(['foo', 'bar'])
Ideally I'd like Violentmonkey/Tampermonkey to avoid preloading all storage data at script start when the script doesn't ask for the legacy GM_xxxValue, in which case multi-value support becomes important because of the overhead to process each value individually. When
GM.xxxValue
functions are implemented as a native asynchronous call it makes sense from a performance viewpoint to allow specifying multiple values in one call, just like it's done inchrome.storage
API.The text was updated successfully, but these errors were encountered: