@tamagui/is-equal-shallow 2.0.0-rc.11 → 2.0.0-rc.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/is-equal-shallow",
3
- "version": "2.0.0-rc.11",
3
+ "version": "2.0.0-rc.12",
4
4
  "files": [
5
5
  "src",
6
6
  "types",
@@ -31,7 +31,7 @@
31
31
  "clean:build": "tamagui-build clean:build"
32
32
  },
33
33
  "devDependencies": {
34
- "@tamagui/build": "2.0.0-rc.11",
34
+ "@tamagui/build": "2.0.0-rc.12",
35
35
  "react": ">=19"
36
36
  },
37
37
  "peerDependencies": {
@@ -4,8 +4,8 @@
4
4
  "sources": [
5
5
  "src/index.ts"
6
6
  ],
7
+ "version": 3,
7
8
  "sourcesContent": [
8
9
  "import { useCallback } from 'react'\n\ntype DebugProp = null | undefined | boolean | 'profile' | 'verbose' | 'break'\n\nexport type CallbackSetState<State> = (next: (cb: State) => State) => void\n\nexport function useCreateShallowSetState<State extends Record<string, unknown>>(\n setter: CallbackSetState<State>,\n debug?: DebugProp\n): React.Dispatch<React.SetStateAction<Partial<State>>> {\n // this must be memoized or it ruins performance in components\n return useCallback(\n (stateOrGetState) => {\n setter((prev) => {\n const next =\n typeof stateOrGetState === 'function' ? stateOrGetState(prev) : stateOrGetState\n const update = mergeIfNotShallowEqual(prev, next)\n\n if (process.env.NODE_ENV === 'development') {\n if (debug && update !== prev) {\n console.groupCollapsed(`setStateShallow CHANGE`, '=>', update)\n console.info(`previously`, prev)\n console.trace()\n console.groupEnd()\n if (debug === 'break') {\n // debugger is intentionally here for debugging\n }\n }\n }\n return update\n })\n },\n [setter, debug]\n )\n}\n\nexport function mergeIfNotShallowEqual<State extends Record<string, unknown>>(\n prev: State,\n next: Partial<State>\n): State {\n if (!prev || !next || isEqualShallow(prev, next)) {\n if (!prev) return next as State\n return prev\n }\n return { ...prev, ...next }\n}\n\nexport function isEqualShallow(\n prev: Record<string, unknown>,\n next: Record<string, unknown>\n): boolean {\n for (const key in next) {\n if (prev[key] !== next[key]) {\n return false\n }\n }\n return true\n}\n"
9
- ],
10
- "version": 3
10
+ ]
11
11
  }