From 898251ce4ab72331231f83ba7b484c7623d5c43d Mon Sep 17 00:00:00 2001 From: eight Date: Sat, 1 Feb 2020 09:46:28 +0800 Subject: [PATCH] Add: doc --- js/router.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/js/router.js b/js/router.js index dadd3acd..5e353b82 100644 --- a/js/router.js +++ b/js/router.js @@ -11,6 +11,15 @@ const router = (() => { return {watch, updateSearch, getSearch, updateHash}; function watch(options, callback) { + /* Watch search params or hash and get notified on change. + + options: {search?: Array, hash?: String} + callback: (Array | 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}); } @@ -31,6 +40,10 @@ const router = (() => { } function updateHash(hash) { + /* hash: String + + Send an empty string to remove the hash. + */ if (buffer.length > 1) { if (!hash && !buffer[buffer.length - 2].includes('#') || buffer[buffer.length - 2].endsWith(hash)) { buffer.pop();