reselect-tools
Version:
Selector Debugging Tools for Reselect.
1 lines • 2.58 kB
JavaScript
(function(e,r){if(typeof define==="function"&&define.amd){define("ReselectTools",["exports","reselect"],r)}else if(typeof exports!=="undefined"){r(exports,require("reselect"))}else{var t={exports:{}};r(t.exports,e.Reselect);e.ReselectTools=t.exports}})(this,function(e,r){"use strict";e.__esModule=true;e.createSelectorWithDependencies=t;e.registerSelectors=i;e.reset=a;e.checkSelector=f;e.getStateWith=u;e.selectorGraph=l;var w=null;var N=new Set;var x=function e(r){return typeof r==="function"};function t(){return r.createSelector.apply(undefined,arguments)}var n=function e(r){return r&&r.resultFunc||x(r)};var o=function e(r){N.add(r);var t=r.dependencies||[];t.forEach(e)};function i(t){Object.keys(t).forEach(function(e){var r=t[e];if(n(r)){r.selectorName=e;o(r)}})}function a(){w=null;N=new Set}function f(e){if(typeof e==="string"){var r=true;var t=false;var n=undefined;try{for(var o=N[Symbol.iterator](),i;!(r=(i=o.next()).done);r=true){var a=i.value;if(a.selectorName===e){e=a;break}}}catch(e){t=true;n=e}finally{try{if(!r&&o.return){o.return()}}finally{if(t){throw n}}}}if(!x(e)){throw new Error("Selector "+e+" is not a function...has it been registered?")}var u=e,c=u.dependencies,f=c===undefined?[]:c,s=u.selectorName,l=s===undefined?null:s;var d=typeof l==="string";var v=e.recomputations?e.recomputations():null;var p={dependencies:f,recomputations:v,isNamed:d,selectorName:l};if(w){var m=w();var h=f.map(function(e){return e(m)});var y={inputs:h};try{var S=e(m);y.output=S}catch(e){var g="checkSelector: error getting output of selector "+l+". The error was:\n"+e;y.error=g}Object.assign(p,y)}return p}function u(e){w=e}function c(e){return Array.from(e.toString()).reduce(function(e,r){return r.charCodeAt(0)+e},0)}var s=function e(r){if(r.selectorName){return r.selectorName}if(r.name){return r.name}return(r.dependencies||[]).reduce(function(e,r){return e+c(r)},(r.resultFunc?r.resultFunc:r).toString())};function l(){var u=arguments.length>0&&arguments[0]!==undefined?arguments[0]:s;var c={nodes:{},edges:[]};var e=function r(e){var t=u(e);if(c.nodes[t])return;var n=f(e),o=n.recomputations,i=n.isNamed;c.nodes[t]={recomputations:o,isNamed:i,name:t};var a=e.dependencies||[];a.forEach(function(e){r(e);c.edges.push({from:t,to:u(e)})})};var r=true;var t=false;var n=undefined;try{for(var o=N[Symbol.iterator](),i;!(r=(i=o.next()).done);r=true){var a=i.value;e(a)}}catch(e){t=true;n=e}finally{try{if(!r&&o.return){o.return()}}finally{if(t){throw n}}}return c}if(typeof window!=="undefined"){window.__RESELECT_TOOLS__={selectorGraph:l,checkSelector:f}}});