use-broadcast-ts
Advanced tools
Comparing version 1.2.3 to 1.2.4
@@ -164,2 +164,6 @@ 'use strict'; | ||
/** | ||
* Types | ||
*/ | ||
/** | ||
* Handle the Zustand set function | ||
@@ -170,15 +174,31 @@ * Trigger a postMessage to all the other tabs | ||
/** | ||
* Update the state | ||
* Get the previous states | ||
*/ | ||
const previous = get(); | ||
/** | ||
* Update the states | ||
*/ | ||
set(...args); | ||
/** | ||
* Get the state to send | ||
* Get the fresh states | ||
*/ | ||
const state = args.reduce((obj, item) => obj = { | ||
...obj, | ||
...item | ||
const updated = get(); | ||
/** | ||
* Get the states that changed | ||
*/ | ||
const state = Object.entries(updated).reduce((obj, [key, val]) => { | ||
if (previous[key] !== val) { | ||
obj = { | ||
...obj, | ||
[key]: val | ||
}; | ||
} | ||
return obj; | ||
}, {}); | ||
/** | ||
* Send the state to all the other tabs | ||
* Send the states to all the other tabs | ||
*/ | ||
@@ -185,0 +205,0 @@ channel.postMessage(state); |
{ | ||
"name": "use-broadcast-ts", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "Use the Broadcast Channel API in React easily with hooks or Zustand, and Typescript!", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -58,2 +58,7 @@ import { StateCreator, StoreMutatorIdentifier } from 'zustand'; | ||
/** | ||
* Types | ||
*/ | ||
type Item = { [key: string]: unknown }; | ||
/** | ||
* Handle the Zustand set function | ||
@@ -64,15 +69,28 @@ * Trigger a postMessage to all the other tabs | ||
/** | ||
* Update the state | ||
* Get the previous states | ||
*/ | ||
const previous = get() as Item; | ||
/** | ||
* Update the states | ||
*/ | ||
set(...args); | ||
type Item = { [key: string]: unknown }; | ||
/** | ||
* Get the fresh states | ||
*/ | ||
const updated = get() as Item; | ||
/** | ||
* Get the state to send | ||
* Get the states that changed | ||
*/ | ||
const state = args.reduce((obj, item) => (obj = { ...obj, ...(item as Item) }), {} as Item); | ||
const state = Object.entries(updated).reduce((obj, [key, val]) => { | ||
if (previous[key] !== val) { | ||
obj = { ...obj, [key]: val }; | ||
} | ||
return obj; | ||
}, {} as Item); | ||
/** | ||
* Send the state to all the other tabs | ||
* Send the states to all the other tabs | ||
*/ | ||
@@ -99,3 +117,3 @@ channel.postMessage(state); | ||
*/ | ||
const state = Object.entries(get() as s).reduce((obj, [key, val]) => { | ||
const state = Object.entries(get() as Item).reduce((obj, [key, val]) => { | ||
if (typeof val !== 'function' && typeof val !== 'symbol') { | ||
@@ -102,0 +120,0 @@ obj = { ...obj, [key]: val }; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33143
970