Coder Social home page Coder Social logo

svelte-chrome-storage's People

Contributors

shaun-wild avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

svelte-chrome-storage's Issues

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.

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.

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}))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.