npm

svelte-crossorigin-store
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

svelte-crossorigin-store

Share your Svelte store across origins, including iFrames.

License Version Build

Features

  • made for Svelte, works anywhere
  • synchronizes store across multiple origins
  • supports iFrames
  • tiny (~450 bytes minified+gzipped)

Installation

npm install svelte-crossorigin-store

Usage

Import

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>

⚠️ Take note that the API doesn't follow a publisher/subscriber approach. Hence, you need to make sure that instances are not initialized with the same value. Otherwise, an infinite loop will occur!

API

createStore

createStore<T>(initialValue?: T, {
	allowedOrigins?: string[];
	id?: string;
	iframeSelector?: string;
	onChange?: (value: any) => void;
});

Methods

The created store exposes the same API methods like a writable svelte/store:

  • set()
  • update()
  • subscribe()

Please refer to the official documentation.

License

This work is licensed under The MIT License.

Package Sidebar

Install

npm i svelte-crossorigin-store

Weekly Downloads

3

Version

0.1.1

License

none

Unpacked Size

6.25 kB

Total Files

5

Last publish

Collaborators

  • idleberg