zendesk / cross-storage

Cross domain local storage, with permissions
Apache License 2.0
2.22k stars 180 forks source link

Support for Different Storage via Adapter #35

Closed JasonLi914 closed 7 years ago

JasonLi914 commented 7 years ago

Hi, I was wondering if it would be possible for CrossStorageHub to be able to support being initialized with different types of storage (i.e. indexedDb, WebSQL), rather than solely using localStorage. The reason for this is that localStorage may not be desired by users because of it's limited storage capacity. My thoughts were that this would be implemented via an Adapter and localStorage will be the default storage option when a different one isn't specified, so that this change will not be breaking for existing users of cross-storage. Would be willing to write this PR as well. Please let me know your thoughts, thanks!

danielstjules commented 7 years ago

I see you've started working on it in https://github.com/JasonLi914/cross-storage/commit/d83b474bb10bef9c7f064d8fc62f2bdc1c688d65 The LocalStorageAdapter is looking good :)

It's def an interesting idea, but I should probably remind that this library essentially isn't compatible with Safari. If one's writing a bunch of application logic that's dependent on cross-domain indexedDb, what about Safari users? My thinking was that if it's just localStorage, you probably aren't storing anything too complicated, and can hopefully fallback to a server or cookie as needed for safari. But for something as heavy/involved as indexedDb, what then? I'd almost want to dissuade devs from using anything other than the "LocalStorageAdapter"

danielstjules commented 7 years ago

Thinking about this a bit more, I don't think additional storage adapters are worth it, since the consumer-facing API would need to be made async to accommodate indexedDb. Seems unnecessary for a project originally designed for localStorage. But you're always welcome to work on a fork! :)