made url more fine-grained

pull/11774/head
godzylinux 2 years ago
parent 7f296861d6
commit 850d285e40

@ -77,7 +77,6 @@ class URLWithReactiveSearchParams extends URL {
this.searchParams.delete(key); this.searchParams.delete(key);
} }
}); });
for (const key of super.searchParams.keys()) { for (const key of super.searchParams.keys()) {
// set/update keys // set/update keys
this.searchParams.set(key, /** @type {string} */ (super.searchParams.get(key))); this.searchParams.set(key, /** @type {string} */ (super.searchParams.get(key)));
@ -107,9 +106,22 @@ export const ReactiveURL = make_reactive(URLWithReactiveSearchParams, {
'pathname', 'pathname',
'hash', 'hash',
'search', 'search',
'href' 'href',
'host'
],
read_properties: [
'protocol',
'username',
'password',
'hostname',
'port',
'pathname',
'hash',
'search',
'href',
'host',
'origin'
], ],
read_properties: ['href', 'origin', 'host', 'hash', 'pathname'],
interceptors: { interceptors: {
protocol: (notify_read_properties, value, property, ...params) => { protocol: (notify_read_properties, value, property, ...params) => {
if ( if (
@ -118,36 +130,35 @@ export const ReactiveURL = make_reactive(URLWithReactiveSearchParams, {
) { ) {
return false; return false;
} }
notify_read_properties(['href', 'origin']); notify_read_properties(['href', 'origin', 'protocol']);
return true; return true;
}, },
username: (notify_read_properties, value, property, ...params) => { username: (notify_read_properties, value, property, ...params) => {
if (value.protocol === params[0]) { if (value.protocol === params[0]) {
return false; return false;
} }
notify_read_properties(['href']); notify_read_properties(['href', 'username']);
return true; return true;
}, },
password: (notify_read_properties, value, property, ...params) => { password: (notify_read_properties, value, property, ...params) => {
if (value.protocol === params[0]) { if (value.protocol === params[0]) {
return false; return false;
} }
notify_read_properties(['href']); notify_read_properties(['href', 'password']);
return true; return true;
}, },
hostname: (notify_read_properties, value, property, ...params) => { hostname: (notify_read_properties, value, property, ...params) => {
if (value.protocol === params[0]) { if (value.protocol === params[0]) {
return false; return false;
} }
notify_read_properties(['href', 'host']); notify_read_properties(['href', 'host', 'hostname']);
return true; return true;
}, },
port: (notify_read_properties, value, property, ...params) => { port: (notify_read_properties, value, property, ...params) => {
if (value.protocol === params[0]) { if (value.protocol === params[0]) {
return false; return false;
} }
notify_read_properties(['href', 'origin', 'host']); notify_read_properties(['href', 'origin', 'host', 'port']);
return true; return true;
}, },
@ -155,28 +166,28 @@ export const ReactiveURL = make_reactive(URLWithReactiveSearchParams, {
if (value.protocol === params[0]) { if (value.protocol === params[0]) {
return false; return false;
} }
notify_read_properties(['href']); notify_read_properties(['href', 'pathname']);
return true; return true;
}, },
hash: (notify_read_properties, value, property, ...params) => { hash: (notify_read_properties, value, property, ...params) => {
if (value.protocol === params[0]) { if (value.protocol === params[0]) {
return false; return false;
} }
notify_read_properties(['href']); notify_read_properties(['href', 'hash']);
return true; return true;
}, },
search: (notify_read_properties, value, property, ...params) => { search: (notify_read_properties, value, property, ...params) => {
if (value.search === params[0]) { if (value.search === params[0]) {
return false; return false;
} }
notify_read_properties(['href', 'hash']); notify_read_properties(['href', 'hash', 'search']);
return true; return true;
}, },
href: (notify_read_properties, value, property, ...params) => { href: (notify_read_properties, value, property, ...params) => {
if (value.href === params[0]) { if (value.href === params[0]) {
return false; return false;
} }
notify_read_properties(['origin', 'host', 'hash', 'pathname']); notify_read_properties(['origin', 'host', 'hash', 'pathname', 'href']);
return true; return true;
} }
} }

@ -68,10 +68,8 @@ test('url.searchParams', () => {
'q: true', 'q: true',
'search: ?q=kit&foo=baz&foo=qux', 'search: ?q=kit&foo=baz&foo=qux',
'foo: baz', 'foo: baz',
'q: true',
'search: ?q=kit', 'search: ?q=kit',
'foo: null', 'foo: null'
'q: true'
]); ]);
cleanup(); cleanup();

Loading…
Cancel
Save