| import type { CreateSelectorOptions, UnknownMemoizer } from '../types' |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export const runInputStabilityCheck = ( |
| inputSelectorResultsObject: { |
| inputSelectorResults: unknown[] |
| inputSelectorResultsCopy: unknown[] |
| }, |
| options: Required< |
| Pick< |
| CreateSelectorOptions<UnknownMemoizer, UnknownMemoizer>, |
| 'memoize' | 'memoizeOptions' |
| > |
| >, |
| inputSelectorArgs: unknown[] | IArguments |
| ) => { |
| const { memoize, memoizeOptions } = options |
| const { inputSelectorResults, inputSelectorResultsCopy } = |
| inputSelectorResultsObject |
| const createAnEmptyObject = memoize(() => ({}), ...memoizeOptions) |
| |
| const areInputSelectorResultsEqual = |
| createAnEmptyObject.apply(null, inputSelectorResults) === |
| createAnEmptyObject.apply(null, inputSelectorResultsCopy) |
| if (!areInputSelectorResultsEqual) { |
| let stack: string | undefined = undefined |
| try { |
| throw new Error() |
| } catch (e) { |
| |
| ;({ stack } = e as Error) |
| } |
| console.warn( |
| '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)`', |
| { |
| arguments: inputSelectorArgs, |
| firstInputs: inputSelectorResults, |
| secondInputs: inputSelectorResultsCopy, |
| stack |
| } |
| ) |
| } |
| } |
|
|