Skip to content
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

Add a readOnly function to svelte/store #5872

Closed
wants to merge 1 commit into from

Conversation

Crisfole
Copy link
Contributor

@Crisfole Crisfole commented Jan 9, 2021

This is a single, tree-shakable function added to the svelte/store runtime. I re-write this for almost every project, it's a handy way to create a custom store and prevent directly modifying a store from outside a module. The custom-element tests all failed, and I couldn't work out how to add a test for this since the ideal test would be something like:

import {writable, readOnly} from 'svelte/store';
function test() {
  const writableStore = writable(null);
  const readableStore = readOnly(writableStore);

  assertNotNull(writableStore.set);
  assertFalsey(readableStore.set);
}

I'm happy to make any changes needed, or for this to be rejected, but the easiest way to get the conversation going is with a PR.

@Crisfole
Copy link
Contributor Author

Someone suggested using derived with the id function. That's a similar result, just more complex...

@benmccann benmccann changed the title Add a readOnly function to svelte/store and documentation Add a readOnly function to svelte/store Jan 18, 2021
@stale
Copy link

stale bot commented Aug 16, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale-bot label Aug 16, 2021
@bluwy
Copy link
Member

bluwy commented Aug 17, 2021

Looks like #6518 duplicates this and already had two approvals there. Code changes are similar too.

@stale stale bot removed the stale-bot label Aug 17, 2021
@Crisfole Crisfole closed this Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants