Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Make storage a default export #55

Closed
jacobrask opened this issue Mar 12, 2019 · 2 comments · Fixed by #71
Closed

Make storage a default export #55

jacobrask opened this issue Mar 12, 2019 · 2 comments · Fixed by #71
Assignees
Labels
api A proposal for changing the API surface

Comments

@jacobrask
Copy link

Is there any particular reason a named storage export was chosen over a default export? I would expect the vast majority of module consumers to only use the storage api, and it feels more in line with community modules to expose that as a default export.

It is quite likely that future built-in modules will look at this first module when designing API:s so I think this is a relevant discussion even if it's a pretty minor issue.

@domenic
Copy link
Collaborator

domenic commented Mar 13, 2019

This is an interesting proposal! I kind of like them both being on equal footing now, especially since isolated storage areas are so useful, but it's possible we should make it easier to get at the default one.

Do you have examples of the community modules you're thinking of?

I'd personally prefer only one way to do things, so we'd get rid of the storage named export and instead have the default export be the main storage area. Does that align with your thinking as well?

@jacobrask
Copy link
Author

If I look at the most depended on packages in npm, they all have a default export. I can't find any packages that feel like perfect comparisons to this API on npm, but in our application we have a memory storage module as a fallback for when localStorage fails. I could imagine us replacing window.localStorage with kv-storage and doing something like this

// appStorage.js
import { StorageArea } from 'std:kv-storage';
const appStorage = new StorageArea('my-app-storage');
export default appStorage;
// memoryStorage.js
const memoryStorage = new Map();
export default memoryStorage;
import globalStorage from 'std:kv-storage';
import appStorage from './appStorage';
import memoryStorage from './memoryStorage';

I would indeed only expect the default and a StorageArea named export.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api A proposal for changing the API surface
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants