vue-query-param
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -1,25 +0,25 @@ | ||
function s(e) { | ||
const t = `${e.size > 0 ? "?" : ""}${e.toString()}`; | ||
function c(a) { | ||
const t = `${a.size > 0 ? "?" : ""}${a.toString()}`; | ||
history.replaceState(null, "", `${location.pathname}${t}`); | ||
} | ||
function l(e) { | ||
const a = new URLSearchParams(location.search); | ||
a.delete(e), s(a); | ||
function l(a) { | ||
const e = new URLSearchParams(location.search); | ||
e.delete(a), c(e); | ||
} | ||
function c(e, a) { | ||
function o(a, e) { | ||
const t = new URLSearchParams(location.search); | ||
if (!a) | ||
return l(e); | ||
t.has(e) ? t.set(e, a) : t.append(e, a), s(t); | ||
if (!e) | ||
return l(a); | ||
t.has(a) ? t.set(a, e) : t.append(a, e), c(t); | ||
} | ||
function n(e) { | ||
return new URLSearchParams(location.search).get(e); | ||
function n(a) { | ||
return new URLSearchParams(location.search).get(a); | ||
} | ||
const o = { | ||
model: "", | ||
callback: null, | ||
format: (e) => `${e}` | ||
}; | ||
function r(e, a) { | ||
return typeof a.value == "string" ? Object.assign(o, { model: a.value }) : Object.assign({}, o, a.value); | ||
function r(a, e) { | ||
const t = { | ||
model: "", | ||
callback: null, | ||
format: (s) => s | ||
}; | ||
return typeof e.value != "object" ? Object.assign(t, { model: e.value }) : "model" in e.value ? Object.assign(t, e.value) : Object.assign(t, { model: e.value }); | ||
} | ||
@@ -29,17 +29,17 @@ const u = { | ||
// Return the query-param from url | ||
created(e, a) { | ||
const t = r(e, a); | ||
t.callback && t.callback(n(a.arg)); | ||
created(a, e) { | ||
const t = r(a, e); | ||
t.callback && t.callback(n(e.arg)); | ||
}, | ||
updated(e, a) { | ||
const t = r(e, a); | ||
c(a.arg, t.format(t.model)); | ||
updated(a, e) { | ||
const t = r(a, e); | ||
o(e.arg, t.format(t.model)); | ||
}, | ||
mounted(e, a) { | ||
const t = r(e, a); | ||
t.model && c(a.arg, t.format(t.model)); | ||
mounted(a, e) { | ||
const t = r(a, e); | ||
t.model && o(e.arg, t.format(t.model)); | ||
} | ||
}, m = { | ||
install(e) { | ||
e.directive(u.name); | ||
install(a) { | ||
a.directive(u.name); | ||
} | ||
@@ -46,0 +46,0 @@ }; |
@@ -1,2 +0,1 @@ | ||
import { VueElement } from "vue"; | ||
export interface QueryParamArgs { | ||
@@ -8,8 +7,8 @@ model: string; | ||
export interface Binding { | ||
value: Function | QueryParamArgs; | ||
oldValue: Function | QueryParamArgs; | ||
value: string | QueryParamArgs; | ||
oldValue: string | QueryParamArgs; | ||
arg: string; | ||
modifiers: object; | ||
instance: VueElement; | ||
instance: object; | ||
dir: object; | ||
} |
{ | ||
"name": "vue-query-param", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Vue directive for bind a model with a URL's query param", | ||
@@ -5,0 +5,0 @@ "author": { |
import { getValueFromURL, setValueToURL } from "./history"; | ||
import type { Binding, QueryParamArgs } from "../types"; | ||
const defaultArgs = { | ||
model: "", | ||
callback: null, | ||
format: (val: object) => `${val}`, | ||
} | ||
function getArgs(el: HTMLElement, binding: Binding): QueryParamArgs { | ||
if (typeof binding.value === 'string') { | ||
const defaultArgs = { | ||
model: "", | ||
callback: null, | ||
format: (val: object) => val, | ||
} | ||
if (typeof binding.value !== 'object') { | ||
return Object.assign(defaultArgs, {model: binding.value}) | ||
} else { | ||
return Object.assign({}, defaultArgs, binding.value) | ||
if ("model" in binding.value) { | ||
return Object.assign(defaultArgs, binding.value) | ||
} else { | ||
return Object.assign(defaultArgs, { model: binding.value }) | ||
} | ||
} | ||
@@ -28,4 +30,4 @@ } | ||
}, | ||
updated(el: HTMLElement, binding: Binding) { | ||
const args = getArgs(el, binding) | ||
updated(el: HTMLElement, binding: Binding) { | ||
const args = getArgs(el, binding) | ||
setValueToURL(binding.arg, args.format(args.model)) | ||
@@ -32,0 +34,0 @@ }, |
@@ -1,3 +0,1 @@ | ||
import { VueElement } from "vue" | ||
export interface QueryParamArgs { | ||
@@ -10,8 +8,8 @@ model: string | ||
export interface Binding { | ||
value: Function | QueryParamArgs | ||
oldValue: Function | QueryParamArgs | ||
value: string | QueryParamArgs | ||
oldValue: string | QueryParamArgs | ||
arg: string | ||
modifiers: object | ||
instance: VueElement | ||
instance: object | ||
dir: object | ||
} |
Sorry, the diff of this file is not supported yet
9662
170