Skip to content

cymkd/svelte-websocket-store

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Svelte v3 npm License minified size downloads GitHub Issues Build Status Styled with prettier Commitizen friendly Known Vulnerabilities Coverage Status Tested with TestCafe Netlify Status

svelte-websocket-store

Svelte store with a websocket backend

import websocketStore from "svelte-websocket-store";

const initialValue = { };
export const myStore = websocketStore("wss://mydomain.com/ws1", initialValue, ['option 1', 'option 2']);


// send JSON to websocket server
$myStore = { content: "to be saved", other_values: "all" };


// receive JSON from server (push)
let response = $myStore;

API

Table of Contents

websocketStore

Create a writable store based on a web-socket. Data is transferred as JSON. Keeps socket open (reopens if closed) as long as there are subscriptions.

Parameters

  • url string the WebSocket url
  • initialValue any store value used before 1st. response from server is present
  • socketOptions Array<string> transparently passed to the WebSocket constructor

Returns Store

install

With npm do:

npm install svelte-websocket-store

With yarn do:

yarn add svelte-websocket-store

run tests

export BROWSER=safari|chrome|...
npm|yarn test

license

BSD-2-Clause

About

svelte store with a websocket backend

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 89.4%
  • Svelte 7.7%
  • HTML 2.9%