Share your Svelte store across origins, including iFrames.
Features
- made for Svelte, works anywhere
- synchronizes store across multiple origins
- supports iFrames
- tiny (~450 bytes minified+gzipped)
npm install svelte-crossorigin-store
import { createStore } from 'svelte-crossorigin-store';
const store = createStore('Hello, world');
const unsubscribe = store.subscribe(value => console.log('State updated:', value));
Or, in your Svelte component:
<script>
import { createStore } from 'svelte-crossorigin-store';
const store = createStore('Hello, world');
</script>
<p>Current State: {$store}</p>
createStore<T>(initialValue?: T, {
allowedOrigins?: string[];
id?: string;
iframeSelector?: string;
onChange?: (value: any) => void;
});
The created store exposes the same API methods like a writable svelte/store
:
set()
update()
subscribe()
Please refer to the official documentation.
This work is licensed under The MIT License.