@choksheak/react-utils 0.1.2 → 0.1.4
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.
- package/docs/classes/sharedState.SharedStateConfig.html +3 -3
- package/docs/functions/sharedState.sharedState.html +1 -1
- package/docs/functions/sharedState.useSharedState.html +2 -2
- package/docs/functions/sharedState.useSharedStateSetter.html +2 -2
- package/docs/functions/sharedState.useSharedStateValue.html +2 -2
- package/docs/types/sharedState.SharedState.html +2 -2
- package/docs/variables/fetcher.fetcher.html +1 -1
- package/docs/variables/fetcher.fetcherWithRetries.html +1 -1
- package/fetcher.d.mts +8 -0
- package/fetcher.d.ts +4 -0
- package/fetcher.js +51 -0
- package/fetcher.mjs +15 -0
- package/index.d.mts +2 -0
- package/index.d.ts +0 -0
- package/index.js +4 -0
- package/index.mjs +12 -0
- package/package.json +1 -1
- package/sharedState.d.mts +55 -0
- package/sharedState.d.ts +53 -0
- package/sharedState.js +194 -0
- package/sharedState.mjs +165 -0
- package/src/sharedState.ts +21 -11
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>SharedStateConfig | Chok’s React Utilities</title><meta name="description" content="Documentation for Chok’s React Utilities"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">Chok’s React Utilities</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="../modules/sharedState.html">sharedState</a></li><li><a href="" aria-current="page">SharedStateConfig</a></li></ul><h1>Class SharedStateConfig</h1></div><section class="tsd-panel tsd-comment"><div class="tsd-comment tsd-typography"><p>These values are configurable by the user at any time.</p>
|
|
2
|
-
</div></section><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/
|
|
2
|
+
</div></section><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/0e9a783f3018e49ee957d3c1f6b6cab46706cc3c/src/sharedState.ts#L23">sharedState.ts:23</a></li></ul></aside><section class="tsd-panel-group tsd-index-group"><section class="tsd-panel tsd-index-panel"><details class="tsd-index-content tsd-accordion" open><summary class="tsd-accordion-summary tsd-index-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h5 class="tsd-index-heading uppercase">Index</h5></summary><div class="tsd-accordion-details"><section class="tsd-index-section"><h3 class="tsd-index-heading">Constructors</h3><div class="tsd-index-list"><a href="#constructor" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Constructor"><use href="../assets/icons.svg#icon-512"></use></svg><span>constructor</span></a>
|
|
3
3
|
</div></section><section class="tsd-index-section"><h3 class="tsd-index-heading">Properties</h3><div class="tsd-index-list"><a href="#defaultpersistexpiryms" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>default<wbr/>Persist<wbr/>Expiry<wbr/>Ms</span></a>
|
|
4
4
|
<a href="#lazyload" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>lazy<wbr/>Load</span></a>
|
|
5
5
|
</div></section></div></details></section></section><details class="tsd-panel-group tsd-member-group tsd-accordion" open><summary class="tsd-accordion-summary" data-key="section-Constructors"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h2>Constructors</h2></summary><section><section class="tsd-panel tsd-member"><h3 class="tsd-anchor-link" id="constructor"><span>constructor</span><a href="#constructor" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><ul class="tsd-signatures"><li class=""><div class="tsd-signature tsd-anchor-link" id="constructorsharedstateconfig"><span class="tsd-signature-keyword">new</span> <span class="tsd-kind-constructor-signature">SharedStateConfig</span><span class="tsd-signature-symbol">()</span><span class="tsd-signature-symbol">:</span> <a href="" class="tsd-signature-type tsd-kind-class">SharedStateConfig</a><a href="#constructorsharedstateconfig" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><h4 class="tsd-returns-title">Returns <a href="" class="tsd-signature-type tsd-kind-class">SharedStateConfig</a></h4></div></li></ul></section></section></details><details class="tsd-panel-group tsd-member-group tsd-accordion" open><summary class="tsd-accordion-summary" data-key="section-Properties"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h2>Properties</h2></summary><section><section class="tsd-panel tsd-member"><h3 class="tsd-anchor-link" id="defaultpersistexpiryms"><code class="tsd-tag">Static</code><span>default<wbr/>Persist<wbr/>Expiry<wbr/>Ms</span><a href="#defaultpersistexpiryms" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">defaultPersistExpiryMs</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span><span class="tsd-signature-symbol"> = MS_PER_DAY</span></div><div class="tsd-comment tsd-typography"><p>Default duration for persistence expiration in milliseconds.</p>
|
|
6
|
-
</div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/
|
|
6
|
+
</div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/0e9a783f3018e49ee957d3c1f6b6cab46706cc3c/src/sharedState.ts#L27">sharedState.ts:27</a></li></ul></aside></section><section class="tsd-panel tsd-member"><h3 class="tsd-anchor-link" id="lazyload"><code class="tsd-tag">Static</code><span>lazy<wbr/>Load</span><a href="#lazyload" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">lazyLoad</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol"> = false</span></div><div class="tsd-comment tsd-typography"><p>True to load from persistence only on mount, false (default) to load in
|
|
7
7
|
the top level scope when the shared state is defined.</p>
|
|
8
|
-
</div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/
|
|
8
|
+
</div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/0e9a783f3018e49ee957d3c1f6b6cab46706cc3c/src/sharedState.ts#L33">sharedState.ts:33</a></li></ul></aside></section></section></details></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h3>On This Page</h3></summary><div class="tsd-accordion-details"><details open class="tsd-accordion tsd-page-navigation-section"><summary class="tsd-accordion-summary" data-key="section-Constructors"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Constructors</summary><div><a href="#constructor"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Constructor"><use href="../assets/icons.svg#icon-512"></use></svg><span>constructor</span></a></div></details><details open class="tsd-accordion tsd-page-navigation-section"><summary class="tsd-accordion-summary" data-key="section-Properties"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Properties</summary><div><a href="#defaultpersistexpiryms"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>default<wbr/>Persist<wbr/>Expiry<wbr/>Ms</span></a><a href="#lazyload"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>lazy<wbr/>Load</span></a></div></details></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">Chok’s React Utilities</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
<!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>sharedState | Chok’s React Utilities</title><meta name="description" content="Documentation for Chok’s React Utilities"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">Chok’s React Utilities</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="../modules/sharedState.html">sharedState</a></li><li><a href="" aria-current="page">sharedState</a></li></ul><h1>Function sharedState</h1></div><section class="tsd-panel"><ul class="tsd-signatures"><li class=""><div class="tsd-signature tsd-anchor-link" id="sharedstate"><span class="tsd-kind-call-signature">sharedState</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#sharedstatet">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><br/> <span class="tsd-kind-parameter">defaultValue</span><span class="tsd-signature-symbol">:</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#sharedstatet">T</a><span class="tsd-signature-symbol">,</span><br/> <span class="tsd-kind-parameter">options</span><span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-symbol">{</span><br/> <span class="tsd-kind-property">indexedDbKey</span><span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">;</span><br/> <span class="tsd-kind-property">lazyLoad</span><span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">;</span><br/> <span class="tsd-kind-property">localStorageKey</span><span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">;</span><br/> <span class="tsd-kind-property">persistExpiryMs</span><span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">;</span><br/> <span class="tsd-signature-symbol">}</span><span class="tsd-signature-symbol">,</span><br/><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <a href="../types/sharedState.SharedState.html" class="tsd-signature-type tsd-kind-type-alias">SharedState</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#sharedstatet">T</a><span class="tsd-signature-symbol">></span><a href="#sharedstate" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><p>Create a new shared state object. Put this code at the top level scope:</p>
|
|
2
2
|
<p>const myState = sharedState<number>(0);</p>
|
|
3
|
-
</div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="sharedstatet"><span class="tsd-kind-type-parameter">T</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">defaultValue</span>: <a class="tsd-signature-type tsd-kind-type-parameter" href="#sharedstatet">T</a></span></li><li><span><code class="tsd-tag">Optional</code><span class="tsd-kind-parameter">options</span>: <span class="tsd-signature-symbol">{</span><br/> <span class="tsd-kind-property">indexedDbKey</span><span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">;</span><br/> <span class="tsd-kind-property">lazyLoad</span><span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">;</span><br/> <span class="tsd-kind-property">localStorageKey</span><span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">;</span><br/> <span class="tsd-kind-property">persistExpiryMs</span><span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">;</span><br/><span class="tsd-signature-symbol">}</span></span></li></ul></div><h4 class="tsd-returns-title">Returns <a href="../types/sharedState.SharedState.html" class="tsd-signature-type tsd-kind-type-alias">SharedState</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#sharedstatet">T</a><span class="tsd-signature-symbol">></span></h4><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/
|
|
3
|
+
</div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="sharedstatet"><span class="tsd-kind-type-parameter">T</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">defaultValue</span>: <a class="tsd-signature-type tsd-kind-type-parameter" href="#sharedstatet">T</a></span></li><li><span><code class="tsd-tag">Optional</code><span class="tsd-kind-parameter">options</span>: <span class="tsd-signature-symbol">{</span><br/> <span class="tsd-kind-property">indexedDbKey</span><span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">;</span><br/> <span class="tsd-kind-property">lazyLoad</span><span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">;</span><br/> <span class="tsd-kind-property">localStorageKey</span><span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">;</span><br/> <span class="tsd-kind-property">persistExpiryMs</span><span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">;</span><br/><span class="tsd-signature-symbol">}</span></span></li></ul></div><h4 class="tsd-returns-title">Returns <a href="../types/sharedState.SharedState.html" class="tsd-signature-type tsd-kind-type-alias">SharedState</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#sharedstatet">T</a><span class="tsd-signature-symbol">></span></h4><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/0e9a783f3018e49ee957d3c1f6b6cab46706cc3c/src/sharedState.ts#L122">sharedState.ts:122</a></li></ul></aside></div></li></ul></section></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">Chok’s React Utilities</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
<!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>useSharedState | Chok’s React Utilities</title><meta name="description" content="Documentation for Chok’s React Utilities"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">Chok’s React Utilities</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="../modules/sharedState.html">sharedState</a></li><li><a href="" aria-current="page">useSharedState</a></li></ul><h1>Function useSharedState</h1></div><section class="tsd-panel"><ul class="tsd-signatures"><li class=""><div class="tsd-signature tsd-anchor-link" id="usesharedstate"><span class="tsd-kind-call-signature">useSharedState</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatet">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><br/> <span class="tsd-kind-parameter">state</span><span class="tsd-signature-symbol">:</span> <a href="../types/sharedState.SharedState.html" class="tsd-signature-type tsd-kind-type-alias">SharedState</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatet">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">,</span><br/><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">[</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatet">T</a
|
|
1
|
+
<!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>useSharedState | Chok’s React Utilities</title><meta name="description" content="Documentation for Chok’s React Utilities"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">Chok’s React Utilities</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="../modules/sharedState.html">sharedState</a></li><li><a href="" aria-current="page">useSharedState</a></li></ul><h1>Function useSharedState</h1></div><section class="tsd-panel"><ul class="tsd-signatures"><li class=""><div class="tsd-signature tsd-anchor-link" id="usesharedstate"><span class="tsd-kind-call-signature">useSharedState</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatet">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><br/> <span class="tsd-kind-parameter">state</span><span class="tsd-signature-symbol">:</span> <a href="../types/sharedState.SharedState.html" class="tsd-signature-type tsd-kind-type-alias">SharedState</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatet">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">,</span><br/><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">[</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatet">T</a><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">next</span><span class="tsd-signature-symbol">:</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatet">T</a> <span class="tsd-signature-symbol">|</span> (<span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">prev</span><span class="tsd-signature-symbol">:</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatet">T</a><span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=></span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatet">T</a>)<span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=></span> <span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">]</span><a href="#usesharedstate" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><p>React hook for subscribing to a key in the global store.
|
|
2
2
|
const [my, setMy] = useSharedState(myState);</p>
|
|
3
|
-
</div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="usesharedstatet"><span class="tsd-kind-type-parameter">T</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">state</span>: <a href="../types/sharedState.SharedState.html" class="tsd-signature-type tsd-kind-type-alias">SharedState</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatet">T</a><span class="tsd-signature-symbol">></span></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-symbol">[</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatet">T</a
|
|
3
|
+
</div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="usesharedstatet"><span class="tsd-kind-type-parameter">T</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">state</span>: <a href="../types/sharedState.SharedState.html" class="tsd-signature-type tsd-kind-type-alias">SharedState</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatet">T</a><span class="tsd-signature-symbol">></span></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-symbol">[</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatet">T</a><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">next</span><span class="tsd-signature-symbol">:</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatet">T</a> <span class="tsd-signature-symbol">|</span> (<span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">prev</span><span class="tsd-signature-symbol">:</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatet">T</a><span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=></span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatet">T</a>)<span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=></span> <span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">]</span></h4><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/0e9a783f3018e49ee957d3c1f6b6cab46706cc3c/src/sharedState.ts#L200">sharedState.ts:200</a></li></ul></aside></div></li></ul></section></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">Chok’s React Utilities</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>useSharedStateSetter | Chok’s React Utilities</title><meta name="description" content="Documentation for Chok’s React Utilities"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">Chok’s React Utilities</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="../modules/sharedState.html">sharedState</a></li><li><a href="" aria-current="page">useSharedStateSetter</a></li></ul><h1>Function useSharedStateSetter</h1></div><section class="tsd-panel"><ul class="tsd-signatures"><li class=""><div class="tsd-signature tsd-anchor-link" id="usesharedstatesetter"><span class="tsd-kind-call-signature">useSharedStateSetter</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatesettert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><br/> <span class="tsd-kind-parameter">state</span><span class="tsd-signature-symbol">:</span> <a href="../types/sharedState.SharedState.html" class="tsd-signature-type tsd-kind-type-alias">SharedState</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatesettert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">,</span><br/><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">next</span><span class="tsd-signature-symbol">:</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatesettert">T</a> <span class="tsd-signature-symbol">|</span> (<span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">prev</span><span class="tsd-signature-symbol">:</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatesettert">T</a
|
|
2
|
-
</div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="usesharedstatesettert"><span class="tsd-kind-type-parameter">T</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">state</span>: <a href="../types/sharedState.SharedState.html" class="tsd-signature-type tsd-kind-type-alias">SharedState</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatesettert">T</a><span class="tsd-signature-symbol">></span></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">next</span><span class="tsd-signature-symbol">:</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatesettert">T</a> <span class="tsd-signature-symbol">|</span> (<span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">prev</span><span class="tsd-signature-symbol">:</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatesettert">T</a
|
|
1
|
+
<!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>useSharedStateSetter | Chok’s React Utilities</title><meta name="description" content="Documentation for Chok’s React Utilities"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">Chok’s React Utilities</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="../modules/sharedState.html">sharedState</a></li><li><a href="" aria-current="page">useSharedStateSetter</a></li></ul><h1>Function useSharedStateSetter</h1></div><section class="tsd-panel"><ul class="tsd-signatures"><li class=""><div class="tsd-signature tsd-anchor-link" id="usesharedstatesetter"><span class="tsd-kind-call-signature">useSharedStateSetter</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatesettert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><br/> <span class="tsd-kind-parameter">state</span><span class="tsd-signature-symbol">:</span> <a href="../types/sharedState.SharedState.html" class="tsd-signature-type tsd-kind-type-alias">SharedState</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatesettert">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">,</span><br/><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">next</span><span class="tsd-signature-symbol">:</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatesettert">T</a> <span class="tsd-signature-symbol">|</span> (<span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">prev</span><span class="tsd-signature-symbol">:</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatesettert">T</a><span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=></span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatesettert">T</a>)<span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=></span> <span class="tsd-signature-type">void</span><a href="#usesharedstatesetter" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><p>E.g. const setMy = useSharedStateSetter(myState)</p>
|
|
2
|
+
</div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="usesharedstatesettert"><span class="tsd-kind-type-parameter">T</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">state</span>: <a href="../types/sharedState.SharedState.html" class="tsd-signature-type tsd-kind-type-alias">SharedState</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatesettert">T</a><span class="tsd-signature-symbol">></span></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">next</span><span class="tsd-signature-symbol">:</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatesettert">T</a> <span class="tsd-signature-symbol">|</span> (<span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">prev</span><span class="tsd-signature-symbol">:</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatesettert">T</a><span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=></span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatesettert">T</a>)<span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=></span> <span class="tsd-signature-type">void</span></h4><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/0e9a783f3018e49ee957d3c1f6b6cab46706cc3c/src/sharedState.ts#L216">sharedState.ts:216</a></li></ul></aside></div></li></ul></section></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">Chok’s React Utilities</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>useSharedStateValue | Chok’s React Utilities</title><meta name="description" content="Documentation for Chok’s React Utilities"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">Chok’s React Utilities</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="../modules/sharedState.html">sharedState</a></li><li><a href="" aria-current="page">useSharedStateValue</a></li></ul><h1>Function useSharedStateValue</h1></div><section class="tsd-panel"><ul class="tsd-signatures"><li class=""><div class="tsd-signature tsd-anchor-link" id="usesharedstatevalue"><span class="tsd-kind-call-signature">useSharedStateValue</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatevaluet">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">state</span><span class="tsd-signature-symbol">:</span> <a href="../types/sharedState.SharedState.html" class="tsd-signature-type tsd-kind-type-alias">SharedState</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatevaluet">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatevaluet">T</a
|
|
2
|
-
</div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="usesharedstatevaluet"><span class="tsd-kind-type-parameter">T</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">state</span>: <a href="../types/sharedState.SharedState.html" class="tsd-signature-type tsd-kind-type-alias">SharedState</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatevaluet">T</a><span class="tsd-signature-symbol">></span></span></li></ul></div><h4 class="tsd-returns-title">Returns <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatevaluet">T</a
|
|
1
|
+
<!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>useSharedStateValue | Chok’s React Utilities</title><meta name="description" content="Documentation for Chok’s React Utilities"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">Chok’s React Utilities</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="../modules/sharedState.html">sharedState</a></li><li><a href="" aria-current="page">useSharedStateValue</a></li></ul><h1>Function useSharedStateValue</h1></div><section class="tsd-panel"><ul class="tsd-signatures"><li class=""><div class="tsd-signature tsd-anchor-link" id="usesharedstatevalue"><span class="tsd-kind-call-signature">useSharedStateValue</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatevaluet">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">state</span><span class="tsd-signature-symbol">:</span> <a href="../types/sharedState.SharedState.html" class="tsd-signature-type tsd-kind-type-alias">SharedState</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatevaluet">T</a><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatevaluet">T</a><a href="#usesharedstatevalue" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></div><div class="tsd-description"><div class="tsd-comment tsd-typography"><p>E.g. const my = useSharedStateValue(myState)</p>
|
|
2
|
+
</div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="usesharedstatevaluet"><span class="tsd-kind-type-parameter">T</span></span></li></ul></section><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">state</span>: <a href="../types/sharedState.SharedState.html" class="tsd-signature-type tsd-kind-type-alias">SharedState</a><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatevaluet">T</a><span class="tsd-signature-symbol">></span></span></li></ul></div><h4 class="tsd-returns-title">Returns <a class="tsd-signature-type tsd-kind-type-parameter" href="#usesharedstatevaluet">T</a></h4><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/0e9a783f3018e49ee957d3c1f6b6cab46706cc3c/src/sharedState.ts#L211">sharedState.ts:211</a></li></ul></aside></div></li></ul></section></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">Chok’s React Utilities</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
<!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>SharedState | Chok’s React Utilities</title><meta name="description" content="Documentation for Chok’s React Utilities"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">Chok’s React Utilities</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="../modules/sharedState.html">sharedState</a></li><li><a href="" aria-current="page">SharedState</a></li></ul><h1>Type Alias SharedState<T></h1></div><div class="tsd-signature"><span class="tsd-signature-keyword">type</span> <span class="tsd-kind-type-alias">SharedState</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#t">T</a><span class="tsd-signature-symbol">></span> <span class="tsd-signature-symbol">=</span> <span class="tsd-signature-symbol">{</span><br/> <a class="tsd-kind-property" href="#getsnapshot">getSnapshot</a><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">()</span> <span class="tsd-signature-symbol">=></span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#t">T</a
|
|
1
|
+
<!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>SharedState | Chok’s React Utilities</title><meta name="description" content="Documentation for Chok’s React Utilities"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">Chok’s React Utilities</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="../modules/sharedState.html">sharedState</a></li><li><a href="" aria-current="page">SharedState</a></li></ul><h1>Type Alias SharedState<T></h1></div><div class="tsd-signature"><span class="tsd-signature-keyword">type</span> <span class="tsd-kind-type-alias">SharedState</span><span class="tsd-signature-symbol"><</span><a class="tsd-signature-type tsd-kind-type-parameter" href="#t">T</a><span class="tsd-signature-symbol">></span> <span class="tsd-signature-symbol">=</span> <span class="tsd-signature-symbol">{</span><br/> <a class="tsd-kind-property" href="#getsnapshot">getSnapshot</a><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">()</span> <span class="tsd-signature-symbol">=></span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#t">T</a><span class="tsd-signature-symbol">;</span><br/> <a class="tsd-kind-property" href="#initdefaultvalueonce">initDefaultValueOnce</a><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">()</span> <span class="tsd-signature-symbol">=></span> <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">></span> <span class="tsd-signature-symbol">|</span> <span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">;</span><br/> <a class="tsd-kind-property" href="#initdone">initDone</a><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">;</span><br/> <a class="tsd-kind-property" href="#setvalue">setValue</a><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">next</span><span class="tsd-signature-symbol">:</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#t">T</a> <span class="tsd-signature-symbol">|</span> (<span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">prev</span><span class="tsd-signature-symbol">:</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#t">T</a><span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=></span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#t">T</a>)<span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=></span> <span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">;</span><br/> <a class="tsd-kind-property" href="#subscribe">subscribe</a><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">subscriber</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">()</span> <span class="tsd-signature-symbol">=></span> <span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=></span> <span class="tsd-signature-symbol">()</span> <span class="tsd-signature-symbol">=></span> <span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">;</span><br/><span class="tsd-signature-symbol">}</span></div><section class="tsd-panel"><h4>Type Parameters</h4><ul class="tsd-type-parameter-list"><li><span id="t"><span class="tsd-kind-type-parameter">T</span></span></li></ul></section><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/0e9a783f3018e49ee957d3c1f6b6cab46706cc3c/src/sharedState.ts#L107">sharedState.ts:107</a></li></ul></aside><section class="tsd-panel-group tsd-index-group"><section class="tsd-panel tsd-index-panel"><details class="tsd-index-content tsd-accordion" open><summary class="tsd-accordion-summary tsd-index-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h5 class="tsd-index-heading uppercase">Index</h5></summary><div class="tsd-accordion-details"><section class="tsd-index-section"><h3 class="tsd-index-heading">Properties</h3><div class="tsd-index-list"><a href="#getsnapshot" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>get<wbr/>Snapshot</span></a>
|
|
2
2
|
<a href="#initdefaultvalueonce" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>init<wbr/>Default<wbr/>Value<wbr/>Once</span></a>
|
|
3
3
|
<a href="#initdone" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>init<wbr/>Done</span></a>
|
|
4
4
|
<a href="#setvalue" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>set<wbr/>Value</span></a>
|
|
5
5
|
<a href="#subscribe" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>subscribe</span></a>
|
|
6
|
-
</div></section></div></details></section></section><details class="tsd-panel-group tsd-member-group tsd-accordion" open><summary class="tsd-accordion-summary" data-key="section-Properties"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h2>Properties</h2></summary><section><section class="tsd-panel tsd-member"><h3 class="tsd-anchor-link" id="getsnapshot"><span>get<wbr/>Snapshot</span><a href="#getsnapshot" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">getSnapshot</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">()</span> <span class="tsd-signature-symbol">=></span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#t">T</a
|
|
6
|
+
</div></section></div></details></section></section><details class="tsd-panel-group tsd-member-group tsd-accordion" open><summary class="tsd-accordion-summary" data-key="section-Properties"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h2>Properties</h2></summary><section><section class="tsd-panel tsd-member"><h3 class="tsd-anchor-link" id="getsnapshot"><span>get<wbr/>Snapshot</span><a href="#getsnapshot" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">getSnapshot</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">()</span> <span class="tsd-signature-symbol">=></span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#t">T</a></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/0e9a783f3018e49ee957d3c1f6b6cab46706cc3c/src/sharedState.ts#L109">sharedState.ts:109</a></li></ul></aside></section><section class="tsd-panel tsd-member"><h3 class="tsd-anchor-link" id="initdefaultvalueonce"><span>init<wbr/>Default<wbr/>Value<wbr/>Once</span><a href="#initdefaultvalueonce" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">initDefaultValueOnce</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">()</span> <span class="tsd-signature-symbol">=></span> <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">></span> <span class="tsd-signature-symbol">|</span> <span class="tsd-signature-type">void</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/0e9a783f3018e49ee957d3c1f6b6cab46706cc3c/src/sharedState.ts#L110">sharedState.ts:110</a></li></ul></aside></section><section class="tsd-panel tsd-member"><h3 class="tsd-anchor-link" id="initdone"><span>init<wbr/>Done</span><a href="#initdone" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">initDone</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/0e9a783f3018e49ee957d3c1f6b6cab46706cc3c/src/sharedState.ts#L111">sharedState.ts:111</a></li></ul></aside></section><section class="tsd-panel tsd-member"><h3 class="tsd-anchor-link" id="setvalue"><span>set<wbr/>Value</span><a href="#setvalue" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">setValue</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">next</span><span class="tsd-signature-symbol">:</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#t">T</a> <span class="tsd-signature-symbol">|</span> (<span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">prev</span><span class="tsd-signature-symbol">:</span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#t">T</a><span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=></span> <a class="tsd-signature-type tsd-kind-type-parameter" href="#t">T</a>)<span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=></span> <span class="tsd-signature-type">void</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/0e9a783f3018e49ee957d3c1f6b6cab46706cc3c/src/sharedState.ts#L112">sharedState.ts:112</a></li></ul></aside></section><section class="tsd-panel tsd-member"><h3 class="tsd-anchor-link" id="subscribe"><span>subscribe</span><a href="#subscribe" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">subscribe</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">subscriber</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">()</span> <span class="tsd-signature-symbol">=></span> <span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">)</span> <span class="tsd-signature-symbol">=></span> <span class="tsd-signature-symbol">()</span> <span class="tsd-signature-symbol">=></span> <span class="tsd-signature-type">void</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/0e9a783f3018e49ee957d3c1f6b6cab46706cc3c/src/sharedState.ts#L108">sharedState.ts:108</a></li></ul></aside></section></section></details></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h3>On This Page</h3></summary><div class="tsd-accordion-details"><details open class="tsd-accordion tsd-page-navigation-section"><summary class="tsd-accordion-summary" data-key="section-Properties"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Properties</summary><div><a href="#getsnapshot"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>get<wbr/>Snapshot</span></a><a href="#initdefaultvalueonce"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>init<wbr/>Default<wbr/>Value<wbr/>Once</span></a><a href="#initdone"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>init<wbr/>Done</span></a><a href="#setvalue"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>set<wbr/>Value</span></a><a href="#subscribe"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Property"><use href="../assets/icons.svg#icon-1024"></use></svg><span>subscribe</span></a></div></details></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">Chok’s React Utilities</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
<!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>fetcher | Chok’s React Utilities</title><meta name="description" content="Documentation for Chok’s React Utilities"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">Chok’s React Utilities</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="../modules/fetcher.html">fetcher</a></li><li><a href="" aria-current="page">fetcher</a></li></ul><h1>Variable fetcher<code class="tsd-tag">Const</code></h1></div><div class="tsd-signature"><span class="tsd-kind-variable">fetcher</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">Wretch</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">unknown</span><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-type">unknown</span><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-type">undefined</span><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-type">undefined</span><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol"> = ...</span></div><div class="tsd-comment tsd-typography"><p>Name this as "fetcher" to make it easier to understand.</p>
|
|
2
|
-
</div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/
|
|
2
|
+
</div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/0e9a783f3018e49ee957d3c1f6b6cab46706cc3c/src/fetcher.ts#L5">fetcher.ts:5</a></li></ul></aside></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">Chok’s React Utilities</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
<!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>fetcherWithRetries | Chok’s React Utilities</title><meta name="description" content="Documentation for Chok’s React Utilities"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">Chok’s React Utilities</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="../modules/fetcher.html">fetcher</a></li><li><a href="" aria-current="page">fetcherWithRetries</a></li></ul><h1>Variable fetcherWithRetries<code class="tsd-tag">Const</code></h1></div><div class="tsd-signature"><span class="tsd-kind-variable">fetcherWithRetries</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">Wretch</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">unknown</span><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-type">unknown</span><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-type">undefined</span><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-type">undefined</span><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol"> = ...</span></div><div class="tsd-comment tsd-typography"><p>Fetcher with default short retries.</p>
|
|
2
|
-
</div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/
|
|
2
|
+
</div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/choksheak/react-utils/blob/0e9a783f3018e49ee957d3c1f6b6cab46706cc3c/src/fetcher.ts#L8">fetcher.ts:8</a></li></ul></aside></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">Chok’s React Utilities</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
package/fetcher.d.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as wretch from 'wretch';
|
|
2
|
+
|
|
3
|
+
/** Name this as "fetcher" to make it easier to understand. */
|
|
4
|
+
declare const fetcher: wretch.Wretch<unknown, unknown, undefined, undefined>;
|
|
5
|
+
/** Fetcher with default short retries. */
|
|
6
|
+
declare const fetcherWithRetries: wretch.Wretch<unknown, unknown, undefined, undefined>;
|
|
7
|
+
|
|
8
|
+
export { fetcher, fetcherWithRetries };
|
package/fetcher.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Name this as "fetcher" to make it easier to understand. */
|
|
2
|
+
export declare const fetcher: import("wretch").Wretch<unknown, unknown, undefined, undefined>;
|
|
3
|
+
/** Fetcher with default short retries. */
|
|
4
|
+
export declare const fetcherWithRetries: import("wretch").Wretch<unknown, unknown, undefined, undefined>;
|
package/fetcher.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/fetcher.ts
|
|
31
|
+
var fetcher_exports = {};
|
|
32
|
+
__export(fetcher_exports, {
|
|
33
|
+
fetcher: () => fetcher,
|
|
34
|
+
fetcherWithRetries: () => fetcherWithRetries
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(fetcher_exports);
|
|
37
|
+
var import_wretch = __toESM(require("wretch"));
|
|
38
|
+
var import_middlewares = require("wretch/middlewares");
|
|
39
|
+
var fetcher = (0, import_wretch.default)();
|
|
40
|
+
var fetcherWithRetries = (0, import_wretch.default)().middlewares([
|
|
41
|
+
(0, import_middlewares.retry)({
|
|
42
|
+
maxAttempts: 3,
|
|
43
|
+
delayTimer: 1e3,
|
|
44
|
+
retryOnNetworkError: true
|
|
45
|
+
})
|
|
46
|
+
]);
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
fetcher,
|
|
50
|
+
fetcherWithRetries
|
|
51
|
+
});
|
package/fetcher.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/fetcher.ts
|
|
2
|
+
import wretch from "wretch";
|
|
3
|
+
import { retry } from "wretch/middlewares";
|
|
4
|
+
var fetcher = wretch();
|
|
5
|
+
var fetcherWithRetries = wretch().middlewares([
|
|
6
|
+
retry({
|
|
7
|
+
maxAttempts: 3,
|
|
8
|
+
delayTimer: 1e3,
|
|
9
|
+
retryOnNetworkError: true
|
|
10
|
+
})
|
|
11
|
+
]);
|
|
12
|
+
export {
|
|
13
|
+
fetcher,
|
|
14
|
+
fetcherWithRetries
|
|
15
|
+
};
|
package/index.d.mts
ADDED
package/index.d.ts
ADDED
|
File without changes
|
package/index.js
ADDED
package/index.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
3
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
// src/index.ts
|
|
7
|
+
var require_index = __commonJS({
|
|
8
|
+
"src/index.ts"() {
|
|
9
|
+
console.log(`Hello from Chok's React Utils`);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
export default require_index();
|
package/package.json
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The "shared state" is a React state that shares the same value across the
|
|
3
|
+
* entire app. It is largely similar to the jotai library, but is much smaller
|
|
4
|
+
* and much easier to work with when used for persisting in local storage or
|
|
5
|
+
* indexed db, with an automatic expiration for persisted values.
|
|
6
|
+
*
|
|
7
|
+
* This library aims to be the shortest, simplest, easiest to use, and most
|
|
8
|
+
* efficient implementation of shared global React states with seamless support
|
|
9
|
+
* for client persistence.
|
|
10
|
+
*/
|
|
11
|
+
/************************************************************************/
|
|
12
|
+
/************************************************************************/
|
|
13
|
+
/**
|
|
14
|
+
* These values are configurable by the user at any time.
|
|
15
|
+
*/
|
|
16
|
+
declare class SharedStateConfig {
|
|
17
|
+
/**
|
|
18
|
+
* Default duration for persistence expiration in milliseconds.
|
|
19
|
+
*/
|
|
20
|
+
static defaultPersistExpiryMs: number;
|
|
21
|
+
/**
|
|
22
|
+
* True to load from persistence only on mount, false (default) to load in
|
|
23
|
+
* the top level scope when the shared state is defined.
|
|
24
|
+
*/
|
|
25
|
+
static lazyLoad: boolean;
|
|
26
|
+
}
|
|
27
|
+
type SharedState<T> = {
|
|
28
|
+
subscribe: (subscriber: () => void) => () => void;
|
|
29
|
+
getSnapshot: () => T;
|
|
30
|
+
initDefaultValueOnce: () => Promise<void> | void;
|
|
31
|
+
initDone: boolean;
|
|
32
|
+
setValue: (next: T | ((prev: T) => T)) => void;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Create a new shared state object. Put this code at the top level scope:
|
|
36
|
+
*
|
|
37
|
+
* const myState = sharedState<number>(0);
|
|
38
|
+
*/
|
|
39
|
+
declare function sharedState<T>(defaultValue: T, options?: {
|
|
40
|
+
localStorageKey?: string;
|
|
41
|
+
indexedDbKey?: string;
|
|
42
|
+
persistExpiryMs?: number;
|
|
43
|
+
lazyLoad?: boolean;
|
|
44
|
+
}): SharedState<T>;
|
|
45
|
+
/**
|
|
46
|
+
* React hook for subscribing to a key in the global store.
|
|
47
|
+
* const [my, setMy] = useSharedState(myState);
|
|
48
|
+
*/
|
|
49
|
+
declare function useSharedState<T>(state: SharedState<T>): [T, (next: T | ((prev: T) => T)) => void];
|
|
50
|
+
/** E.g. const my = useSharedStateValue(myState) */
|
|
51
|
+
declare function useSharedStateValue<T>(state: SharedState<T>): T;
|
|
52
|
+
/** E.g. const setMy = useSharedStateSetter(myState) */
|
|
53
|
+
declare function useSharedStateSetter<T>(state: SharedState<T>): (next: T | ((prev: T) => T)) => void;
|
|
54
|
+
|
|
55
|
+
export { type SharedState, SharedStateConfig, sharedState, useSharedState, useSharedStateSetter, useSharedStateValue };
|
package/sharedState.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The "shared state" is a React state that shares the same value across the
|
|
3
|
+
* entire app. It is largely similar to the jotai library, but is much smaller
|
|
4
|
+
* and much easier to work with when used for persisting in local storage or
|
|
5
|
+
* indexed db, with an automatic expiration for persisted values.
|
|
6
|
+
*
|
|
7
|
+
* This library aims to be the shortest, simplest, easiest to use, and most
|
|
8
|
+
* efficient implementation of shared global React states with seamless support
|
|
9
|
+
* for client persistence.
|
|
10
|
+
*/
|
|
11
|
+
/************************************************************************/
|
|
12
|
+
/************************************************************************/
|
|
13
|
+
/**
|
|
14
|
+
* These values are configurable by the user at any time.
|
|
15
|
+
*/
|
|
16
|
+
export declare class SharedStateConfig {
|
|
17
|
+
/**
|
|
18
|
+
* Default duration for persistence expiration in milliseconds.
|
|
19
|
+
*/
|
|
20
|
+
static defaultPersistExpiryMs: number;
|
|
21
|
+
/**
|
|
22
|
+
* True to load from persistence only on mount, false (default) to load in
|
|
23
|
+
* the top level scope when the shared state is defined.
|
|
24
|
+
*/
|
|
25
|
+
static lazyLoad: boolean;
|
|
26
|
+
}
|
|
27
|
+
export type SharedState<T> = {
|
|
28
|
+
subscribe: (subscriber: () => void) => () => void;
|
|
29
|
+
getSnapshot: () => T;
|
|
30
|
+
initDefaultValueOnce: () => Promise<void> | void;
|
|
31
|
+
initDone: boolean;
|
|
32
|
+
setValue: (next: T | ((prev: T) => T)) => void;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Create a new shared state object. Put this code at the top level scope:
|
|
36
|
+
*
|
|
37
|
+
* const myState = sharedState<number>(0);
|
|
38
|
+
*/
|
|
39
|
+
export declare function sharedState<T>(defaultValue: T, options?: {
|
|
40
|
+
localStorageKey?: string;
|
|
41
|
+
indexedDbKey?: string;
|
|
42
|
+
persistExpiryMs?: number;
|
|
43
|
+
lazyLoad?: boolean;
|
|
44
|
+
}): SharedState<T>;
|
|
45
|
+
/**
|
|
46
|
+
* React hook for subscribing to a key in the global store.
|
|
47
|
+
* const [my, setMy] = useSharedState(myState);
|
|
48
|
+
*/
|
|
49
|
+
export declare function useSharedState<T>(state: SharedState<T>): [T, (next: T | ((prev: T) => T)) => void];
|
|
50
|
+
/** E.g. const my = useSharedStateValue(myState) */
|
|
51
|
+
export declare function useSharedStateValue<T>(state: SharedState<T>): T;
|
|
52
|
+
/** E.g. const setMy = useSharedStateSetter(myState) */
|
|
53
|
+
export declare function useSharedStateSetter<T>(state: SharedState<T>): (next: T | ((prev: T) => T)) => void;
|
package/sharedState.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/sharedState.ts
|
|
21
|
+
var sharedState_exports = {};
|
|
22
|
+
__export(sharedState_exports, {
|
|
23
|
+
SharedStateConfig: () => SharedStateConfig,
|
|
24
|
+
sharedState: () => sharedState,
|
|
25
|
+
useSharedState: () => useSharedState,
|
|
26
|
+
useSharedStateSetter: () => useSharedStateSetter,
|
|
27
|
+
useSharedStateValue: () => useSharedStateValue
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(sharedState_exports);
|
|
30
|
+
var import_kvStore = require("@choksheak/ts-utils/kvStore");
|
|
31
|
+
var import_timeConstants = require("@choksheak/ts-utils/timeConstants");
|
|
32
|
+
var import_react = require("react");
|
|
33
|
+
var SharedStateConfig = class {
|
|
34
|
+
/**
|
|
35
|
+
* Default duration for persistence expiration in milliseconds.
|
|
36
|
+
*/
|
|
37
|
+
static defaultPersistExpiryMs = import_timeConstants.MS_PER_DAY;
|
|
38
|
+
/**
|
|
39
|
+
* True to load from persistence only on mount, false (default) to load in
|
|
40
|
+
* the top level scope when the shared state is defined.
|
|
41
|
+
*/
|
|
42
|
+
static lazyLoad = false;
|
|
43
|
+
};
|
|
44
|
+
var PubSubStore = class {
|
|
45
|
+
dataByKey = /* @__PURE__ */ new Map();
|
|
46
|
+
subscribersByKey = /* @__PURE__ */ new Map();
|
|
47
|
+
// This could be undefined if T includes undefined, else it should never
|
|
48
|
+
// return undefined because the user has to always specify the default value.
|
|
49
|
+
get(key) {
|
|
50
|
+
return this.dataByKey.get(key);
|
|
51
|
+
}
|
|
52
|
+
set(key, value) {
|
|
53
|
+
const prev = this.dataByKey.get(key);
|
|
54
|
+
if (prev === value) return;
|
|
55
|
+
this.dataByKey.set(key, value);
|
|
56
|
+
this.notify(key, value, prev);
|
|
57
|
+
}
|
|
58
|
+
setNoNotify(key, value) {
|
|
59
|
+
this.dataByKey.set(key, value);
|
|
60
|
+
}
|
|
61
|
+
// Subscribe to changes of a specific key
|
|
62
|
+
subscribe(key, subscriber) {
|
|
63
|
+
let subscribers = this.subscribersByKey.get(key);
|
|
64
|
+
if (!subscribers) {
|
|
65
|
+
subscribers = /* @__PURE__ */ new Set();
|
|
66
|
+
this.subscribersByKey.set(key, subscribers);
|
|
67
|
+
}
|
|
68
|
+
subscribers.add(subscriber);
|
|
69
|
+
return () => {
|
|
70
|
+
subscribers.delete(subscriber);
|
|
71
|
+
if (subscribers.size === 0) this.subscribersByKey.delete(key);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
notify(key, next, prev) {
|
|
75
|
+
const subscribers = this.subscribersByKey.get(key);
|
|
76
|
+
if (!subscribers) return;
|
|
77
|
+
const copy = Array.from(subscribers.values());
|
|
78
|
+
for (const subscriber of copy) {
|
|
79
|
+
try {
|
|
80
|
+
subscriber(next, prev);
|
|
81
|
+
} catch (e) {
|
|
82
|
+
console.error(`Error invoking subscriber:`, e);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var store = new PubSubStore();
|
|
88
|
+
var stateKey = 0;
|
|
89
|
+
function sharedState(defaultValue, options) {
|
|
90
|
+
const { localStorageKey, indexedDbKey, persistExpiryMs, lazyLoad } = options ?? {};
|
|
91
|
+
const key = String(stateKey++);
|
|
92
|
+
let persistenceAdapter;
|
|
93
|
+
const expiryMs = persistExpiryMs ?? SharedStateConfig.defaultPersistExpiryMs;
|
|
94
|
+
if (localStorageKey) {
|
|
95
|
+
persistenceAdapter = new LocalStorageAdapter(localStorageKey, expiryMs);
|
|
96
|
+
} else if (indexedDbKey) {
|
|
97
|
+
persistenceAdapter = new IndexedDbAdapter(indexedDbKey, expiryMs);
|
|
98
|
+
}
|
|
99
|
+
function subscribe(subscriber) {
|
|
100
|
+
return store.subscribe(key, () => subscriber());
|
|
101
|
+
}
|
|
102
|
+
function getSnapshot() {
|
|
103
|
+
return store.get(key);
|
|
104
|
+
}
|
|
105
|
+
function setValue(next) {
|
|
106
|
+
if (typeof next === "function") {
|
|
107
|
+
const prev = store.get(key);
|
|
108
|
+
next = next(prev);
|
|
109
|
+
}
|
|
110
|
+
store.set(key, next);
|
|
111
|
+
void persistenceAdapter?.save?.(next);
|
|
112
|
+
}
|
|
113
|
+
store.setNoNotify(key, defaultValue);
|
|
114
|
+
const state = {
|
|
115
|
+
subscribe,
|
|
116
|
+
getSnapshot,
|
|
117
|
+
// initial default handling
|
|
118
|
+
initDefaultValueOnce: async () => {
|
|
119
|
+
if (state.initDone) return;
|
|
120
|
+
state.initDone = true;
|
|
121
|
+
const v = await persistenceAdapter?.load?.();
|
|
122
|
+
store.set(key, v !== void 0 ? v : defaultValue);
|
|
123
|
+
},
|
|
124
|
+
initDone: false,
|
|
125
|
+
setValue
|
|
126
|
+
};
|
|
127
|
+
const lazy = lazyLoad !== void 0 ? lazyLoad : SharedStateConfig.lazyLoad;
|
|
128
|
+
if (!lazy) {
|
|
129
|
+
void state.initDefaultValueOnce();
|
|
130
|
+
}
|
|
131
|
+
return state;
|
|
132
|
+
}
|
|
133
|
+
function useSharedState(state) {
|
|
134
|
+
state.initDefaultValueOnce();
|
|
135
|
+
const value = (0, import_react.useSyncExternalStore)(state.subscribe, state.getSnapshot);
|
|
136
|
+
return [value, state.setValue];
|
|
137
|
+
}
|
|
138
|
+
function useSharedStateValue(state) {
|
|
139
|
+
return useSharedState(state)[0];
|
|
140
|
+
}
|
|
141
|
+
function useSharedStateSetter(state) {
|
|
142
|
+
return useSharedState(state)[1];
|
|
143
|
+
}
|
|
144
|
+
var LocalStorageAdapter = class {
|
|
145
|
+
constructor(key, expiryMs) {
|
|
146
|
+
this.key = key;
|
|
147
|
+
this.expiryMs = expiryMs;
|
|
148
|
+
}
|
|
149
|
+
save(value) {
|
|
150
|
+
if (typeof window === "undefined") return;
|
|
151
|
+
window.localStorage.setItem(
|
|
152
|
+
this.key,
|
|
153
|
+
JSON.stringify({
|
|
154
|
+
value,
|
|
155
|
+
expiresAt: Date.now() + this.expiryMs
|
|
156
|
+
})
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
load() {
|
|
160
|
+
if (typeof window === "undefined") return void 0;
|
|
161
|
+
const raw = window.localStorage.getItem(this.key);
|
|
162
|
+
if (!raw) return void 0;
|
|
163
|
+
const box = JSON.parse(raw);
|
|
164
|
+
if (!box || !box?.expiresAt || Date.now() >= box.expiresAt) {
|
|
165
|
+
window.localStorage.removeItem(this.key);
|
|
166
|
+
return void 0;
|
|
167
|
+
}
|
|
168
|
+
return box.value;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
var IndexedDbAdapter = class {
|
|
172
|
+
constructor(key, expiryMs) {
|
|
173
|
+
this.key = key;
|
|
174
|
+
this.expiryMs = expiryMs;
|
|
175
|
+
}
|
|
176
|
+
async save(value) {
|
|
177
|
+
if (typeof window === "undefined") return;
|
|
178
|
+
await import_kvStore.kvStore.set(this.key, JSON.stringify(value), this.expiryMs);
|
|
179
|
+
}
|
|
180
|
+
async load() {
|
|
181
|
+
if (typeof window === "undefined") return void 0;
|
|
182
|
+
const raw = await import_kvStore.kvStore.get(this.key);
|
|
183
|
+
if (raw === void 0) return void 0;
|
|
184
|
+
return JSON.parse(raw);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
188
|
+
0 && (module.exports = {
|
|
189
|
+
SharedStateConfig,
|
|
190
|
+
sharedState,
|
|
191
|
+
useSharedState,
|
|
192
|
+
useSharedStateSetter,
|
|
193
|
+
useSharedStateValue
|
|
194
|
+
});
|
package/sharedState.mjs
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// src/sharedState.ts
|
|
2
|
+
import { kvStore } from "@choksheak/ts-utils/kvStore";
|
|
3
|
+
import { MS_PER_DAY } from "@choksheak/ts-utils/timeConstants";
|
|
4
|
+
import { useSyncExternalStore } from "react";
|
|
5
|
+
var SharedStateConfig = class {
|
|
6
|
+
/**
|
|
7
|
+
* Default duration for persistence expiration in milliseconds.
|
|
8
|
+
*/
|
|
9
|
+
static defaultPersistExpiryMs = MS_PER_DAY;
|
|
10
|
+
/**
|
|
11
|
+
* True to load from persistence only on mount, false (default) to load in
|
|
12
|
+
* the top level scope when the shared state is defined.
|
|
13
|
+
*/
|
|
14
|
+
static lazyLoad = false;
|
|
15
|
+
};
|
|
16
|
+
var PubSubStore = class {
|
|
17
|
+
dataByKey = /* @__PURE__ */ new Map();
|
|
18
|
+
subscribersByKey = /* @__PURE__ */ new Map();
|
|
19
|
+
// This could be undefined if T includes undefined, else it should never
|
|
20
|
+
// return undefined because the user has to always specify the default value.
|
|
21
|
+
get(key) {
|
|
22
|
+
return this.dataByKey.get(key);
|
|
23
|
+
}
|
|
24
|
+
set(key, value) {
|
|
25
|
+
const prev = this.dataByKey.get(key);
|
|
26
|
+
if (prev === value) return;
|
|
27
|
+
this.dataByKey.set(key, value);
|
|
28
|
+
this.notify(key, value, prev);
|
|
29
|
+
}
|
|
30
|
+
setNoNotify(key, value) {
|
|
31
|
+
this.dataByKey.set(key, value);
|
|
32
|
+
}
|
|
33
|
+
// Subscribe to changes of a specific key
|
|
34
|
+
subscribe(key, subscriber) {
|
|
35
|
+
let subscribers = this.subscribersByKey.get(key);
|
|
36
|
+
if (!subscribers) {
|
|
37
|
+
subscribers = /* @__PURE__ */ new Set();
|
|
38
|
+
this.subscribersByKey.set(key, subscribers);
|
|
39
|
+
}
|
|
40
|
+
subscribers.add(subscriber);
|
|
41
|
+
return () => {
|
|
42
|
+
subscribers.delete(subscriber);
|
|
43
|
+
if (subscribers.size === 0) this.subscribersByKey.delete(key);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
notify(key, next, prev) {
|
|
47
|
+
const subscribers = this.subscribersByKey.get(key);
|
|
48
|
+
if (!subscribers) return;
|
|
49
|
+
const copy = Array.from(subscribers.values());
|
|
50
|
+
for (const subscriber of copy) {
|
|
51
|
+
try {
|
|
52
|
+
subscriber(next, prev);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.error(`Error invoking subscriber:`, e);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var store = new PubSubStore();
|
|
60
|
+
var stateKey = 0;
|
|
61
|
+
function sharedState(defaultValue, options) {
|
|
62
|
+
const { localStorageKey, indexedDbKey, persistExpiryMs, lazyLoad } = options ?? {};
|
|
63
|
+
const key = String(stateKey++);
|
|
64
|
+
let persistenceAdapter;
|
|
65
|
+
const expiryMs = persistExpiryMs ?? SharedStateConfig.defaultPersistExpiryMs;
|
|
66
|
+
if (localStorageKey) {
|
|
67
|
+
persistenceAdapter = new LocalStorageAdapter(localStorageKey, expiryMs);
|
|
68
|
+
} else if (indexedDbKey) {
|
|
69
|
+
persistenceAdapter = new IndexedDbAdapter(indexedDbKey, expiryMs);
|
|
70
|
+
}
|
|
71
|
+
function subscribe(subscriber) {
|
|
72
|
+
return store.subscribe(key, () => subscriber());
|
|
73
|
+
}
|
|
74
|
+
function getSnapshot() {
|
|
75
|
+
return store.get(key);
|
|
76
|
+
}
|
|
77
|
+
function setValue(next) {
|
|
78
|
+
if (typeof next === "function") {
|
|
79
|
+
const prev = store.get(key);
|
|
80
|
+
next = next(prev);
|
|
81
|
+
}
|
|
82
|
+
store.set(key, next);
|
|
83
|
+
void persistenceAdapter?.save?.(next);
|
|
84
|
+
}
|
|
85
|
+
store.setNoNotify(key, defaultValue);
|
|
86
|
+
const state = {
|
|
87
|
+
subscribe,
|
|
88
|
+
getSnapshot,
|
|
89
|
+
// initial default handling
|
|
90
|
+
initDefaultValueOnce: async () => {
|
|
91
|
+
if (state.initDone) return;
|
|
92
|
+
state.initDone = true;
|
|
93
|
+
const v = await persistenceAdapter?.load?.();
|
|
94
|
+
store.set(key, v !== void 0 ? v : defaultValue);
|
|
95
|
+
},
|
|
96
|
+
initDone: false,
|
|
97
|
+
setValue
|
|
98
|
+
};
|
|
99
|
+
const lazy = lazyLoad !== void 0 ? lazyLoad : SharedStateConfig.lazyLoad;
|
|
100
|
+
if (!lazy) {
|
|
101
|
+
void state.initDefaultValueOnce();
|
|
102
|
+
}
|
|
103
|
+
return state;
|
|
104
|
+
}
|
|
105
|
+
function useSharedState(state) {
|
|
106
|
+
state.initDefaultValueOnce();
|
|
107
|
+
const value = useSyncExternalStore(state.subscribe, state.getSnapshot);
|
|
108
|
+
return [value, state.setValue];
|
|
109
|
+
}
|
|
110
|
+
function useSharedStateValue(state) {
|
|
111
|
+
return useSharedState(state)[0];
|
|
112
|
+
}
|
|
113
|
+
function useSharedStateSetter(state) {
|
|
114
|
+
return useSharedState(state)[1];
|
|
115
|
+
}
|
|
116
|
+
var LocalStorageAdapter = class {
|
|
117
|
+
constructor(key, expiryMs) {
|
|
118
|
+
this.key = key;
|
|
119
|
+
this.expiryMs = expiryMs;
|
|
120
|
+
}
|
|
121
|
+
save(value) {
|
|
122
|
+
if (typeof window === "undefined") return;
|
|
123
|
+
window.localStorage.setItem(
|
|
124
|
+
this.key,
|
|
125
|
+
JSON.stringify({
|
|
126
|
+
value,
|
|
127
|
+
expiresAt: Date.now() + this.expiryMs
|
|
128
|
+
})
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
load() {
|
|
132
|
+
if (typeof window === "undefined") return void 0;
|
|
133
|
+
const raw = window.localStorage.getItem(this.key);
|
|
134
|
+
if (!raw) return void 0;
|
|
135
|
+
const box = JSON.parse(raw);
|
|
136
|
+
if (!box || !box?.expiresAt || Date.now() >= box.expiresAt) {
|
|
137
|
+
window.localStorage.removeItem(this.key);
|
|
138
|
+
return void 0;
|
|
139
|
+
}
|
|
140
|
+
return box.value;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
var IndexedDbAdapter = class {
|
|
144
|
+
constructor(key, expiryMs) {
|
|
145
|
+
this.key = key;
|
|
146
|
+
this.expiryMs = expiryMs;
|
|
147
|
+
}
|
|
148
|
+
async save(value) {
|
|
149
|
+
if (typeof window === "undefined") return;
|
|
150
|
+
await kvStore.set(this.key, JSON.stringify(value), this.expiryMs);
|
|
151
|
+
}
|
|
152
|
+
async load() {
|
|
153
|
+
if (typeof window === "undefined") return void 0;
|
|
154
|
+
const raw = await kvStore.get(this.key);
|
|
155
|
+
if (raw === void 0) return void 0;
|
|
156
|
+
return JSON.parse(raw);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
export {
|
|
160
|
+
SharedStateConfig,
|
|
161
|
+
sharedState,
|
|
162
|
+
useSharedState,
|
|
163
|
+
useSharedStateSetter,
|
|
164
|
+
useSharedStateValue
|
|
165
|
+
};
|
package/src/sharedState.ts
CHANGED
|
@@ -37,7 +37,7 @@ export class SharedStateConfig {
|
|
|
37
37
|
/* Shared state implementation */
|
|
38
38
|
/************************************************************************/
|
|
39
39
|
|
|
40
|
-
type Subscriber<T> = (next: T, prev: T
|
|
40
|
+
type Subscriber<T> = (next: T, prev: T) => void;
|
|
41
41
|
|
|
42
42
|
type PersistenceAdapter<T> = {
|
|
43
43
|
save?: (value: T) => Promise<void> | void;
|
|
@@ -48,12 +48,14 @@ class PubSubStore {
|
|
|
48
48
|
private dataByKey = new Map<string, unknown>();
|
|
49
49
|
private subscribersByKey = new Map<string, Set<Subscriber<unknown>>>();
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
// This could be undefined if T includes undefined, else it should never
|
|
52
|
+
// return undefined because the user has to always specify the default value.
|
|
53
|
+
public get<T>(key: string): T {
|
|
54
|
+
return this.dataByKey.get(key) as T;
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
public set<T>(key: string, value: T): void {
|
|
56
|
-
const prev = this.dataByKey.get(key) as T
|
|
58
|
+
const prev = this.dataByKey.get(key) as T;
|
|
57
59
|
|
|
58
60
|
// Do nothing if no change.
|
|
59
61
|
if (prev === value) return;
|
|
@@ -62,6 +64,10 @@ class PubSubStore {
|
|
|
62
64
|
this.notify(key, value, prev);
|
|
63
65
|
}
|
|
64
66
|
|
|
67
|
+
public setNoNotify<T>(key: string, value: T): void {
|
|
68
|
+
this.dataByKey.set(key, value);
|
|
69
|
+
}
|
|
70
|
+
|
|
65
71
|
// Subscribe to changes of a specific key
|
|
66
72
|
public subscribe<T>(key: string, subscriber: Subscriber<T>): () => void {
|
|
67
73
|
let subscribers = this.subscribersByKey.get(key);
|
|
@@ -80,7 +86,7 @@ class PubSubStore {
|
|
|
80
86
|
};
|
|
81
87
|
}
|
|
82
88
|
|
|
83
|
-
private notify<T>(key: string, next: T, prev: T
|
|
89
|
+
private notify<T>(key: string, next: T, prev: T): void {
|
|
84
90
|
const subscribers = this.subscribersByKey.get(key);
|
|
85
91
|
if (!subscribers) return;
|
|
86
92
|
|
|
@@ -100,10 +106,10 @@ const store = new PubSubStore();
|
|
|
100
106
|
|
|
101
107
|
export type SharedState<T> = {
|
|
102
108
|
subscribe: (subscriber: () => void) => () => void;
|
|
103
|
-
getSnapshot: () => T
|
|
109
|
+
getSnapshot: () => T;
|
|
104
110
|
initDefaultValueOnce: () => Promise<void> | void;
|
|
105
111
|
initDone: boolean;
|
|
106
|
-
setValue: (next: T | ((prev: T
|
|
112
|
+
setValue: (next: T | ((prev: T) => T)) => void;
|
|
107
113
|
};
|
|
108
114
|
|
|
109
115
|
let stateKey = 0;
|
|
@@ -143,20 +149,24 @@ export function sharedState<T>(
|
|
|
143
149
|
}
|
|
144
150
|
|
|
145
151
|
// `getSnapshot` function — must return same ref if value unchanged
|
|
146
|
-
function getSnapshot(): T
|
|
152
|
+
function getSnapshot(): T {
|
|
147
153
|
return store.get(key);
|
|
148
154
|
}
|
|
149
155
|
|
|
150
|
-
function setValue(next: T | ((prev: T
|
|
156
|
+
function setValue(next: T | ((prev: T) => T)): void {
|
|
151
157
|
if (typeof next === "function") {
|
|
152
158
|
const prev = store.get<T>(key);
|
|
153
|
-
next = (next as (p: T
|
|
159
|
+
next = (next as (p: T) => T)(prev);
|
|
154
160
|
}
|
|
155
161
|
|
|
156
162
|
store.set(key, next);
|
|
157
163
|
void persistenceAdapter?.save?.(next);
|
|
158
164
|
}
|
|
159
165
|
|
|
166
|
+
// Always set the default value first to avoid returning undefineds if that
|
|
167
|
+
// is not part of T.
|
|
168
|
+
store.setNoNotify(key, defaultValue);
|
|
169
|
+
|
|
160
170
|
const state = {
|
|
161
171
|
subscribe,
|
|
162
172
|
getSnapshot,
|
|
@@ -189,7 +199,7 @@ export function sharedState<T>(
|
|
|
189
199
|
*/
|
|
190
200
|
export function useSharedState<T>(
|
|
191
201
|
state: SharedState<T>,
|
|
192
|
-
): [T
|
|
202
|
+
): [T, (next: T | ((prev: T) => T)) => void] {
|
|
193
203
|
state.initDefaultValueOnce();
|
|
194
204
|
|
|
195
205
|
const value = useSyncExternalStore(state.subscribe, state.getSnapshot);
|