Add: doc
This commit is contained in:
parent
2b8efaacd5
commit
898251ce4a
13
js/router.js
13
js/router.js
|
@ -11,6 +11,15 @@ const router = (() => {
|
||||||
return {watch, updateSearch, getSearch, updateHash};
|
return {watch, updateSearch, getSearch, updateHash};
|
||||||
|
|
||||||
function watch(options, callback) {
|
function watch(options, callback) {
|
||||||
|
/* Watch search params or hash and get notified on change.
|
||||||
|
|
||||||
|
options: {search?: Array<key: String>, hash?: String}
|
||||||
|
callback: (Array<value: String | null> | Boolean) => void
|
||||||
|
|
||||||
|
`hash` should always start with '#'.
|
||||||
|
When watching search params, callback receives a list of values.
|
||||||
|
When watching hash, callback receives a boolean.
|
||||||
|
*/
|
||||||
watchers.push({options, callback});
|
watchers.push({options, callback});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +40,10 @@ const router = (() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateHash(hash) {
|
function updateHash(hash) {
|
||||||
|
/* hash: String
|
||||||
|
|
||||||
|
Send an empty string to remove the hash.
|
||||||
|
*/
|
||||||
if (buffer.length > 1) {
|
if (buffer.length > 1) {
|
||||||
if (!hash && !buffer[buffer.length - 2].includes('#') || buffer[buffer.length - 2].endsWith(hash)) {
|
if (!hash && !buffer[buffer.length - 2].includes('#') || buffer[buffer.length - 2].endsWith(hash)) {
|
||||||
buffer.pop();
|
buffer.pop();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user