@pradip1995/segment-primitives 0.4.14 → 0.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,26 +1,26 @@
1
- export const WISHLIST_UPDATED_EVENT = "wishlist:updated"
2
-
3
- export type WishlistUpdatedDetail = {
4
- delta?: number
5
- count?: number
6
- }
7
-
8
- export function nextWishlistCount(
9
- current: number,
10
- detail?: WishlistUpdatedDetail | null
11
- ): number {
12
- const base = Number.isFinite(current) ? Math.max(0, Math.trunc(current)) : 0
13
- if (!detail) return base
14
- if (typeof detail.count === "number" && Number.isFinite(detail.count)) {
15
- return Math.max(0, Math.trunc(detail.count))
16
- }
17
- if (typeof detail.delta === "number" && Number.isFinite(detail.delta)) {
18
- return Math.max(0, base + Math.trunc(detail.delta))
19
- }
20
- return base
21
- }
22
-
23
- export function dispatchWishlistUpdated(detail: WishlistUpdatedDetail) {
24
- if (typeof window === "undefined") return
25
- window.dispatchEvent(new CustomEvent(WISHLIST_UPDATED_EVENT, { detail }))
26
- }
1
+ export const WISHLIST_UPDATED_EVENT = "wishlist:updated"
2
+
3
+ export type WishlistUpdatedDetail = {
4
+ delta?: number
5
+ count?: number
6
+ }
7
+
8
+ export function nextWishlistCount(
9
+ current: number,
10
+ detail?: WishlistUpdatedDetail | null
11
+ ): number {
12
+ const base = Number.isFinite(current) ? Math.max(0, Math.trunc(current)) : 0
13
+ if (!detail) return base
14
+ if (typeof detail.count === "number" && Number.isFinite(detail.count)) {
15
+ return Math.max(0, Math.trunc(detail.count))
16
+ }
17
+ if (typeof detail.delta === "number" && Number.isFinite(detail.delta)) {
18
+ return Math.max(0, base + Math.trunc(detail.delta))
19
+ }
20
+ return base
21
+ }
22
+
23
+ export function dispatchWishlistUpdated(detail: WishlistUpdatedDetail) {
24
+ if (typeof window === "undefined") return
25
+ window.dispatchEvent(new CustomEvent(WISHLIST_UPDATED_EVENT, { detail }))
26
+ }