jotai-location
Advanced tools
Comparing version 0.3.3 to 0.4.0
@@ -5,2 +5,6 @@ # Change Log | ||
## [0.4.0] - 2023-01-31 | ||
### Added | ||
- Migrate to Jotai v2 API #1 | ||
## [0.3.3] - 2023-01-05 | ||
@@ -7,0 +11,0 @@ ### Changed |
@@ -1,2 +0,2 @@ | ||
import{atom as e}from"jotai";import{unstable_NO_STORAGE_VALUE as n,atomWithStorage as t}from"jotai/utils";const o=()=>"undefined"!=typeof window&&window.location?{pathname:window.location.pathname,searchParams:new URLSearchParams(window.location.search)}:{},a=(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)||o,s=(null==n?void 0:n.applyLocation)||a,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,o)=>{t(c,o),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 o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},s.apply(this,arguments)}function l(e,o,a){const i=(null==a?void 0:a.serialize)||JSON.stringify;let r=i(o),l=o;const c=(null==a?void 0:a.deserialize)||(e=>{if(r!==(e=e||"")){try{l=JSON.parse(e)}catch(e){return n}r=e}return l}),w=(null==a?void 0:a.subscribe)||(e=>(window.addEventListener("hashchange",e),()=>{window.removeEventListener("hashchange",e)}));null!=a&&a.replaceState&&console.warn("[DEPRECATED] Use setHash=replaceState instead");const d=null==a?void 0:a.setHash;let h=e=>{window.location.hash=e};("replaceState"===d||null!=a&&a.replaceState)&&(h=e=>{window.history.replaceState(null,"",`${window.location.pathname}${window.location.search}#${e}`)}),"function"==typeof d&&(h=d);const u=s({getItem:e=>{if("undefined"==typeof window||!window.location)return n;const t=new URLSearchParams(window.location.hash.slice(1)).get(e);return c(t)},setItem:(e,n)=>{const t=new URLSearchParams(window.location.hash.slice(1)),o=i(n);t.set(e,o),h(t.toString()),r=o,l=n},removeItem:e=>{const n=new URLSearchParams(window.location.hash.slice(1));n.delete(e),h(n.toString())}},(null==a?void 0:a.delayInit)&&{delayInit:!0},{subscribe:(e,n)=>w(()=>{const t=new URLSearchParams(window.location.hash.slice(1)).get(e);n(null!==t?c(t):o)})});return t(e,o,u)}export{l as atomWithHash,r as atomWithLocation}; | ||
import{atom as e}from"jotai/vanilla";import{atomWithStorage as n,unstable_NO_STORAGE_VALUE as t}from"jotai/vanilla/utils";const a=()=>"undefined"!=typeof window&&window.location?{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,l=(null==n?void 0:n.applyLocation)||o,s=(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=s(n);return n(),t},e(e=>e(c),(e,t,a)=>{t(c,a),l(e(c),n)})}function l(e,a,o){const i=(null==o?void 0:o.serialize)||JSON.stringify;let r=i(a),l=a;const s=(null==o?void 0:o.deserialize)||(e=>{if(r!==(e=e||"")){try{l=JSON.parse(e)}catch(e){return t}r=e}return l}),c=(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 w=null==o?void 0:o.setHash;let d=e=>{window.location.hash=e};return("replaceState"===w||null!=o&&o.replaceState)&&(d=e=>{window.history.replaceState(null,"",`${window.location.pathname}${window.location.search}#${e}`)}),"function"==typeof w&&(d=w),n(e,a,{getItem:e=>{if("undefined"==typeof window||!window.location)return t;const n=new URLSearchParams(window.location.hash.slice(1)).get(e);return s(n)},setItem:(e,n)=>{const t=new URLSearchParams(window.location.hash.slice(1)),a=i(n);t.set(e,a),d(t.toString()),r=a,l=n},removeItem:e=>{const n=new URLSearchParams(window.location.hash.slice(1));n.delete(e),d(n.toString())},subscribe:(e,n)=>c(()=>{const t=new URLSearchParams(window.location.hash.slice(1)).get(e);n(null!==t?s(t):a)})})}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 o=function(){return"undefined"!=typeof window&&window.location?{pathname:window.location.pathname,searchParams:new URLSearchParams(window.location.search)}:{}},a=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 o in e)Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o])}return n},r.apply(this,arguments)}n.atomWithHash=function(n,t,o){var a=(null==o?void 0:o.serialize)||JSON.stringify,i=a(t),l=t,c=(null==o?void 0:o.deserialize)||function(n){if(i!==(n=n||"")){try{l=JSON.parse(n)}catch(n){return e.unstable_NO_STORAGE_VALUE}i=n}return l},u=(null==o?void 0:o.subscribe)||function(n){return window.addEventListener("hashchange",n),function(){window.removeEventListener("hashchange",n)}};null!=o&&o.replaceState&&console.warn("[DEPRECATED] Use setHash=replaceState instead");var s=null==o?void 0:o.setHash,d=function(n){window.location.hash=n};("replaceState"===s||null!=o&&o.replaceState)&&(d=function(n){window.history.replaceState(null,"",""+window.location.pathname+window.location.search+"#"+n)}),"function"==typeof s&&(d=s);var h=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 c(t)},setItem:function(n,t){var e=new URLSearchParams(window.location.hash.slice(1)),o=a(t);e.set(n,o),d(e.toString()),i=o,l=t},removeItem:function(n){var t=new URLSearchParams(window.location.hash.slice(1));t.delete(n),d(t.toString())}},(null==o?void 0:o.delayInit)&&{delayInit:!0},{subscribe:function(n,e){return u(function(){var o=new URLSearchParams(window.location.hash.slice(1)).get(n);e(null!==o?c(o):t)})}});return e.atomWithStorage(n,t,h)},n.atomWithLocation=function(n){var e,r=(null==n?void 0:n.getLocation)||o,l=(null==n?void 0:n.applyLocation)||a,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,o){e(u,o),l(t(u),n)})}}); | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("jotai/vanilla"),require("jotai/vanilla/utils")):"function"==typeof define&&define.amd?define(["exports","jotai/vanilla","jotai/vanilla/utils"],e):e((n||self).jotaiLocation={},n.vanilla,n.utils)}(this,function(n,e,t){var a=function(){return"undefined"!=typeof window&&window.location?{pathname:window.location.pathname,searchParams:new URLSearchParams(window.location.search)}:{}},o=function(n,e){var t=new URL(window.location.href);n.pathname&&(t.pathname=n.pathname),n.searchParams&&(t.search=n.searchParams.toString()),null!=e&&e.replace?window.history.replaceState(null,"",t):window.history.pushState(null,"",t)},i=function(n){return window.addEventListener("popstate",n),function(){return window.removeEventListener("popstate",n)}};n.atomWithHash=function(n,e,a){var o=(null==a?void 0:a.serialize)||JSON.stringify,i=o(e),r=e,l=(null==a?void 0:a.deserialize)||function(n){if(i!==(n=n||"")){try{r=JSON.parse(n)}catch(n){return t.unstable_NO_STORAGE_VALUE}i=n}return r},c=(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 u=null==a?void 0:a.setHash,s=function(n){window.location.hash=n};return("replaceState"===u||null!=a&&a.replaceState)&&(s=function(n){window.history.replaceState(null,"",""+window.location.pathname+window.location.search+"#"+n)}),"function"==typeof u&&(s=u),t.atomWithStorage(n,e,{getItem:function(n){if("undefined"==typeof window||!window.location)return t.unstable_NO_STORAGE_VALUE;var e=new URLSearchParams(window.location.hash.slice(1)).get(n);return l(e)},setItem:function(n,e){var t=new URLSearchParams(window.location.hash.slice(1)),a=o(e);t.set(n,a),s(t.toString()),i=a,r=e},removeItem:function(n){var e=new URLSearchParams(window.location.hash.slice(1));e.delete(n),s(e.toString())},subscribe:function(n,t){return c(function(){var a=new URLSearchParams(window.location.hash.slice(1)).get(n);t(null!==a?l(a):e)})}})},n.atomWithLocation=function(n){var t,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=e.atom(null!=(t=null==n?void 0:n.preloaded)?t:r());return u.onMount=function(n){var e=function(){return n(r())},t=c(e);return e(),t},e.atom(function(n){return n(u)},function(e,t,a){t(u,a),l(e(u),n)})}}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -1,3 +0,3 @@ | ||
import type { WritableAtom } from 'jotai'; | ||
import { unstable_NO_STORAGE_VALUE as NO_STORAGE_VALUE, RESET } from 'jotai/utils'; | ||
import type { WritableAtom } from 'jotai/vanilla'; | ||
import { unstable_NO_STORAGE_VALUE as NO_STORAGE_VALUE, RESET } from 'jotai/vanilla/utils'; | ||
type SetStateActionWithReset<Value> = Value | typeof RESET | ((prev: Value) => Value | typeof RESET); | ||
@@ -7,3 +7,2 @@ export declare function atomWithHash<Value>(key: string, initialValue: Value, options?: { | ||
deserialize?: (str: string | null) => Value | typeof NO_STORAGE_VALUE; | ||
delayInit?: boolean; | ||
/** | ||
@@ -15,3 +14,3 @@ * @deprecated Use {@link options.setHash} with 'replaceState' instead | ||
setHash?: 'default' | 'replaceState' | ((searchParams: string) => void); | ||
}): WritableAtom<Value, SetStateActionWithReset<Value>>; | ||
}): WritableAtom<Value, [SetStateActionWithReset<Value>], void>; | ||
export {}; |
@@ -1,2 +0,2 @@ | ||
import type { PrimitiveAtom } from 'jotai'; | ||
import type { PrimitiveAtom } from 'jotai/vanilla'; | ||
type Location = { | ||
@@ -3,0 +3,0 @@ pathname?: string; |
{ | ||
"name": "jotai-location", | ||
"description": "👻🔗", | ||
"version": "0.3.3", | ||
"version": "0.4.0", | ||
"author": "Daishi Kato", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/jotai-labs/jotai-location.git" | ||
"url": "https://github.com/jotaijs/jotai-location.git" | ||
}, | ||
@@ -51,37 +51,37 @@ "source": "./src/index.ts", | ||
"devDependencies": { | ||
"@testing-library/dom": "^8.19.1", | ||
"@testing-library/dom": "^8.20.0", | ||
"@testing-library/react": "^13.4.0", | ||
"@testing-library/user-event": "^14.4.3", | ||
"@types/jest": "^29.2.3", | ||
"@types/react": "^18.0.25", | ||
"@types/react-dom": "^18.0.9", | ||
"@typescript-eslint/eslint-plugin": "^5.43.0", | ||
"@typescript-eslint/parser": "^5.43.0", | ||
"eslint": "^8.27.0", | ||
"@types/jest": "^29.4.0", | ||
"@types/react": "^18.0.27", | ||
"@types/react-dom": "^18.0.10", | ||
"@typescript-eslint/eslint-plugin": "^5.50.0", | ||
"@typescript-eslint/parser": "^5.50.0", | ||
"eslint": "^8.33.0", | ||
"eslint-config-airbnb": "^19.0.4", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-jsx-a11y": "^6.6.1", | ||
"eslint-config-prettier": "^8.6.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-jsx-a11y": "^6.7.1", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-plugin-react": "^7.31.10", | ||
"eslint-plugin-react": "^7.32.2", | ||
"html-webpack-plugin": "^5.5.0", | ||
"jest": "^29.3.1", | ||
"jest-environment-jsdom": "^29.3.1", | ||
"jotai": "^1.9.2", | ||
"jest": "^29.4.1", | ||
"jest-environment-jsdom": "^29.4.1", | ||
"jotai": "^2.0.0", | ||
"microbundle": "^0.15.1", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.7.1", | ||
"prettier": "^2.8.3", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react-error-boundary": "^3.1.4", | ||
"ts-jest": "^29.0.3", | ||
"ts-loader": "^9.4.1", | ||
"typescript": "^4.9.3", | ||
"ts-jest": "^29.0.5", | ||
"ts-loader": "^9.4.2", | ||
"typescript": "^4.9.5", | ||
"webpack": "^5.75.0", | ||
"webpack-cli": "^4.10.0", | ||
"webpack-cli": "^5.0.1", | ||
"webpack-dev-server": "^4.11.1" | ||
}, | ||
"peerDependencies": { | ||
"jotai": "*" | ||
"jotai": ">=1.11.0" | ||
} | ||
} |
// TODO consider refactoring without atomWithStorage | ||
import type { WritableAtom } from 'jotai'; | ||
import type { WritableAtom } from 'jotai/vanilla'; | ||
import { | ||
@@ -8,3 +8,3 @@ atomWithStorage, | ||
RESET, | ||
} from 'jotai/utils'; | ||
} from 'jotai/vanilla/utils'; | ||
@@ -22,3 +22,2 @@ type SetStateActionWithReset<Value> = | ||
deserialize?: (str: string | null) => Value | typeof NO_STORAGE_VALUE; | ||
delayInit?: boolean; | ||
/** | ||
@@ -31,3 +30,3 @@ * @deprecated Use {@link options.setHash} with 'replaceState' instead | ||
}, | ||
): WritableAtom<Value, SetStateActionWithReset<Value>> { | ||
): WritableAtom<Value, [SetStateActionWithReset<Value>], void> { | ||
const serialize = options?.serialize || JSON.stringify; | ||
@@ -104,3 +103,2 @@ | ||
}, | ||
...(options?.delayInit && { delayInit: true }), | ||
subscribe: (k: string, setValue: (v: Value) => void) => { | ||
@@ -107,0 +105,0 @@ const callback = () => { |
@@ -1,3 +0,3 @@ | ||
import { atom } from 'jotai'; | ||
import type { PrimitiveAtom, SetStateAction } from 'jotai'; | ||
import { atom } from 'jotai/vanilla'; | ||
import type { PrimitiveAtom, SetStateAction } from 'jotai/vanilla'; | ||
@@ -4,0 +4,0 @@ type Location = { |
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
46321
248