reselect.mjs 21 KB

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