Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/modules / ___dist / router / @examples / onChange.js
Size: Mime:
"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);
});