reselect.legacy-esm.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  3. var __hasOwnProp = Object.prototype.hasOwnProperty;
  4. var __propIsEnum = Object.prototype.propertyIsEnumerable;
  5. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  6. var __spreadValues = (a, b) => {
  7. for (var prop in b || (b = {}))
  8. if (__hasOwnProp.call(b, prop))
  9. __defNormalProp(a, prop, b[prop]);
  10. if (__getOwnPropSymbols)
  11. for (var prop of __getOwnPropSymbols(b)) {
  12. if (__propIsEnum.call(b, prop))
  13. __defNormalProp(a, prop, b[prop]);
  14. }
  15. return a;
  16. };
  17. var __publicField = (obj, key, value) => {
  18. __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  19. return value;
  20. };
  21. // src/devModeChecks/identityFunctionCheck.ts
  22. var runIdentityFunctionCheck = (resultFunc) => {
  23. let isInputSameAsOutput = false;
  24. try {
  25. const emptyObject = {};
  26. if (resultFunc(emptyObject) === emptyObject)
  27. isInputSameAsOutput = true;
  28. } catch (e) {
  29. }
  30. if (isInputSameAsOutput) {
  31. let stack = void 0;
  32. try {
  33. throw new Error();
  34. } catch (e) {
  35. ;
  36. ({ stack } = e);
  37. }
  38. console.warn(
  39. "The result function returned its own inputs without modification. e.g\n`createSelector([state => state.todos], todos => todos)`\nThis could lead to inefficient memoization and unnecessary re-renders.\nEnsure transformation logic is in the result function, and extraction logic is in the input selectors.",
  40. { stack }
  41. );
  42. }
  43. };
  44. // src/devModeChecks/inputStabilityCheck.ts
  45. var runInputStabilityCheck = (inputSelectorResultsObject, options, inputSelectorArgs) => {
  46. const { memoize, memoizeOptions } = options;
  47. const { inputSelectorResults, inputSelectorResultsCopy } = inputSelectorResultsObject;
  48. const createAnEmptyObject = memoize(() => ({}), ...memoizeOptions);
  49. const areInputSelectorResultsEqual = createAnEmptyObject.apply(null, inputSelectorResults) === createAnEmptyObject.apply(null, inputSelectorResultsCopy);
  50. if (!areInputSelectorResultsEqual) {
  51. let stack = void 0;
  52. try {
  53. throw new Error();
  54. } catch (e) {
  55. ;
  56. ({ stack } = e);
  57. }
  58. console.warn(
  59. "An input selector returned a different result when passed same arguments.\nThis means your output selector will likely run more frequently than intended.\nAvoid returning a new reference inside your input selector, e.g.\n`createSelector([state => state.todos.map(todo => todo.id)], todoIds => todoIds.length)`",
  60. {
  61. arguments: inputSelectorArgs,
  62. firstInputs: inputSelectorResults,
  63. secondInputs: inputSelectorResultsCopy,
  64. stack
  65. }
  66. );
  67. }
  68. };
  69. // src/devModeChecks/setGlobalDevModeChecks.ts
  70. var globalDevModeChecks = {
  71. inputStabilityCheck: "once",
  72. identityFunctionCheck: "once"
  73. };
  74. var setGlobalDevModeChecks = (devModeChecks) => {
  75. Object.assign(globalDevModeChecks, devModeChecks);
  76. };
  77. // src/utils.ts
  78. var NOT_FOUND = "NOT_FOUND";
  79. function assertIsFunction(func, errorMessage = `expected a function, instead received ${typeof func}`) {
  80. if (typeof func !== "function") {
  81. throw new TypeError(errorMessage);
  82. }
  83. }
  84. function assertIsObject(object, errorMessage = `expected an object, instead received ${typeof object}`) {
  85. if (typeof object !== "object") {
  86. throw new TypeError(errorMessage);
  87. }
  88. }
  89. function assertIsArrayOfFunctions(array, errorMessage = `expected all items to be functions, instead received the following types: `) {
  90. if (!array.every((item) => typeof item === "function")) {
  91. const itemTypes = array.map(
  92. (item) => typeof item === "function" ? `function ${item.name || "unnamed"}()` : typeof item
  93. ).join(", ");
  94. throw new TypeError(`${errorMessage}[${itemTypes}]`);
  95. }
  96. }
  97. var ensureIsArray = (item) => {
  98. return Array.isArray(item) ? item : [item];
  99. };
  100. function getDependencies(createSelectorArgs) {
  101. const dependencies = Array.isArray(createSelectorArgs[0]) ? createSelectorArgs[0] : createSelectorArgs;
  102. assertIsArrayOfFunctions(
  103. dependencies,
  104. `createSelector expects all input-selectors to be functions, but received the following types: `
  105. );
  106. return dependencies;
  107. }
  108. function collectInputSelectorResults(dependencies, inputSelectorArgs) {
  109. const inputSelectorResults = [];
  110. const { length } = dependencies;
  111. for (let i = 0; i < length; i++) {
  112. inputSelectorResults.push(dependencies[i].apply(null, inputSelectorArgs));
  113. }
  114. return inputSelectorResults;
  115. }
  116. var getDevModeChecksExecutionInfo = (firstRun, devModeChecks) => {
  117. const { identityFunctionCheck, inputStabilityCheck } = __spreadValues(__spreadValues({}, globalDevModeChecks), devModeChecks);
  118. return {
  119. identityFunctionCheck: {
  120. shouldRun: identityFunctionCheck === "always" || identityFunctionCheck === "once" && firstRun,
  121. run: runIdentityFunctionCheck
  122. },
  123. inputStabilityCheck: {
  124. shouldRun: inputStabilityCheck === "always" || inputStabilityCheck === "once" && firstRun,
  125. run: runInputStabilityCheck
  126. }
  127. };
  128. };
  129. // src/autotrackMemoize/autotracking.ts
  130. var $REVISION = 0;
  131. var CURRENT_TRACKER = null;
  132. var Cell = class {
  133. constructor(initialValue, isEqual = tripleEq) {
  134. __publicField(this, "revision", $REVISION);
  135. __publicField(this, "_value");
  136. __publicField(this, "_lastValue");
  137. __publicField(this, "_isEqual", tripleEq);
  138. this._value = this._lastValue = initialValue;
  139. this._isEqual = isEqual;
  140. }
  141. // Whenever a storage value is read, it'll add itself to the current tracker if
  142. // one exists, entangling its state with that cache.
  143. get value() {
  144. CURRENT_TRACKER == null ? void 0 : CURRENT_TRACKER.add(this);
  145. return this._value;
  146. }
  147. // Whenever a storage value is updated, we bump the global revision clock,
  148. // assign the revision for this storage to the new value, _and_ we schedule a
  149. // rerender. This is important, and it's what makes autotracking _pull_
  150. // based. We don't actively tell the caches which depend on the storage that
  151. // anything has happened. Instead, we recompute the caches when needed.
  152. set value(newValue) {
  153. if (this.value === newValue)
  154. return;
  155. this._value = newValue;
  156. this.revision = ++$REVISION;
  157. }
  158. };
  159. function tripleEq(a, b) {
  160. return a === b;
  161. }
  162. var TrackingCache = class {
  163. constructor(fn) {
  164. __publicField(this, "_cachedValue");
  165. __publicField(this, "_cachedRevision", -1);
  166. __publicField(this, "_deps", []);
  167. __publicField(this, "hits", 0);
  168. __publicField(this, "fn");
  169. this.fn = fn;
  170. }
  171. clear() {
  172. this._cachedValue = void 0;
  173. this._cachedRevision = -1;
  174. this._deps = [];
  175. this.hits = 0;
  176. }
  177. get value() {
  178. if (this.revision > this._cachedRevision) {
  179. const { fn } = this;
  180. const currentTracker = /* @__PURE__ */ new Set();
  181. const prevTracker = CURRENT_TRACKER;
  182. CURRENT_TRACKER = currentTracker;
  183. this._cachedValue = fn();
  184. CURRENT_TRACKER = prevTracker;
  185. this.hits++;
  186. this._deps = Array.from(currentTracker);
  187. this._cachedRevision = this.revision;
  188. }
  189. CURRENT_TRACKER == null ? void 0 : CURRENT_TRACKER.add(this);
  190. return this._cachedValue;
  191. }
  192. get revision() {
  193. return Math.max(...this._deps.map((d) => d.revision), 0);
  194. }
  195. };
  196. function getValue(cell) {
  197. if (!(cell instanceof Cell)) {
  198. console.warn("Not a valid cell! ", cell);
  199. }
  200. return cell.value;
  201. }
  202. function setValue(storage, value) {
  203. if (!(storage instanceof Cell)) {
  204. throw new TypeError(
  205. "setValue must be passed a tracked store created with `createStorage`."
  206. );
  207. }
  208. storage.value = storage._lastValue = value;
  209. }
  210. function createCell(initialValue, isEqual = tripleEq) {
  211. return new Cell(initialValue, isEqual);
  212. }
  213. function createCache(fn) {
  214. assertIsFunction(
  215. fn,
  216. "the first parameter to `createCache` must be a function"
  217. );
  218. return new TrackingCache(fn);
  219. }
  220. // src/autotrackMemoize/tracking.ts
  221. var neverEq = (a, b) => false;
  222. function createTag() {
  223. return createCell(null, neverEq);
  224. }
  225. function dirtyTag(tag, value) {
  226. setValue(tag, value);
  227. }
  228. var consumeCollection = (node) => {
  229. let tag = node.collectionTag;
  230. if (tag === null) {
  231. tag = node.collectionTag = createTag();
  232. }
  233. getValue(tag);
  234. };
  235. var dirtyCollection = (node) => {
  236. const tag = node.collectionTag;
  237. if (tag !== null) {
  238. dirtyTag(tag, null);
  239. }
  240. };
  241. // src/autotrackMemoize/proxy.ts
  242. var REDUX_PROXY_LABEL = Symbol();
  243. var nextId = 0;
  244. var proto = Object.getPrototypeOf({});
  245. var ObjectTreeNode = class {
  246. constructor(value) {
  247. this.value = value;
  248. __publicField(this, "proxy", new Proxy(this, objectProxyHandler));
  249. __publicField(this, "tag", createTag());
  250. __publicField(this, "tags", {});
  251. __publicField(this, "children", {});
  252. __publicField(this, "collectionTag", null);
  253. __publicField(this, "id", nextId++);
  254. this.value = value;
  255. this.tag.value = value;
  256. }
  257. };
  258. var objectProxyHandler = {
  259. get(node, key) {
  260. function calculateResult() {
  261. const { value } = node;
  262. const childValue = Reflect.get(value, key);
  263. if (typeof key === "symbol") {
  264. return childValue;
  265. }
  266. if (key in proto) {
  267. return childValue;
  268. }
  269. if (typeof childValue === "object" && childValue !== null) {
  270. let childNode = node.children[key];
  271. if (childNode === void 0) {
  272. childNode = node.children[key] = createNode(childValue);
  273. }
  274. if (childNode.tag) {
  275. getValue(childNode.tag);
  276. }
  277. return childNode.proxy;
  278. } else {
  279. let tag = node.tags[key];
  280. if (tag === void 0) {
  281. tag = node.tags[key] = createTag();
  282. tag.value = childValue;
  283. }
  284. getValue(tag);
  285. return childValue;
  286. }
  287. }
  288. const res = calculateResult();
  289. return res;
  290. },
  291. ownKeys(node) {
  292. consumeCollection(node);
  293. return Reflect.ownKeys(node.value);
  294. },
  295. getOwnPropertyDescriptor(node, prop) {
  296. return Reflect.getOwnPropertyDescriptor(node.value, prop);
  297. },
  298. has(node, prop) {
  299. return Reflect.has(node.value, prop);
  300. }
  301. };
  302. var ArrayTreeNode = class {
  303. constructor(value) {
  304. this.value = value;
  305. __publicField(this, "proxy", new Proxy([this], arrayProxyHandler));
  306. __publicField(this, "tag", createTag());
  307. __publicField(this, "tags", {});
  308. __publicField(this, "children", {});
  309. __publicField(this, "collectionTag", null);
  310. __publicField(this, "id", nextId++);
  311. this.value = value;
  312. this.tag.value = value;
  313. }
  314. };
  315. var arrayProxyHandler = {
  316. get([node], key) {
  317. if (key === "length") {
  318. consumeCollection(node);
  319. }
  320. return objectProxyHandler.get(node, key);
  321. },
  322. ownKeys([node]) {
  323. return objectProxyHandler.ownKeys(node);
  324. },
  325. getOwnPropertyDescriptor([node], prop) {
  326. return objectProxyHandler.getOwnPropertyDescriptor(node, prop);
  327. },
  328. has([node], prop) {
  329. return objectProxyHandler.has(node, prop);
  330. }
  331. };
  332. function createNode(value) {
  333. if (Array.isArray(value)) {
  334. return new ArrayTreeNode(value);
  335. }
  336. return new ObjectTreeNode(value);
  337. }
  338. function updateNode(node, newValue) {
  339. const { value, tags, children } = node;
  340. node.value = newValue;
  341. if (Array.isArray(value) && Array.isArray(newValue) && value.length !== newValue.length) {
  342. dirtyCollection(node);
  343. } else {
  344. if (value !== newValue) {
  345. let oldKeysSize = 0;
  346. let newKeysSize = 0;
  347. let anyKeysAdded = false;
  348. for (const _key in value) {
  349. oldKeysSize++;
  350. }
  351. for (const key in newValue) {
  352. newKeysSize++;
  353. if (!(key in value)) {
  354. anyKeysAdded = true;
  355. break;
  356. }
  357. }
  358. const isDifferent = anyKeysAdded || oldKeysSize !== newKeysSize;
  359. if (isDifferent) {
  360. dirtyCollection(node);
  361. }
  362. }
  363. }
  364. for (const key in tags) {
  365. const childValue = value[key];
  366. const newChildValue = newValue[key];
  367. if (childValue !== newChildValue) {
  368. dirtyCollection(node);
  369. dirtyTag(tags[key], newChildValue);
  370. }
  371. if (typeof newChildValue === "object" && newChildValue !== null) {
  372. delete tags[key];
  373. }
  374. }
  375. for (const key in children) {
  376. const childNode = children[key];
  377. const newChildValue = newValue[key];
  378. const childValue = childNode.value;
  379. if (childValue === newChildValue) {
  380. continue;
  381. } else if (typeof newChildValue === "object" && newChildValue !== null) {
  382. updateNode(childNode, newChildValue);
  383. } else {
  384. deleteNode(childNode);
  385. delete children[key];
  386. }
  387. }
  388. }
  389. function deleteNode(node) {
  390. if (node.tag) {
  391. dirtyTag(node.tag, null);
  392. }
  393. dirtyCollection(node);
  394. for (const key in node.tags) {
  395. dirtyTag(node.tags[key], null);
  396. }
  397. for (const key in node.children) {
  398. deleteNode(node.children[key]);
  399. }
  400. }
  401. // src/lruMemoize.ts
  402. function createSingletonCache(equals) {
  403. let entry;
  404. return {
  405. get(key) {
  406. if (entry && equals(entry.key, key)) {
  407. return entry.value;
  408. }
  409. return NOT_FOUND;
  410. },
  411. put(key, value) {
  412. entry = { key, value };
  413. },
  414. getEntries() {
  415. return entry ? [entry] : [];
  416. },
  417. clear() {
  418. entry = void 0;
  419. }
  420. };
  421. }
  422. function createLruCache(maxSize, equals) {
  423. let entries = [];
  424. function get(key) {
  425. const cacheIndex = entries.findIndex((entry) => equals(key, entry.key));
  426. if (cacheIndex > -1) {
  427. const entry = entries[cacheIndex];
  428. if (cacheIndex > 0) {
  429. entries.splice(cacheIndex, 1);
  430. entries.unshift(entry);
  431. }
  432. return entry.value;
  433. }
  434. return NOT_FOUND;
  435. }
  436. function put(key, value) {
  437. if (get(key) === NOT_FOUND) {
  438. entries.unshift({ key, value });
  439. if (entries.length > maxSize) {
  440. entries.pop();
  441. }
  442. }
  443. }
  444. function getEntries() {
  445. return entries;
  446. }
  447. function clear() {
  448. entries = [];
  449. }
  450. return { get, put, getEntries, clear };
  451. }
  452. var referenceEqualityCheck = (a, b) => a === b;
  453. function createCacheKeyComparator(equalityCheck) {
  454. return function areArgumentsShallowlyEqual(prev, next) {
  455. if (prev === null || next === null || prev.length !== next.length) {
  456. return false;
  457. }
  458. const { length } = prev;
  459. for (let i = 0; i < length; i++) {
  460. if (!equalityCheck(prev[i], next[i])) {
  461. return false;
  462. }
  463. }
  464. return true;
  465. };
  466. }
  467. function lruMemoize(func, equalityCheckOrOptions) {
  468. const providedOptions = typeof equalityCheckOrOptions === "object" ? equalityCheckOrOptions : { equalityCheck: equalityCheckOrOptions };
  469. const {
  470. equalityCheck = referenceEqualityCheck,
  471. maxSize = 1,
  472. resultEqualityCheck
  473. } = providedOptions;
  474. const comparator = createCacheKeyComparator(equalityCheck);
  475. let resultsCount = 0;
  476. const cache = maxSize === 1 ? createSingletonCache(comparator) : createLruCache(maxSize, comparator);
  477. function memoized() {
  478. let value = cache.get(arguments);
  479. if (value === NOT_FOUND) {
  480. value = func.apply(null, arguments);
  481. resultsCount++;
  482. if (resultEqualityCheck) {
  483. const entries = cache.getEntries();
  484. const matchingEntry = entries.find(
  485. (entry) => resultEqualityCheck(entry.value, value)
  486. );
  487. if (matchingEntry) {
  488. value = matchingEntry.value;
  489. resultsCount !== 0 && resultsCount--;
  490. }
  491. }
  492. cache.put(arguments, value);
  493. }
  494. return value;
  495. }
  496. memoized.clearCache = () => {
  497. cache.clear();
  498. memoized.resetResultsCount();
  499. };
  500. memoized.resultsCount = () => resultsCount;
  501. memoized.resetResultsCount = () => {
  502. resultsCount = 0;
  503. };
  504. return memoized;
  505. }
  506. // src/autotrackMemoize/autotrackMemoize.ts
  507. function autotrackMemoize(func) {
  508. const node = createNode(
  509. []
  510. );
  511. let lastArgs = null;
  512. const shallowEqual = createCacheKeyComparator(referenceEqualityCheck);
  513. const cache = createCache(() => {
  514. const res = func.apply(null, node.proxy);
  515. return res;
  516. });
  517. function memoized() {
  518. if (!shallowEqual(lastArgs, arguments)) {
  519. updateNode(node, arguments);
  520. lastArgs = arguments;
  521. }
  522. return cache.value;
  523. }
  524. memoized.clearCache = () => {
  525. return cache.clear();
  526. };
  527. return memoized;
  528. }
  529. // src/weakMapMemoize.ts
  530. var StrongRef = class {
  531. constructor(value) {
  532. this.value = value;
  533. }
  534. deref() {
  535. return this.value;
  536. }
  537. };
  538. var Ref = typeof WeakRef !== "undefined" ? WeakRef : StrongRef;
  539. var UNTERMINATED = 0;
  540. var TERMINATED = 1;
  541. function createCacheNode() {
  542. return {
  543. s: UNTERMINATED,
  544. v: void 0,
  545. o: null,
  546. p: null
  547. };
  548. }
  549. function weakMapMemoize(func, options = {}) {
  550. let fnNode = createCacheNode();
  551. const { resultEqualityCheck } = options;
  552. let lastResult;
  553. let resultsCount = 0;
  554. function memoized() {
  555. var _a;
  556. let cacheNode = fnNode;
  557. const { length } = arguments;
  558. for (let i = 0, l = length; i < l; i++) {
  559. const arg = arguments[i];
  560. if (typeof arg === "function" || typeof arg === "object" && arg !== null) {
  561. let objectCache = cacheNode.o;
  562. if (objectCache === null) {
  563. cacheNode.o = objectCache = /* @__PURE__ */ new WeakMap();
  564. }
  565. const objectNode = objectCache.get(arg);
  566. if (objectNode === void 0) {
  567. cacheNode = createCacheNode();
  568. objectCache.set(arg, cacheNode);
  569. } else {
  570. cacheNode = objectNode;
  571. }
  572. } else {
  573. let primitiveCache = cacheNode.p;
  574. if (primitiveCache === null) {
  575. cacheNode.p = primitiveCache = /* @__PURE__ */ new Map();
  576. }
  577. const primitiveNode = primitiveCache.get(arg);
  578. if (primitiveNode === void 0) {
  579. cacheNode = createCacheNode();
  580. primitiveCache.set(arg, cacheNode);
  581. } else {
  582. cacheNode = primitiveNode;
  583. }
  584. }
  585. }
  586. const terminatedNode = cacheNode;
  587. let result;
  588. if (cacheNode.s === TERMINATED) {
  589. result = cacheNode.v;
  590. } else {
  591. result = func.apply(null, arguments);
  592. resultsCount++;
  593. }
  594. terminatedNode.s = TERMINATED;
  595. if (resultEqualityCheck) {
  596. const lastResultValue = (_a = lastResult == null ? void 0 : lastResult.deref()) != null ? _a : lastResult;
  597. if (lastResultValue != null && resultEqualityCheck(lastResultValue, result)) {
  598. result = lastResultValue;
  599. resultsCount !== 0 && resultsCount--;
  600. }
  601. const needsWeakRef = typeof result === "object" && result !== null || typeof result === "function";
  602. lastResult = needsWeakRef ? new Ref(result) : result;
  603. }
  604. terminatedNode.v = result;
  605. return result;
  606. }
  607. memoized.clearCache = () => {
  608. fnNode = createCacheNode();
  609. memoized.resetResultsCount();
  610. };
  611. memoized.resultsCount = () => resultsCount;
  612. memoized.resetResultsCount = () => {
  613. resultsCount = 0;
  614. };
  615. return memoized;
  616. }
  617. // src/createSelectorCreator.ts
  618. function createSelectorCreator(memoizeOrOptions, ...memoizeOptionsFromArgs) {
  619. const createSelectorCreatorOptions = typeof memoizeOrOptions === "function" ? {
  620. memoize: memoizeOrOptions,
  621. memoizeOptions: memoizeOptionsFromArgs
  622. } : memoizeOrOptions;
  623. const createSelector2 = (...createSelectorArgs) => {
  624. let recomputations = 0;
  625. let dependencyRecomputations = 0;
  626. let lastResult;
  627. let directlyPassedOptions = {};
  628. let resultFunc = createSelectorArgs.pop();
  629. if (typeof resultFunc === "object") {
  630. directlyPassedOptions = resultFunc;
  631. resultFunc = createSelectorArgs.pop();
  632. }
  633. assertIsFunction(
  634. resultFunc,
  635. `createSelector expects an output function after the inputs, but received: [${typeof resultFunc}]`
  636. );
  637. const combinedOptions = __spreadValues(__spreadValues({}, createSelectorCreatorOptions), directlyPassedOptions);
  638. const {
  639. memoize,
  640. memoizeOptions = [],
  641. argsMemoize = weakMapMemoize,
  642. argsMemoizeOptions = [],
  643. devModeChecks = {}
  644. } = combinedOptions;
  645. const finalMemoizeOptions = ensureIsArray(memoizeOptions);
  646. const finalArgsMemoizeOptions = ensureIsArray(argsMemoizeOptions);
  647. const dependencies = getDependencies(createSelectorArgs);
  648. const memoizedResultFunc = memoize(function recomputationWrapper() {
  649. recomputations++;
  650. return resultFunc.apply(
  651. null,
  652. arguments
  653. );
  654. }, ...finalMemoizeOptions);
  655. let firstRun = true;
  656. const selector = argsMemoize(function dependenciesChecker() {
  657. dependencyRecomputations++;
  658. const inputSelectorResults = collectInputSelectorResults(
  659. dependencies,
  660. arguments
  661. );
  662. if (process.env.NODE_ENV !== "production") {
  663. const { identityFunctionCheck, inputStabilityCheck } = getDevModeChecksExecutionInfo(firstRun, devModeChecks);
  664. if (identityFunctionCheck.shouldRun) {
  665. identityFunctionCheck.run(
  666. resultFunc
  667. );
  668. }
  669. if (inputStabilityCheck.shouldRun) {
  670. const inputSelectorResultsCopy = collectInputSelectorResults(
  671. dependencies,
  672. arguments
  673. );
  674. inputStabilityCheck.run(
  675. { inputSelectorResults, inputSelectorResultsCopy },
  676. { memoize, memoizeOptions: finalMemoizeOptions },
  677. arguments
  678. );
  679. }
  680. if (firstRun)
  681. firstRun = false;
  682. }
  683. lastResult = memoizedResultFunc.apply(null, inputSelectorResults);
  684. return lastResult;
  685. }, ...finalArgsMemoizeOptions);
  686. return Object.assign(selector, {
  687. resultFunc,
  688. memoizedResultFunc,
  689. dependencies,
  690. dependencyRecomputations: () => dependencyRecomputations,
  691. resetDependencyRecomputations: () => {
  692. dependencyRecomputations = 0;
  693. },
  694. lastResult: () => lastResult,
  695. recomputations: () => recomputations,
  696. resetRecomputations: () => {
  697. recomputations = 0;
  698. },
  699. memoize,
  700. argsMemoize
  701. });
  702. };
  703. return createSelector2;
  704. }
  705. var createSelector = /* @__PURE__ */ createSelectorCreator(weakMapMemoize);
  706. // src/createStructuredSelector.ts
  707. var createStructuredSelector = (inputSelectorsObject, selectorCreator = createSelector) => {
  708. assertIsObject(
  709. inputSelectorsObject,
  710. `createStructuredSelector expects first argument to be an object where each property is a selector, instead received a ${typeof inputSelectorsObject}`
  711. );
  712. const inputSelectorKeys = Object.keys(inputSelectorsObject);
  713. const dependencies = inputSelectorKeys.map((key) => inputSelectorsObject[key]);
  714. const structuredSelector = selectorCreator(
  715. dependencies,
  716. (...inputSelectorResults) => {
  717. return inputSelectorResults.reduce((composition, value, index) => {
  718. composition[inputSelectorKeys[index]] = value;
  719. return composition;
  720. }, {});
  721. }
  722. );
  723. return structuredSelector;
  724. };
  725. export {
  726. createSelector,
  727. createSelectorCreator,
  728. createStructuredSelector,
  729. lruMemoize,
  730. referenceEqualityCheck,
  731. setGlobalDevModeChecks,
  732. autotrackMemoize as unstable_autotrackMemoize,
  733. weakMapMemoize
  734. };
  735. //# sourceMappingURL=reselect.legacy-esm.js.map