jotai-location
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -1,2 +0,2 @@ | ||
import{atom as n}from"jotai";const a=()=>({pathname:window.location.pathname,searchParams:new URLSearchParams(window.location.search)}),o=(n,a)=>{const o=new URL(window.location.href);n.pathname&&(o.pathname=n.pathname),n.searchParams&&(o.search=n.searchParams.toString()),null!=a&&a.replace?window.history.replaceState(null,"",o):window.history.pushState(null,"",o)},t=n=>(window.addEventListener("popstate",n),()=>window.removeEventListener("popstate",n));function e(e){var r;const i=(null==e?void 0:e.getLocation)||a,l=(null==e?void 0:e.applyLocation)||o,s=(null==e?void 0:e.subscribe)||t,c=n(null!=(r=null==e?void 0:e.preloaded)?r:i());return c.onMount=n=>{const a=()=>n(i()),o=s(a);return a(),o},n(n=>n(c),(n,a,o)=>{a(c,o),l(n(c),e)})}export{e as atomWithLocation}; | ||
//# sourceMappingURL=index.modern.js.map | ||
import{atom as n}from"jotai";import{unstable_NO_STORAGE_VALUE as e,atomWithStorage as t}from"jotai/utils";const a=()=>({pathname:window.location.pathname,searchParams:new URLSearchParams(window.location.search)}),o=(n,e)=>{const 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=n=>(window.addEventListener("popstate",n),()=>window.removeEventListener("popstate",n));function r(e){var t;const r=(null==e?void 0:e.getLocation)||a,s=(null==e?void 0:e.applyLocation)||o,l=(null==e?void 0:e.subscribe)||i,c=n(null!=(t=null==e?void 0:e.preloaded)?t:r());return c.onMount=n=>{const e=()=>n(r()),t=l(e);return e(),t},n(n=>n(c),(n,t,a)=>{t(c,a),s(n(c),e)})}function s(){return s=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(n[a]=t[a])}return n},s.apply(this,arguments)}function l(n,a,o){const i=(null==o?void 0:o.serialize)||JSON.stringify,r=(null==o?void 0:o.deserialize)||(n=>{try{return JSON.parse(n||"")}catch(n){return e}}),l=(null==o?void 0:o.subscribe)||(n=>(window.addEventListener("hashchange",n),()=>{window.removeEventListener("hashchange",n)})),c=n=>{null!=o&&o.replaceState?window.history.replaceState(null,"",`${window.location.pathname}${window.location.search}#${n.toString()}`):window.location.hash=n.toString()},w=s({getItem:n=>{if(void 0===window.location)return e;const t=new URLSearchParams(window.location.hash.slice(1)).get(n);return r(t)},setItem:(n,e)=>{const t=new URLSearchParams(window.location.hash.slice(1));t.set(n,i(e)),c(t)},removeItem:n=>{const e=new URLSearchParams(window.location.hash.slice(1));e.delete(n),c(e)}},(null==o?void 0:o.delayInit)&&{delayInit:!0},{subscribe:(n,e)=>l(()=>{const t=new URLSearchParams(window.location.hash.slice(1)).get(n);e(null!==t?r(t):a)})});return t(n,a,w)}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")):"function"==typeof define&&define.amd?define(["exports","jotai"],t):t((n||self).jotaiLocation={},n.jotai)}(this,function(n,t){var o=function(){return{pathname:window.location.pathname,searchParams:new URLSearchParams(window.location.search)}},e=function(n,t){var o=new URL(window.location.href);n.pathname&&(o.pathname=n.pathname),n.searchParams&&(o.search=n.searchParams.toString()),null!=t&&t.replace?window.history.replaceState(null,"",o):window.history.pushState(null,"",o)},a=function(n){return window.addEventListener("popstate",n),function(){return window.removeEventListener("popstate",n)}};n.atomWithLocation=function(n){var i,r=(null==n?void 0:n.getLocation)||o,u=(null==n?void 0:n.applyLocation)||e,c=(null==n?void 0:n.subscribe)||a,l=t.atom(null!=(i=null==n?void 0:n.preloaded)?i:r());return l.onMount=function(n){var t=function(){return n(r())},o=c(t);return t(),o},t.atom(function(n){return n(l)},function(t,o,e){o(l,e),u(t(l),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 o=function(){return{pathname:window.location.pathname,searchParams:new URLSearchParams(window.location.search)}},i=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)},a=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 i=(null==o?void 0:o.serialize)||JSON.stringify,a=(null==o?void 0:o.deserialize)||function(n){try{return JSON.parse(n||"")}catch(n){return e.unstable_NO_STORAGE_VALUE}},l=(null==o?void 0:o.subscribe)||function(n){return window.addEventListener("hashchange",n),function(){window.removeEventListener("hashchange",n)}},c=function(n){null!=o&&o.replaceState?window.history.replaceState(null,"",""+window.location.pathname+window.location.search+"#"+n.toString()):window.location.hash=n.toString()},u=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 a(t)},setItem:function(n,t){var e=new URLSearchParams(window.location.hash.slice(1));e.set(n,i(t)),c(e)},removeItem:function(n){var t=new URLSearchParams(window.location.hash.slice(1));t.delete(n),c(t)}},(null==o?void 0:o.delayInit)&&{delayInit:!0},{subscribe:function(n,e){return l(function(){var o=new URLSearchParams(window.location.hash.slice(1)).get(n);e(null!==o?a(o):t)})}});return e.atomWithStorage(n,t,u)},n.atomWithLocation=function(n){var e,r=(null==n?void 0:n.getLocation)||o,l=(null==n?void 0:n.applyLocation)||i,c=(null==n?void 0:n.subscribe)||a,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)})}}); | ||
//# sourceMappingURL=index.umd.js.map |
import type { PrimitiveAtom } from 'jotai'; | ||
declare type Location = { | ||
type Location = { | ||
pathname?: string; | ||
searchParams?: URLSearchParams; | ||
}; | ||
declare type Options<T> = { | ||
type Options<T> = { | ||
preloaded?: T; | ||
@@ -15,5 +15,5 @@ replace?: boolean; | ||
}; | ||
declare type RequiredOptions<T> = Omit<Options<T>, 'getLocation' | 'applyLocation'> & Required<Pick<Options<T>, 'getLocation' | 'applyLocation'>>; | ||
type RequiredOptions<T> = Omit<Options<T>, 'getLocation' | 'applyLocation'> & Required<Pick<Options<T>, 'getLocation' | 'applyLocation'>>; | ||
export declare function atomWithLocation(options?: Options<Location>): PrimitiveAtom<Location>; | ||
export declare function atomWithLocation<T>(options: RequiredOptions<T>): PrimitiveAtom<T>; | ||
export {}; |
export { atomWithLocation } from './atomWithLocation'; | ||
export { atomWithHash } from './atomWithHash'; |
{ | ||
"name": "jotai-location", | ||
"description": "👻🔗", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"author": "Daishi Kato", | ||
@@ -30,3 +30,3 @@ "repository": { | ||
"compile": "microbundle build -f modern,umd --globals react=React", | ||
"postcompile": "cp dist/index.modern.js dist/index.modern.mjs && cp dist/index.modern.js.map dist/index.modern.mjs.map", | ||
"postcompile": "cp dist/index.modern.mjs dist/index.modern.js && cp dist/index.modern.mjs.map dist/index.modern.js.map", | ||
"test": "run-s eslint tsc-test jest", | ||
@@ -51,8 +51,9 @@ "eslint": "eslint --ext .js,.ts,.tsx .", | ||
"devDependencies": { | ||
"@types/jest": "^28.1.6", | ||
"@types/react": "^18.0.17", | ||
"@types/react-dom": "^18.0.6", | ||
"@typescript-eslint/eslint-plugin": "^5.33.0", | ||
"@typescript-eslint/parser": "^5.33.0", | ||
"eslint": "^8.21.0", | ||
"@testing-library/react": "^13.4.0", | ||
"@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", | ||
"eslint-config-airbnb": "^19.0.4", | ||
@@ -63,8 +64,8 @@ "eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-plugin-react": "^7.30.1", | ||
"eslint-plugin-react": "^7.31.10", | ||
"html-webpack-plugin": "^5.5.0", | ||
"jest": "^28.1.3", | ||
"jest-environment-jsdom": "^28.1.3", | ||
"jotai": "^1.7.8", | ||
"microbundle": "^0.15.0", | ||
"jest": "^29.3.1", | ||
"jest-environment-jsdom": "^29.3.1", | ||
"jotai": "^1.9.2", | ||
"microbundle": "^0.15.1", | ||
"npm-run-all": "^4.1.5", | ||
@@ -75,13 +76,12 @@ "prettier": "^2.7.1", | ||
"react-error-boundary": "^3.1.4", | ||
"ts-jest": "^28.0.7", | ||
"ts-loader": "^9.3.1", | ||
"typescript": "^4.7.4", | ||
"webpack": "^5.74.0", | ||
"ts-jest": "^29.0.3", | ||
"ts-loader": "^9.4.1", | ||
"typescript": "^4.9.3", | ||
"webpack": "^5.75.0", | ||
"webpack-cli": "^4.10.0", | ||
"webpack-dev-server": "^4.10.0" | ||
"webpack-dev-server": "^4.11.1" | ||
}, | ||
"peerDependencies": { | ||
"jotai": "*", | ||
"react": ">=17.0.0" | ||
"jotai": "*" | ||
} | ||
} |
@@ -7,2 +7,2 @@ # jotai-location | ||
- [Initial announcement]() | ||
- [Initial announcement](https://twitter.com/dai_shi/status/1558093027024875520) |
export { atomWithLocation } from './atomWithLocation'; | ||
export { atomWithHash } from './atomWithHash'; |
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
40112
1
16
220
29