Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jotai-immer

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jotai-immer - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

dist/atomWithImmer.d.ts

110

package.json
{
"name": "jotai-immer",
"description": "👻🪛",
"version": "0.3.0",
"version": "0.4.0",
"type": "module",
"author": "Daishi Kato",

@@ -11,12 +12,15 @@ "repository": {

"source": "./src/index.ts",
"main": "./dist/index.umd.js",
"module": "./dist/index.modern.js",
"types": "./dist/src/index.d.ts",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/src/index.d.ts",
"module": "./dist/index.modern.js",
"import": "./dist/index.modern.mjs",
"default": "./dist/index.umd.js"
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
},
"default": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}

@@ -29,18 +33,18 @@ },

],
"packageManager": "pnpm@8.15.0",
"scripts": {
"compile": "microbundle build -f modern,umd --globals react=React",
"postcompile": "cp dist/index.modern.mjs dist/index.modern.js && cp dist/index.modern.mjs.map dist/index.modern.js.map",
"test": "run-s eslint tsc-test jest",
"eslint": "eslint --ext .js,.ts,.tsx .",
"jest": "jest",
"tsc-test": "tsc --project . --noEmit",
"examples:01_atomWithImmer": "DIR=01_atomWithImmer EXT=tsx webpack serve",
"examples:02_withImmer": "DIR=02_withImmer EXT=tsx webpack serve",
"examples:03_useImmerAtom": "DIR=03_useImmerAtom EXT=tsx webpack serve",
"examples:04_useSetImmerAtom": "DIR=04_useSetImmerAtom EXT=tsx webpack serve"
"compile": "rm -rf dist && pnpm run '/^compile:.*/'",
"compile:esm": "tsc -p tsconfig.esm.json",
"compile:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
"test": "pnpm run '/^test:.*/'",
"test:format": "prettier -c .",
"test:lint": "eslint .",
"test:types": "tsc -p . --noEmit",
"test:types:examples": "tsc -p examples --noEmit",
"test:spec": "vitest run",
"examples:01_atomWithImmer": "DIR=01_atomWithImmer vite",
"examples:02_withImmer": "DIR=02_withImmer vite",
"examples:03_useImmerAtom": "DIR=03_useImmerAtom vite",
"examples:04_useSetImmerAtom": "DIR=04_useSetImmerAtom vite"
},
"jest": {
"testEnvironment": "jsdom",
"preset": "ts-jest/presets/js-with-ts"
},
"keywords": [

@@ -53,41 +57,37 @@ "jotai",

"license": "MIT",
"prettier": {
"singleQuote": true
},
"devDependencies": {
"@testing-library/react": "^14.1.2",
"@types/jest": "^29.5.11",
"@types/node": "^20.10.6",
"@types/react": "^18.2.46",
"@types/react-dom": "^18.2.18",
"@typescript-eslint/eslint-plugin": "^6.17.0",
"@typescript-eslint/parser": "^6.17.0",
"eslint": "^8.56.0",
"@testing-library/jest-dom": "^6.4.5",
"@testing-library/react": "^15.0.7",
"@testing-library/user-event": "^14.5.2",
"@types/node": "^20.12.12",
"@types/react": "^18.3.2",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^7.10.0",
"@typescript-eslint/parser": "^7.10.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.6.1",
"eslint-plugin-prettier": "^5.1.2",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"html-webpack-plugin": "^5.6.0",
"immer": "^10.0.3",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jotai": "^2.6.1",
"microbundle": "^0.15.1",
"npm-run-all": "^4.1.5",
"prettier": "^3.1.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.12",
"ts-jest": "^29.1.1",
"ts-loader": "^9.5.1",
"typescript": "^5.3.3",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1"
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.2",
"happy-dom": "^14.11.0",
"immer": "^10.1.1",
"jotai": "^2.8.0",
"jotai-immer": "link:",
"prettier": "^3.2.5",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"ts-expect": "^1.3.0",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"vitest": "^1.6.0"
},
"peerDependencies": {
"immer": "*",
"jotai": ">=2.0.0",
"react": ">=17.0.0"
"immer": ">=9.0.0",
"jotai": ">=2.0.0"
}
}

@@ -1,10 +0,14 @@

import { produce } from 'immer'
import type { Draft } from 'immer'
import { atom } from 'jotai/vanilla'
import type { WritableAtom } from 'jotai/vanilla'
import { produce } from 'immer';
import type { Draft } from 'immer';
import { atom } from 'jotai/vanilla';
import type { WritableAtom } from 'jotai/vanilla';
export function atomWithImmer<Value>(
initialValue: Value
initialValue: Value,
): WritableAtom<Value, [Value | ((draft: Draft<Value>) => void)], void> {
const anAtom: any = atom(
const anAtom: WritableAtom<
Value,
[Value | ((draft: Draft<Value>) => void)],
void
> = atom(
initialValue,

@@ -18,7 +22,7 @@ (get, set, fn: Value | ((draft: Draft<Value>) => void)) =>

? (fn as (draft: Draft<Value>) => void)
: () => fn
)
)
)
return anAtom
: () => fn,
),
),
);
return anAtom;
}

@@ -1,4 +0,4 @@

