use-broadcast-ts
Advanced tools
Comparing version 1.5.0 to 1.6.0
@@ -284,2 +284,3 @@ 'use strict'; | ||
tabs.push(new_id); | ||
options == null ? void 0 : options.onTabsChange == null ? void 0 : options.onTabsChange(tabs); | ||
channel.postMessage({ | ||
@@ -325,2 +326,3 @@ action: 'add_new_tab', | ||
tabs.splice(index, 1); | ||
options == null ? void 0 : options.onTabsChange == null ? void 0 : options.onTabsChange(tabs); | ||
} | ||
@@ -336,3 +338,3 @@ } | ||
tabs.splice(0, tabs.length, ...e.data.tabs); | ||
options == null ? void 0 : options.onBecomeMain == null ? void 0 : options.onBecomeMain(); | ||
options == null ? void 0 : options.onBecomeMain == null ? void 0 : options.onBecomeMain(id); | ||
} | ||
@@ -358,3 +360,3 @@ } | ||
isSynced = true; | ||
options == null ? void 0 : options.onBecomeMain == null ? void 0 : options.onBecomeMain(); | ||
options == null ? void 0 : options.onBecomeMain == null ? void 0 : options.onBecomeMain(id); | ||
} | ||
@@ -361,0 +363,0 @@ }, (_options$mainTimeout = options == null ? void 0 : options.mainTimeout) != null ? _options$mainTimeout : 100); |
@@ -21,4 +21,10 @@ import { StateCreator, StoreMutatorIdentifier } from 'zustand'; | ||
* Callback when this tab / window becomes the main tab / window | ||
* Triggered only in the main tab / window | ||
*/ | ||
onBecomeMain?: () => void; | ||
onBecomeMain?: (id: number) => void; | ||
/** | ||
* Callback when a new tab is opened / closed | ||
* Triggered only in the main tab / window | ||
*/ | ||
onTabsChange?: (ids: number[]) => void; | ||
}; | ||
@@ -25,0 +31,0 @@ /** |
{ | ||
"name": "use-broadcast-ts", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "Use the Broadcast Channel API in React easily with hooks or Zustand, and Typescript!", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -161,6 +161,13 @@ # use-broadcast-ts | ||
Type: `() => void` | ||
Type: `(id: number) => void` | ||
A callback that will be called when the tab becomes the main tab. | ||
##### options.onTabsChange | ||
Type: `(tabs: number[]) => void` | ||
A callback that will be called when the number of tabs changes. | ||
Only triggered on the main tab. | ||
### useBroadcast (hooks) | ||
@@ -167,0 +174,0 @@ |
@@ -25,4 +25,11 @@ import { StateCreator, StoreMutatorIdentifier } from 'zustand'; | ||
* Callback when this tab / window becomes the main tab / window | ||
* Triggered only in the main tab / window | ||
*/ | ||
onBecomeMain?: () => void; | ||
onBecomeMain?: (id: number) => void; | ||
/** | ||
* Callback when a new tab is opened / closed | ||
* Triggered only in the main tab / window | ||
*/ | ||
onTabsChange?: (ids: number[]) => void; | ||
}; | ||
@@ -200,2 +207,4 @@ | ||
options?.onTabsChange?.(tabs); | ||
channel.postMessage({ action: 'add_new_tab', id: new_id } as Message); | ||
@@ -240,2 +249,4 @@ | ||
tabs.splice(index, 1); | ||
options?.onTabsChange?.(tabs); | ||
} | ||
@@ -252,3 +263,3 @@ } | ||
options?.onBecomeMain?.(); | ||
options?.onBecomeMain?.(id); | ||
} | ||
@@ -272,3 +283,3 @@ } | ||
options?.onBecomeMain?.(); | ||
options?.onBecomeMain?.(id); | ||
} | ||
@@ -275,0 +286,0 @@ }, options?.mainTimeout ?? 100); |
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
44025
1339
251