A lightweight abstraction between Svelte stores and Chrome extension storage.

Overview

Svelte Chrome Storage

A lightweight abstraction between Svelte stores and Chrome extension storage.

This library makes data synchronization of background and popup scripts super simple, data changed in one is immediately reflected in the other. 🚀


NPM version NPM Publish

Installation

Install:

npm i svelte-chrome-storage

Usage

Reactive Syntax

<script>
    import {chromeStorageLocal} from "svelte-chrome-storage"
    
    let message = chromeStorageLocal("message")
    $message = "Hello, World!"
</script>

<!-- Any chrome storage updates are reactive! -->
<p>{$message}</p>

Pub-sub Syntax

<script>
    import {chromeStorageSync} from "svelte-chrome-storage"
    
    let message = chromeStorageSync("message")
    message.subscribe(newMessage => console.log(newMessage))
    message.set("Hello, World!")
</script>

The examples above set the message key on their respective chrome storage areas.

Values changed using the chrome.storage api are also reflected.

chrome.storage.local.set({message: "Hello, World!"})

Contributions

Feel free to open any issues or pull requests for any changes you'd like to see.

You might also like...

Simple and lightweight form validation for Svelte with no dependencies.

Svelidate Simple and lightweight form validation for Svelte with no dependencies Installation // npm npm install svelidate // yarn yarn add svelidate

Dec 28, 2022

This monorepo stores all code and assets of all projects with which we develop regels.overheid.nl

Welcome Introduction In 2021 Utrecht started developing the Virtual Income Desk with Open Rules. An initiative with the aim for citizens to always and

Dec 8, 2022

This is a project that add, stores and deletes current book in the library

Project Name Awesome books: with ES6 Description the project. In this project, I restructured my Awesome books app code. The goal was to make it more

Nov 11, 2022

Exploit chrome's profile sync for free cloud storage

BookmarkFS - the dumbest project i've ever made Exploits the google chrome bookmark sync service to store files for free Installation and usage Go to

Dec 30, 2022

Google-reviews-crawler - A simple Playwright crawler that stores Google Maps Place/Business reviews to a JSON file.

google-reviews-crawler A simple Playwright crawler that stores Google Maps Place/Business reviews to a JSON file. Usage Clone the repo, install the de

Oct 26, 2022

This Project is basically provides a cloud based solution for the medical stores so they can manage their inventory, expiry, billbook & credits on a single platform

This Project is basically provides a cloud based solution for the medical stores so they can manage their inventory, expiry, billbook & credits on a single platform

Jul 11, 2022

Recoil Sync stores for Next.js

recoil-sync-next Recoil Sync stores for Next.js Features URL Persistence Syncing an atom with the browser URL. Session Storage Persistence Synced with

Dec 28, 2022

A JavaScript library stores the form-data to the localstorage so you don't have to fill the form again.

A JavaScript library stores the form-data to the localstorage so you don't have to fill the form again.

form-storage A JavaScript library stores the form-data to the localstorage so you don't have to fill the form again. Installation via npm npm install

Dec 10, 2022

StarkNet support extension for VSCode. Visualize StarkNet contracts: view storage variables, external and view functions, and events.

StarkNet support extension for VSCode. Visualize StarkNet contracts: view storage variables, external and view functions, and events.

StarkNet Explorer extension This VSCode extension quickly shows relevant aspects of StarkNet contracts: Storage variables of the current contract, and

