@solid-primitives/page-visibility
Advanced tools
Comparing version
@@ -1,4 +0,3 @@ | ||
import { sharedConfig } from 'solid-js'; | ||
import { createSharedRoot } from '@solid-primitives/rootless'; | ||
import { createHydrateSignal } from '@solid-primitives/utils'; | ||
import { createHydratableSingletonRoot } from '@solid-primitives/rootless'; | ||
import { createHydratableSignal } from '@solid-primitives/utils'; | ||
import { makeEventListener } from '@solid-primitives/event-listener'; | ||
@@ -8,11 +7,9 @@ | ||
var createPageVisibility = () => { | ||
const isVisible = () => document.visibilityState === "visible"; | ||
const [state, setState] = createHydrateSignal(true, isVisible); | ||
const update = () => setState(isVisible()); | ||
makeEventListener(document, "visibilitychange", update); | ||
return state; | ||
const checkVisibility = () => document.visibilityState === "visible"; | ||
const [isVisible, setVisible] = createHydratableSignal(true, checkVisibility); | ||
makeEventListener(document, "visibilitychange", () => setVisible(checkVisibility)); | ||
return isVisible; | ||
}; | ||
var sharedPageVisibility = /* @__PURE__ */ createSharedRoot(createPageVisibility); | ||
var usePageVisibility = () => sharedConfig.context ? createPageVisibility() : sharedPageVisibility(); | ||
var usePageVisibility = /* @__PURE__ */ createHydratableSingletonRoot(createPageVisibility); | ||
export { createPageVisibility, usePageVisibility }; |
@@ -19,3 +19,3 @@ import { Accessor } from 'solid-js'; | ||
* | ||
* This is a [shared root primitive](https://github.com/solidjs-community/solid-primitives/tree/main/packages/rootless#createSharedRoot) except if during hydration. | ||
* This is a [singleton root primitive](https://github.com/solidjs-community/solid-primitives/tree/main/packages/rootless#createSingletonRoot) except if during hydration. | ||
* | ||
@@ -22,0 +22,0 @@ * @example |
@@ -1,4 +0,3 @@ | ||
import { sharedConfig } from 'solid-js'; | ||
import { createSharedRoot } from '@solid-primitives/rootless'; | ||
import { createHydrateSignal } from '@solid-primitives/utils'; | ||
import { createHydratableSingletonRoot } from '@solid-primitives/rootless'; | ||
import { createHydratableSignal } from '@solid-primitives/utils'; | ||
import { makeEventListener } from '@solid-primitives/event-listener'; | ||
@@ -8,11 +7,9 @@ | ||
var createPageVisibility = () => { | ||
const isVisible = () => document.visibilityState === "visible"; | ||
const [state, setState] = createHydrateSignal(true, isVisible); | ||
const update = () => setState(isVisible()); | ||
makeEventListener(document, "visibilitychange", update); | ||
return state; | ||
const checkVisibility = () => document.visibilityState === "visible"; | ||
const [isVisible, setVisible] = createHydratableSignal(true, checkVisibility); | ||
makeEventListener(document, "visibilitychange", () => setVisible(checkVisibility)); | ||
return isVisible; | ||
}; | ||
var sharedPageVisibility = /* @__PURE__ */ createSharedRoot(createPageVisibility); | ||
var usePageVisibility = () => sharedConfig.context ? createPageVisibility() : sharedPageVisibility(); | ||
var usePageVisibility = /* @__PURE__ */ createHydratableSingletonRoot(createPageVisibility); | ||
export { createPageVisibility, usePageVisibility }; |
@@ -1,4 +0,3 @@ | ||
import 'solid-js'; | ||
import '@solid-primitives/rootless'; | ||
import '@solid-primitives/utils'; | ||
import { createHydratableSingletonRoot } from '@solid-primitives/rootless'; | ||
import { trueFn } from '@solid-primitives/utils'; | ||
import '@solid-primitives/event-listener'; | ||
@@ -9,7 +8,7 @@ | ||
{ | ||
return () => true; | ||
return trueFn; | ||
} | ||
}; | ||
var usePageVisibility = () => () => false ; | ||
var usePageVisibility = /* @__PURE__ */ createHydratableSingletonRoot(createPageVisibility); | ||
export { createPageVisibility, usePageVisibility }; |
{ | ||
"name": "@solid-primitives/page-visibility", | ||
"version": "2.0.6", | ||
"version": "2.0.7", | ||
"description": "Primitive to track page visibility", | ||
@@ -94,4 +94,4 @@ "author": "David Di Biase", | ||
"@solid-primitives/event-listener": "^2.2.8", | ||
"@solid-primitives/rootless": "^1.2.6", | ||
"@solid-primitives/utils": "^5.4.0" | ||
"@solid-primitives/rootless": "^1.3.0", | ||
"@solid-primitives/utils": "^5.5.0" | ||
}, | ||
@@ -98,0 +98,0 @@ "peerDependencies": { |
@@ -13,3 +13,3 @@ <p> | ||
- [`createPageVisibility`](#createPageVisibility) - Creates a signal with a boolean value identifying the page visibility state | ||
- [`usePageVisibility`](#usePageVisibility) - A [shared-root](https://github.com/solidjs-community/solid-primitives/tree/main/packages/rootless#createSharedRoot) alternative. | ||
- [`usePageVisibility`](#usePageVisibility) - A [singleton root](https://github.com/solidjs-community/solid-primitives/tree/main/packages/rootless#createSingletonRoot) alternative. | ||
@@ -42,3 +42,3 @@ ## Installation | ||
`usePageVisibility` is a [shared root](https://github.com/solidjs-community/solid-primitives/tree/main/packages/rootless#createSharedRoot) primitive. It is providing the same signal as `createPageVisibility`, but the event-listener and the signal are shared between dependents, making it more optimized to use in multiple places at once. | ||
`usePageVisibility` is a [singleton root](https://github.com/solidjs-community/solid-primitives/tree/main/packages/rootless#createSingletonRoot) primitive. It is providing the same signal as `createPageVisibility`, but the event-listener and the signal are shared between dependents, making it more optimized to use in multiple places at once. | ||
@@ -45,0 +45,0 @@ ### How to use it |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
10222
-3.06%100
-12.28%