@coalesce.dev/store-worker
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

Shared Store - Worker

@coalesce.dev/store-worker

This package provides a library used to create the worker component of a shared store.

Usage

Create a file to be used as the entry point of the worker. For example, here is a file that sets up a store using the HTTP plugin:

import { SharedStore } from '@coalesce.dev/store-worker';
import { schema } from '../schema';
import { HttpPlugin } from '@coalesce.dev/store-plugins-http';

const store = new SharedStore('exampleStoreId', schema, {
  ...HttpPlugin,
});

This worker can then be loaded using the @coalesce.dev/store-client package:

import { SharedStoreClient } from '@coalesce.dev/store-client';
import { schema } from '../schema';

export const storeClient = new SharedStoreClient(
  () =>
    new SharedWorker(new URL('../worker', import.meta.url), {
      name: 'example-worker',
    }),
  schema
);

The state of the worker will periodically be persisted in an IndexedDB database shortly after any mutations. When the worker is restarted, it will load this previous state.

Readme

Keywords

none

Package Sidebar

Install

npm i @coalesce.dev/store-worker

Weekly Downloads

1

Version

0.1.4

License

GNU GPLv3

Unpacked Size

12.5 kB

Total Files

11

Last publish

Collaborators

  • matt.meeks