export { atomWithImmer } from './atomWithImmer'
export { withImmer } from './withImmer'
export { useImmerAtom } from './useImmerAtom'
export { useSetImmerAtom } from './useSetImmerAtom'
export { atomWithImmer } from './atomWithImmer.js';
export { withImmer } from './withImmer.js';
export { useImmerAtom } from './useImmerAtom.js';
export { useSetImmerAtom } from './useSetImmerAtom.js';

@@ -1,23 +0,24 @@

import type { Draft } from 'immer'
import { useAtomValue } from 'jotai/react'
import type { WritableAtom } from 'jotai/vanilla'
import { useSetImmerAtom } from './useSetImmerAtom'
import type { Draft } from 'immer';
import { useAtomValue } from 'jotai/react';
import type { WritableAtom } from 'jotai/vanilla';
type Options = Parameters<typeof useAtomValue>[1]
import { useSetImmerAtom } from './useSetImmerAtom.js';
type Options = Parameters<typeof useAtomValue>[1];
export function useImmerAtom<Value, Result>(
anAtom: WritableAtom<Value, [(draft: Draft<Value>) => void], Result>,
options?: Options
): [Value, (fn: (draft: Draft<Value>) => void) => Result]
options?: Options,
): [Value, (fn: (draft: Draft<Value>) => void) => Result];
export function useImmerAtom<Value, Result>(
anAtom: WritableAtom<Value, [(value: Value) => Value], Result>,
options?: Options
): [Value, (fn: (draft: Draft<Value>) => void) => Result]
options?: Options,
): [Value, (fn: (draft: Draft<Value>) => void) => Result];
export function useImmerAtom<Value, Result>(
anAtom: WritableAtom<Value, [(value: Value) => Value], Result>,
options?: Options
options?: Options,
) {
return [useAtomValue(anAtom, options), useSetImmerAtom(anAtom, options)]
return [useAtomValue(anAtom, options), useSetImmerAtom(anAtom, options)];
}

@@ -1,28 +0,28 @@

import { useCallback } from 'react'
import { produce } from 'immer'
import type { Draft } from 'immer'
import { useSetAtom } from 'jotai/react'
import type { WritableAtom } from 'jotai/vanilla'
import { useCallback } from 'react';
import { produce } from 'immer';
import type { Draft } from 'immer';
import { useSetAtom } from 'jotai/react';
import type { WritableAtom } from 'jotai/vanilla';
type Options = Parameters<typeof useSetAtom>[1]
type Options = Parameters<typeof useSetAtom>[1];
export function useSetImmerAtom<Value, Result>(
anAtom: WritableAtom<Value, [(draft: Draft<Value>) => void], Result>,
options?: Options
): (fn: (draft: Draft<Value>) => void) => Result
options?: Options,
): (fn: (draft: Draft<Value>) => void) => Result;
export function useSetImmerAtom<Value, Result>(
anAtom: WritableAtom<Value, [(value: Value) => Value], Result>,
options?: Options
): (fn: (draft: Draft<Value>) => void) => Result
options?: Options,
): (fn: (draft: Draft<Value>) => void) => Result;
export function useSetImmerAtom<Value, Result>(
anAtom: WritableAtom<Value, [(value: Value) => Value], Result>,
options?: Options
options?: Options,
) {
const setState = useSetAtom(anAtom, options)
const setState = useSetAtom(anAtom, options);
return useCallback(
(fn: (draft: Draft<Value>) => void) => setState(produce(fn)),
[setState]
)
[setState],
);
}

@@ -1,20 +0,20 @@

import { produce } from 'immer'
import type { Draft } from 'immer'
import { atom } from 'jotai/vanilla'
import type { PrimitiveAtom, WritableAtom } from 'jotai/vanilla'
import { produce } from 'immer';
import type { Draft } from 'immer';
import { atom } from 'jotai/vanilla';
import type { PrimitiveAtom, WritableAtom } from 'jotai/vanilla';
const cache1 = new WeakMap()
const cache1 = new WeakMap();
const memo1 = <T>(create: () => T, dep1: object): T =>
(cache1.has(dep1) ? cache1 : cache1.set(dep1, create())).get(dep1)
(cache1.has(dep1) ? cache1 : cache1.set(dep1, create())).get(dep1);
export function withImmer<Value>(
anAtom: PrimitiveAtom<Value>
): WritableAtom<Value, [Value | ((draft: Draft<Value>) => void)], void>
anAtom: PrimitiveAtom<Value>,
): WritableAtom<Value, [Value | ((draft: Draft<Value>) => void)], void>;
export function withImmer<Value, Result>(
anAtom: WritableAtom<Value, [Value], Result>
): WritableAtom<Value, [Value | ((draft: Draft<Value>) => void)], Result>
anAtom: WritableAtom<Value, [Value], Result>,
): WritableAtom<Value, [Value | ((draft: Draft<Value>) => void)], Result>;
export function withImmer<Value, Result>(
anAtom: WritableAtom<Value, [Value], Result>
anAtom: WritableAtom<Value, [Value], Result>,
) {

@@ -31,8 +31,8 @@ return memo1(() => {

? (fn as (draft: Draft<Value>) => void)
: () => fn
)
)
)
return derivedAtom
}, anAtom)
: () => fn,
),
),
);
return derivedAtom;
}, anAtom);
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc