svelte-webext-storage-adapter icon indicating copy to clipboard operation
svelte-webext-storage-adapter copied to clipboard

Feedback wanted: Using custom stores

Open PixievoltNo1 opened this issue 5 years ago • 4 comments

This package creates Svelte writable stores for you, and offers no alternatives. Is there any demand for a way to specify a different compatible implementation of the store contract to use? How would you use this feature if I provided it?

I'm thinking the API for this would be a new storeFactory option for webextStorageAdapter(). The value would be a function that takes the initial value as an argument and returns the store object.

PixievoltNo1 avatar Aug 04 '20 09:08 PixievoltNo1

Hi, I'm using this and have come across a need for a custom store. My specific use is pretty simple and only really needs the ability to pass a custom set. parameter to writable, but currently I had planned on adding another property/method to the custom store, but not 100% needed.

If you had an idea in mind on how you wanted to implement it I could take a shot at it in a PR.

edit: was half awake when I initially commented, edited for clarity.

fielding avatar Jan 10 '23 04:01 fielding

This could be much more reasonably implemented in v3, as currently there's a lot of manipulation of the store object to collect data to write to storage, whereas v3 will accomplish the same with just a call to .subscribe(). However, the current v3 plans include removing the options parameter for API simplicity. If you're sure that custom stores would make your work a lot easier, I could put options back in the plans so that there's a place for a storeFactory option.

PixievoltNo1 avatar Jan 12 '23 03:01 PixievoltNo1

The v3 beta has been released (see #14); I decided against removing options but have not yet added a store factory option. @fielding, I'd appreciate more info on how helpful this would be to you. You mentioned you wanted to pass a custom set paramater to writable (I assume you mean start parameter?), but now that v3 uses subscriptions internally, a writable would always be "started", so I doubt it would help you much now.

PixievoltNo1 avatar Feb 05 '23 07:02 PixievoltNo1

v3 was released without this, but I'm open to discussing it for a 3.x release.

PixievoltNo1 avatar Feb 22 '23 07:02 PixievoltNo1