Repository URL to install this package:
|
Version:
1.2.8 ▾
|
"use strict";
/**
* @description subscribe to the change event
* ONLY when the change matches the data provided
*
* @see chain/matcher
* @param {RegExp | Function | String | Object} matcher handle any of these for matching
*
* @param {Function} [subscriber=undefined] @curried 1
* @return {OneRouter} @chainable
*/
function onChangeFor(matcher, subscriber = undefined) {
// only 1 argument was passed in
if (arguments.length === 1) {
// ===
// return curriedSubscriber => onChangeFor(matcher, curriedSubscriber)
return function (curriedSubscriber) {
return onChangeFor(curriedSubscriber, subscriber);
};
} // if (isFunction(matcher)) {
// if (matcher.length === 1) {
// // by default, if param has ONE argument
// // then give it the latest
// }
// else if (matcher.length === 2) {
// // give current, previous...
// // or previous, current...
// // ^ @example opinionated default
// }
// // can also test only on prev, only on next
// // but for now, this is YAGNI
// matcher(previousRoute, nextRoute) {
// //
// }
// }
}
/**
* @example @name onChange
*/
function onRouteChange(oneRouterInstance) {//
}
oneRouter.onChange(onRouteChange);
/**
* @todo @name onChangeWhen
*/
const isCategoryChange = url => url.includes('category');
const onCategoryChange = oneRouter.onChangeWhen(isCategoryChange);
onCategoryChange(oneRouterInstance => {
console.log(oneRouterInstance);
});