Skip to content

Commit

Permalink
updated use hook to now allow pulling in the entire object
Browse files Browse the repository at this point in the history
  • Loading branch information
sghsri committed Apr 24, 2024
1 parent af44c78 commit caf6327
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chrome-extension-toolkit",
"version": "0.0.66",
"version": "0.0.67",
"description": "A template for creating npm packages using TypeScript and VSCode",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
5 changes: 3 additions & 2 deletions src/storage/createStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export type Store<T = {}> = {

/**
* A react hook that allows you to get and set the value of the specified key in the store from a functional component.
* @param key the key to get the value of
* @param key the key to get the value of or null to get the entire store
* @returns a tuple containing the value of the specified key, and a function to set the value
*/
use<K extends keyof T | null, D extends K extends keyof T ? Serializable<T[K]> : T>(
Expand All @@ -92,7 +92,7 @@ export type Store<T = {}> = {

/**
* A react hook that allows you to get and set the value of the specified key in the store from a functional component.
* @param key the key to get the value of
* @param key the key to get the value of or null to get the entire store
* @param defaultValue the default value to use if the key is not already set
*/
use<K extends keyof T | null>(
Expand Down Expand Up @@ -320,6 +320,7 @@ function createStore<T>(
const onChanged = (change: DataChange<T>) => {
const newValue: any = { ...value };
newValue[change.key] = change.newValue;
setValue(newValue);
};
// @ts-ignore
Object.keys(defaults).forEach(k => store.subscribe(k, onChanged));
Expand Down

1 comment on commit caf6327

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines Statements Branches Functions
Coverage: 8%
8.62% (27/313) 13.92% (11/79) 9.21% (7/76)

Please sign in to comment.