jotai-location
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -5,2 +5,6 @@ # Change Log | ||
## [0.3.1] - 2022-12-22 | ||
### Changed | ||
- fix: atomWithHash without window #5 | ||
## [0.3.0] - 2022-12-01 | ||
@@ -7,0 +11,0 @@ ### Added |
@@ -1,2 +0,2 @@ | ||
import{atom as e}from"jotai";import{unstable_NO_STORAGE_VALUE as n,atomWithStorage as t}from"jotai/utils";const a=()=>({pathname:window.location.pathname,searchParams:new URLSearchParams(window.location.search)}),o=(e,n)=>{const t=new URL(window.location.href);e.pathname&&(t.pathname=e.pathname),e.searchParams&&(t.search=e.searchParams.toString()),null!=n&&n.replace?window.history.replaceState(null,"",t):window.history.pushState(null,"",t)},i=e=>(window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e));function r(n){var t;const r=(null==n?void 0:n.getLocation)||a,s=(null==n?void 0:n.applyLocation)||o,l=(null==n?void 0:n.subscribe)||i,c=e(null!=(t=null==n?void 0:n.preloaded)?t:r());return c.onMount=e=>{const n=()=>e(r()),t=l(n);return n(),t},e(e=>e(c),(e,t,a)=>{t(c,a),s(e(c),n)})}function s(){return s=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},s.apply(this,arguments)}function l(e,a,o){const i=(null==o?void 0:o.serialize)||JSON.stringify,r=(null==o?void 0:o.deserialize)||(e=>{try{return JSON.parse(e||"")}catch(e){return n}}),l=(null==o?void 0:o.subscribe)||(e=>(window.addEventListener("hashchange",e),()=>{window.removeEventListener("hashchange",e)}));null!=o&&o.replaceState&&console.warn("[DEPRECATED] Use setHash=replaceState instead");const c=null==o?void 0:o.setHash;let h=e=>{window.location.hash=e};("replaceState"===c||null!=o&&o.replaceState)&&(h=e=>{window.history.replaceState(null,"",`${window.location.pathname}${window.location.search}#${e}`)}),"function"==typeof c&&(h=c);const w=s({getItem:e=>{if(void 0===window.location)return n;const t=new URLSearchParams(window.location.hash.slice(1)).get(e);return r(t)},setItem:(e,n)=>{const t=new URLSearchParams(window.location.hash.slice(1));t.set(e,i(n)),h(t.toString())},removeItem:e=>{const n=new URLSearchParams(window.location.hash.slice(1));n.delete(e),h(n.toString())}},(null==o?void 0:o.delayInit)&&{delayInit:!0},{subscribe:(e,n)=>l(()=>{const t=new URLSearchParams(window.location.hash.slice(1)).get(e);n(null!==t?r(t):a)})});return t(e,a,w)}export{l as atomWithHash,r as atomWithLocation}; | ||
import{atom as e}from"jotai";import{unstable_NO_STORAGE_VALUE as n,atomWithStorage as t}from"jotai/utils";const a=()=>({pathname:window.location.pathname,searchParams:new URLSearchParams(window.location.search)}),o=(e,n)=>{const t=new URL(window.location.href);e.pathname&&(t.pathname=e.pathname),e.searchParams&&(t.search=e.searchParams.toString()),null!=n&&n.replace?window.history.replaceState(null,"",t):window.history.pushState(null,"",t)},i=e=>(window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e));function r(n){var t;const r=(null==n?void 0:n.getLocation)||a,s=(null==n?void 0:n.applyLocation)||o,l=(null==n?void 0:n.subscribe)||i,c=e(null!=(t=null==n?void 0:n.preloaded)?t:r());return c.onMount=e=>{const n=()=>e(r()),t=l(n);return n(),t},e(e=>e(c),(e,t,a)=>{t(c,a),s(e(c),n)})}function s(){return s=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},s.apply(this,arguments)}function l(e,a,o){const i=(null==o?void 0:o.serialize)||JSON.stringify,r=(null==o?void 0:o.deserialize)||(e=>{try{return JSON.parse(e||"")}catch(e){return n}}),l=(null==o?void 0:o.subscribe)||(e=>(window.addEventListener("hashchange",e),()=>{window.removeEventListener("hashchange",e)}));null!=o&&o.replaceState&&console.warn("[DEPRECATED] Use setHash=replaceState instead");const c=null==o?void 0:o.setHash;let w=e=>{window.location.hash=e};("replaceState"===c||null!=o&&o.replaceState)&&(w=e=>{window.history.replaceState(null,"",`${window.location.pathname}${window.location.search}#${e}`)}),"function"==typeof c&&(w=c);const h=s({getItem:e=>{if("undefined"==typeof window||!window.location)return n;const t=new URLSearchParams(window.location.hash.slice(1)).get(e);return r(t)},setItem:(e,n)=>{const t=new URLSearchParams(window.location.hash.slice(1));t.set(e,i(n)),w(t.toString())},removeItem:e=>{const n=new URLSearchParams(window.location.hash.slice(1));n.delete(e),w(n.toString())}},(null==o?void 0:o.delayInit)&&{delayInit:!0},{subscribe:(e,n)=>l(()=>{const t=new URLSearchParams(window.location.hash.slice(1)).get(e);n(null!==t?r(t):a)})});return t(e,a,h)}export{l as atomWithHash,r as atomWithLocation}; | ||
//# sourceMappingURL=index.modern.mjs.map |
@@ -1,2 +0,2 @@ | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("jotai"),require("jotai/utils")):"function"==typeof define&&define.amd?define(["exports","jotai","jotai/utils"],t):t((n||self).jotaiLocation={},n.jotai,n.utils)}(this,function(n,t,e){var a=function(){return{pathname:window.location.pathname,searchParams:new URLSearchParams(window.location.search)}},o=function(n,t){var e=new URL(window.location.href);n.pathname&&(e.pathname=n.pathname),n.searchParams&&(e.search=n.searchParams.toString()),null!=t&&t.replace?window.history.replaceState(null,"",e):window.history.pushState(null,"",e)},i=function(n){return window.addEventListener("popstate",n),function(){return window.removeEventListener("popstate",n)}};function r(){return r=Object.assign?Object.assign.bind():function(n){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(n[a]=e[a])}return n},r.apply(this,arguments)}n.atomWithHash=function(n,t,a){var o=(null==a?void 0:a.serialize)||JSON.stringify,i=(null==a?void 0:a.deserialize)||function(n){try{return JSON.parse(n||"")}catch(n){return e.unstable_NO_STORAGE_VALUE}},l=(null==a?void 0:a.subscribe)||function(n){return window.addEventListener("hashchange",n),function(){window.removeEventListener("hashchange",n)}};null!=a&&a.replaceState&&console.warn("[DEPRECATED] Use setHash=replaceState instead");var c=null==a?void 0:a.setHash,u=function(n){window.location.hash=n};("replaceState"===c||null!=a&&a.replaceState)&&(u=function(n){window.history.replaceState(null,"",""+window.location.pathname+window.location.search+"#"+n)}),"function"==typeof c&&(u=c);var s=r({getItem:function(n){if(void 0===window.location)return e.unstable_NO_STORAGE_VALUE;var t=new URLSearchParams(window.location.hash.slice(1)).get(n);return i(t)},setItem:function(n,t){var e=new URLSearchParams(window.location.hash.slice(1));e.set(n,o(t)),u(e.toString())},removeItem:function(n){var t=new URLSearchParams(window.location.hash.slice(1));t.delete(n),u(t.toString())}},(null==a?void 0:a.delayInit)&&{delayInit:!0},{subscribe:function(n,e){return l(function(){var a=new URLSearchParams(window.location.hash.slice(1)).get(n);e(null!==a?i(a):t)})}});return e.atomWithStorage(n,t,s)},n.atomWithLocation=function(n){var e,r=(null==n?void 0:n.getLocation)||a,l=(null==n?void 0:n.applyLocation)||o,c=(null==n?void 0:n.subscribe)||i,u=t.atom(null!=(e=null==n?void 0:n.preloaded)?e:r());return u.onMount=function(n){var t=function(){return n(r())},e=c(t);return t(),e},t.atom(function(n){return n(u)},function(t,e,a){e(u,a),l(t(u),n)})}}); | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("jotai"),require("jotai/utils")):"function"==typeof define&&define.amd?define(["exports","jotai","jotai/utils"],t):t((n||self).jotaiLocation={},n.jotai,n.utils)}(this,function(n,t,e){var a=function(){return{pathname:window.location.pathname,searchParams:new URLSearchParams(window.location.search)}},o=function(n,t){var e=new URL(window.location.href);n.pathname&&(e.pathname=n.pathname),n.searchParams&&(e.search=n.searchParams.toString()),null!=t&&t.replace?window.history.replaceState(null,"",e):window.history.pushState(null,"",e)},i=function(n){return window.addEventListener("popstate",n),function(){return window.removeEventListener("popstate",n)}};function r(){return r=Object.assign?Object.assign.bind():function(n){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(n[a]=e[a])}return n},r.apply(this,arguments)}n.atomWithHash=function(n,t,a){var o=(null==a?void 0:a.serialize)||JSON.stringify,i=(null==a?void 0:a.deserialize)||function(n){try{return JSON.parse(n||"")}catch(n){return e.unstable_NO_STORAGE_VALUE}},l=(null==a?void 0:a.subscribe)||function(n){return window.addEventListener("hashchange",n),function(){window.removeEventListener("hashchange",n)}};null!=a&&a.replaceState&&console.warn("[DEPRECATED] Use setHash=replaceState instead");var c=null==a?void 0:a.setHash,u=function(n){window.location.hash=n};("replaceState"===c||null!=a&&a.replaceState)&&(u=function(n){window.history.replaceState(null,"",""+window.location.pathname+window.location.search+"#"+n)}),"function"==typeof c&&(u=c);var s=r({getItem:function(n){if("undefined"==typeof window||!window.location)return e.unstable_NO_STORAGE_VALUE;var t=new URLSearchParams(window.location.hash.slice(1)).get(n);return i(t)},setItem:function(n,t){var e=new URLSearchParams(window.location.hash.slice(1));e.set(n,o(t)),u(e.toString())},removeItem:function(n){var t=new URLSearchParams(window.location.hash.slice(1));t.delete(n),u(t.toString())}},(null==a?void 0:a.delayInit)&&{delayInit:!0},{subscribe:function(n,e){return l(function(){var a=new URLSearchParams(window.location.hash.slice(1)).get(n);e(null!==a?i(a):t)})}});return e.atomWithStorage(n,t,s)},n.atomWithLocation=function(n){var e,r=(null==n?void 0:n.getLocation)||a,l=(null==n?void 0:n.applyLocation)||o,c=(null==n?void 0:n.subscribe)||i,u=t.atom(null!=(e=null==n?void 0:n.preloaded)?e:r());return u.onMount=function(n){var t=function(){return n(r())},e=c(t);return t(),e},t.atom(function(n){return n(u)},function(t,e,a){e(u,a),l(t(u),n)})}}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "jotai-location", | ||
"description": "👻🔗", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"author": "Daishi Kato", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -69,3 +69,3 @@ // TODO consider refactoring without atomWithStorage | ||
getItem: (k: string) => { | ||
if (typeof window.location === 'undefined') { | ||
if (typeof window === 'undefined' || !window.location) { | ||
return NO_STORAGE_VALUE; | ||
@@ -72,0 +72,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
43811
237