Skip to content

Commit

Permalink
Merge branch 'noop-check' of https://github.com/aryaemami59/reselect
Browse files Browse the repository at this point in the history
…into noop-check
  • Loading branch information
aryaemami59 committed Nov 30, 2023
2 parents 4cd963d + 52eb002 commit 8774936
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 177 deletions.
7 changes: 6 additions & 1 deletion src/autotrackMemoize/autotrackMemoize.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { createNode, updateNode } from './proxy'
import type { Node } from './tracking'

import type {
AnyFunction,
DefaultMemoizeFields,
Simplify
} from '@internal/types'
import {
createCacheKeyComparator,
defaultEqualityCheck
} from '../defaultMemoize'
import type { AnyFunction, DefaultMemoizeFields, Simplify } from '../types'
import { createCache } from './autotracking'

/**
Expand Down Expand Up @@ -54,6 +58,7 @@ import { createCache } from './autotracking'
* <caption>Using `createSelectorCreator`</caption>
* ```ts
* import { unstable_autotrackMemoize as autotrackMemoize, createSelectorCreator } from 'reselect'
import { createCacheKeyComparator, defaultEqualityCheck } from '../defaultMemoize';
*
* const createSelectorAutotrack = createSelectorCreator({ memoize: autotrackMemoize })
*
Expand Down
1 change: 1 addition & 0 deletions src/autotrackMemoize/autotracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Additional references:
// - https://www.pzuraq.com/blog/how-autotracking-works
// - https://v5.chriskrycho.com/journal/autotracking-elegant-dx-via-cutting-edge-cs/

import type { EqualityFn } from '../types'
import { assertIsFunction } from '../utils'

Expand Down
2 changes: 1 addition & 1 deletion src/devModeChecks/identityFunctionCheck.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AnyFunction } from '../types'
import type { AnyFunction } from '@internal/types'

/**
* Runs a check to determine if the given result function behaves as an
Expand Down
2 changes: 1 addition & 1 deletion src/devModeChecks/inputStabilityCheck.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CreateSelectorOptions, UnknownMemoizer } from '../types'
import type { CreateSelectorOptions, UnknownMemoizer } from '@internal/types'

/**
* Runs a stability check to ensure the input selector results remain stable
Expand Down
2 changes: 1 addition & 1 deletion src/devModeChecks/setGlobalDevModeChecks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DevModeChecks } from '../types'
import type { DevModeChecks } from '@internal/types'

/**
* Global configuration for development mode checks. This specifies the default
Expand Down
12 changes: 8 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { runIdentityFunctionCheck } from './devModeChecks/identityFunctionCheck'
import { runInputStabilityCheck } from './devModeChecks/inputStabilityCheck'
import { globalDevModeChecks } from './devModeChecks/setGlobalDevModeChecks'
import type { DevModeChecks, Selector, SelectorArray } from './types'
import { DevModeChecksExecutionInfo } from './types'
import type {
DevModeChecks,
DevModeChecksExecutionInfo,
Selector,
SelectorArray
} from './types'

export const NOT_FOUND = 'NOT_FOUND'
export type NOT_FOUND_TYPE = typeof NOT_FOUND
Expand Down Expand Up @@ -129,7 +133,7 @@ export function collectInputSelectorResults(
export const getDevModeChecksExecutionInfo = (
firstRun: boolean,
devModeChecks: Partial<DevModeChecks>
) => {
): DevModeChecksExecutionInfo => {
const { identityFunctionCheck, inputStabilityCheck } = {
...globalDevModeChecks,
...devModeChecks
Expand All @@ -147,5 +151,5 @@ export const getDevModeChecksExecutionInfo = (
(inputStabilityCheck === 'once' && firstRun),
run: runInputStabilityCheck
}
} satisfies DevModeChecksExecutionInfo
} as DevModeChecksExecutionInfo
}
2 changes: 1 addition & 1 deletion src/versionedTypes/ts47-mergeParameters.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This entire implementation courtesy of Anders Hjelsberg:
// https://github.com/microsoft/TypeScript/pull/50831#issuecomment-1253830522

import type { AnyFunction } from '../types'
import type { AnyFunction } from '@internal/types'

/**
* Represents the longest array within an array of arrays.
Expand Down
5 changes: 4 additions & 1 deletion src/weakMapMemoize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,10 @@ export function weakMapMemoize<Func extends AnyFunction>(

if (resultEqualityCheck) {
const lastResultValue = lastResult?.deref() ?? lastResult
if (lastResultValue != null && resultEqualityCheck(lastResultValue, result)) {
if (
lastResultValue != null &&
resultEqualityCheck(lastResultValue, result)
) {
result = lastResultValue
resultsCount !== 0 && resultsCount--
}
Expand Down
5 changes: 4 additions & 1 deletion typescript_test/argsMemoize.typetest.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import memoizeOne from 'memoize-one'
import microMemoize from 'micro-memoize'
import {
unstable_autotrackMemoize as autotrackMemoize,
createSelector,
createSelectorCreator,
defaultMemoize,
setGlobalDevModeChecks,
unstable_autotrackMemoize as autotrackMemoize,
weakMapMemoize
} from 'reselect'
import { expectExactType } from './typesTestUtils'

setGlobalDevModeChecks({ identityFunctionCheck: 'never' })

interface RootState {
todos: {
id: number
Expand Down
1 change: 1 addition & 0 deletions typescript_test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"module": "commonjs",
"strict": true,
"target": "ES2015",
"esModuleInterop": true,
"lib": ["ES2021.WeakRef"],
"declaration": true,
"noEmit": true,
Expand Down
21 changes: 14 additions & 7 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
import { defineConfig } from 'vitest/config'

import { fileURLToPath } from 'url'
import path from 'path'
import { defineConfig } from 'vitest/config'

// No __dirname under Node ESM
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
// const __filename = fileURLToPath(import.meta.url)
// const __dirname = path.dirname(__filename)

export default defineConfig({
resolve: {
alias: {
reselect: path.resolve(__dirname, 'src/index.ts'), // @remap-prod-remove-line
'@internal/': path.resolve(__dirname, 'src')
}
},
test: {
typecheck: { tsconfig: './type-tests/tsconfig.json' },
globals: true,
include: ['./test/**/*.(spec|test).[jt]s?(x)'],
environment: 'jsdom',
alias: {
reselect: path.join(__dirname, 'src/index.ts'), // @remap-prod-remove-line
// reselect: './src/index.ts', // @remap-prod-remove-line
// reselect: path.join(__dirname, 'src/index.ts'), // @remap-prod-remove-line

// this mapping is disabled as we want `dist` imports in the tests only to be used for "type-only" imports which don't play a role for jest
'@internal/': path.join(__dirname, 'src')
// '@internal/': './src/'
// '@internal/': path.join(__dirname, 'src')
},
deps: {
interopDefault: true
Expand Down
Loading

0 comments on commit 8774936

Please sign in to comment.