Nov 4, 2022
Comments
  • Store value is undefined on initial use

    Store value is undefined on initial use

    When obtaining a value that was set before the current component initializes, it is possible to first read an undefined value from the store. Eventually the value is set and the subscribers then receive the correct value.

    To reproduce this, set a local value in the background process:

    // background.ts
    chrome.runtime.onInstalled.addListener(() => {
    	chrome.storage.local.set({"test": 1337})
    }
    

    Then in your popup component, immediately subsribe to the value:

    <script lang="ts">
        import {chromeStorageLocal} from "svelte-chrome-storage/dist/chrome-storage-store-adapter"
    
        let testStore = chromeStorageLocal<number>("test")
        $: console.log("$testStore:", $testStore)
    </script>
    

    In the console of the popup I get

    index.js:6 $testStore: undefined
    index.js:6 $testStore: 1337
    

    I ran into this when attempting to do a comparison on a store value and it was not as expected.

    I did confirm that if you check the value using setTimeout after a short wait, the first read on the value is correct, indicating that it is a timing/initialization issue and not an issue with the first read per-se.

    opened by freb 1
  • Cannot use to create a custom store

    Cannot use to create a custom store

    This library appeared to be exactly what I was looking for (and trying to implement myself), but as I tried to use it I ran into issues.

    My goal is to keep my store strongly typed and provide setters for each field that should be editable. Something like the following:

    const Key = "settings"
    
    type Settings = {
    	recording: boolean;
    	recordTabId: string;
    	onSettingsPage: boolean;
    	settingsUrl: string;
    }
    
    function settingsStore() {
    	// Causes more issues
    	// const { subscribe, update } = chromeStorageLocal<Settings>(Key)
    
    	const settings = chromeStorageLocal<Settings>(Key)
    
    	return {
    		subscribe: settings.subscribe,
    		startRecording: () => settings.update(state => ({...state, recording: true})),
    		stopRecording: () => settings.update(state => ({...state, recording: false})),
    		setRecordTabId: (id: string) => settings.update(state => ({...state, recordTabId: id})),
    		clearRecordTabId: () => settings.update(state => ({...state, recordTabId: ""})),
    	}
    }
    

    Doing this, I run into issues where this is not defined when subscribing. If I pull the subscribe and update methods off of chromeStorageLocal, I run into similar issues when calling update from my setters (i.e. update(...) instead of settings.update(...)).

    I was going to try extending the ChromeStorageStoreAdapter class, but it is not exported.

    Likely this approach just is not compatible with the library. And assuming it isn't and isn't meant to be, I'm wondering if you have any other guidance on a way to type the store with an object and allow callers to set individual keys without having to pass back in the entire object themselves.

    I'm trying to avoid doing the following from the callers:

    let settingsStore = chromeStorageLocal<Settings>(Key)
    settingsStore.update(state => ({...state, recording: false}))
    
    opened by freb 1
  • Could not find a declaration file for module

    Could not find a declaration file for module

    I'm doing the following import as instructed by the README:

    import {chromeStorageLocal} from "svelte-chrome-storage"
    

    But chromeStorageLocal has type any because of the error:

    Could not find a declaration file for module 'svelte-chrome-storage
    

    Things work fine when importing from the dist folder:

    import {chromeStorageLocal} from "svelte-chrome-storage/dist/chrome-storage-store-adapter"
    

    vscode is producing the error.

    opened by freb 0
Releases(v0.1.8_2)
Owner
Shaun Wild
I love Kotlin!
Shaun Wild
An abstraction layer on top of @replit/crosis that makes Repl connection management and operations so easy, a Furret could do it! 🎉

Crosis4Furrets An abstraction layer on top of @replit/crosis that makes Repl connection management and operations so easy, a Furret could do it! ?? In

Ray 18 Dec 29, 2022
A Promise-compatible abstraction that defers resolving/rejecting promises to another closure.

Deferred Promise The DeferredPromise class is a Promise-compatible abstraction that defers resolving/rejecting promises to another closure. This class

Open Draft 21 Dec 15, 2022
A Svelte parser that compiles to Mitosis JSON, allowing you to write Svelte components once and compile to every framework.

Sveltosis Still in development A Svelte parser that compiles to Mitosis JSON, allowing you to write Svelte components once and compile to every framew

sveltosis 70 Nov 24, 2022
Tenzi is a dice game. The player needs to roll dice until they are all the same. Clicking on a dice, freezes it at its current value between rolls. Best scores are saved to local storage.

Roll until all dice are the same Try me! Technologies Used Description Tenzi is a dice game used to demonstrate the use of React Hooks (useState, useE

Michael Kolesidis 7 Nov 23, 2022
Eth-explorers-extension - Chrome extension to open Ethereum addresses & transaction hash from any page on popular explorers + dashboards

eth-explorers-extension(s) This repository contains two folders with two extensions that work for address and transactions respectively. 1. eth-addres

Apoorv Lathey 71 Jan 6, 2023
Lightweight (< 2.3kB gzipped) and performant natural sorting of arrays and collections by differentiating between unicode characters, numbers, dates, etc.

fast-natural-order-by Lightweight (< 2.3kB gzipped) and performant natural sorting of arrays and collections by differentiating between unicode charac

Shelf 5 Nov 14, 2022
A remote nodejs Cache Server, for you to have your perfect MAP Cache Saved and useable remotely. Easy Server and Client Creations, fast, stores the Cache before stopping and restores it again!

remote-map-cache A remote nodejs Cache Server, for you to have your perfect MAP Cache Saved and useable remotely. Easy Server and Client Creations, fa

Tomato6966 8 Oct 31, 2022
🍭 search-buddy ultra lightweight javascript plugin that can help you create instant search and/or facilitate navigation between pages.

?? search-buddy search-buddy is an open‑source ultra lightweight javascript plugin (* <1kb). It can help you create instant search and/or facilitate n

Michael 4 Jun 16, 2022
A Gun DB extension that ships secure* ephemeral messaging between Gun peers using Bugout, secured by Gun's SEA suite

Bugoff A Gun DB extension that ships secure* ephemeral messaging between Gun peers using Bugout, secured by Gun's SEA suite About Bugoff creates an SE

Daniel Raeder 14 Nov 12, 2022