Skip to content

Commit

Permalink
factor out internal identityFn to utils (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
sisp committed Mar 11, 2022
1 parent a7bd0c2 commit 0bc6a0d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 2 additions & 4 deletions packages/lib/src/snapshot/getSnapshot.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { assertTweakedObject } from "../tweaker/core"
import { resolveTypeChecker } from "../types/resolveTypeChecker"
import { AnyType, TypeToData } from "../types/schemas"
import { failure, isPrimitive } from "../utils"
import { failure, identityFn, isPrimitive } from "../utils"
import {
freezeInternalSnapshot,
getInternalSnapshot,
reportInternalSnapshotObserved,
} from "./internal"
import type { SnapshotOutOf } from "./SnapshotOf"

const identityFn = (x: any) => x

/**
* Retrieves an immutable snapshot for a data structure.
* Since returned snapshots are immutable they will respect shallow equality, this is,
Expand All @@ -37,7 +35,7 @@ export function getSnapshot<T extends AnyType>(
export function getSnapshot<T>(nodeOrPrimitive: T): SnapshotOutOf<T>

export function getSnapshot(arg1: any, arg2?: any): any {
let toSnapshotProcessor = identityFn
let toSnapshotProcessor = identityFn as (sn: any) => unknown
let nodeOrPrimitive: any

if (arguments.length >= 2) {
Expand Down
4 changes: 1 addition & 3 deletions packages/lib/src/types/primitiveBased/primitives.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { assertIsPrimitive } from "../../utils"
import { assertIsPrimitive, identityFn } from "../../utils"
import type { PrimitiveValue } from "../../utils/types"
import { registerStandardTypeResolver } from "../resolveTypeChecker"
import type { AnyStandardType, IdentityType } from "../schemas"
import { TypeChecker, TypeCheckerBaseType, TypeInfo, TypeInfoGen } from "../TypeChecker"
import { TypeCheckError } from "../TypeCheckError"

const identityFn = <T>(x: T): T => x

/**
* A type that represents a certain value of a primitive (for example an *exact* number or string).
*
Expand Down
3 changes: 1 addition & 2 deletions packages/lib/src/types/utility/unchecked.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { identityFn } from "../../utils"
import type { IdentityType } from "../schemas"
import { TypeChecker, TypeCheckerBaseType, TypeInfo } from "../TypeChecker"

const identityFn = (x: any) => x

const unchecked: IdentityType<any> = new TypeChecker(
TypeCheckerBaseType.Any,
null,
Expand Down
5 changes: 5 additions & 0 deletions packages/lib/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ export function lazy<A extends unknown[], R>(getter: (...args: A) => R): typeof
}
}

/**
* @internal
*/
export const identityFn = <T>(x: T): T => x

/**
* @internal
*/
Expand Down

0 comments on commit 0bc6a0d

Please sign in to comment.