🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
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

to
0.3.0

dist/src/useSetImmerAtom.d.ts

2

dist/index.modern.js

@@ -1,2 +0,2 @@

import{produce as t}from"immer";import{atom as o}from"jotai/vanilla";import{useCallback as r}from"react";import{useAtom as n}from"jotai/react";function e(r){const n=o(r,(o,r,e)=>r(n,t(o(n),"function"==typeof e?e:()=>e)));return n}const i=new WeakMap;function f(r){return n=()=>o(t=>t(r),(o,n,e)=>n(r,t(o(r),"function"==typeof e?e:()=>e))),(i.has(e=r)?i:i.set(e,n())).get(e);var n,e}function a(o,e){const[i,f]=n(o,e);return[i,r(o=>f(t(o)),[f])]}export{e as atomWithImmer,a as useImmerAtom,f as withImmer};
import{produce as t}from"immer";import{atom as o}from"jotai/vanilla";import{useSetAtom as n,useAtomValue as r}from"jotai/react";import{useCallback as e}from"react";function i(n){const r=o(n,(o,n,e)=>n(r,t(o(r),"function"==typeof e?e:()=>e)));return r}const f=new WeakMap;function c(n){return r=()=>o(t=>t(n),(o,r,e)=>r(n,t(o(n),"function"==typeof e?e:()=>e))),(f.has(e=n)?f:f.set(e,r())).get(e);var r,e}function a(o,r){const i=n(o,r);return e(o=>i(t(o)),[i])}function m(t,o){return[r(t,o),a(t,o)]}export{i as atomWithImmer,m as useImmerAtom,a as useSetImmerAtom,c as withImmer};
//# sourceMappingURL=index.modern.mjs.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("immer"),require("jotai/vanilla"),require("react"),require("jotai/react")):"function"==typeof define&&define.amd?define(["exports","immer","jotai/vanilla","react","jotai/react"],t):t((e||self).jotaiImmer={},e.immer,e.vanilla,e.React,e.react)}(this,function(e,t,n,r,o){var i=new WeakMap;e.atomWithImmer=function(e){var r=n.atom(e,function(e,n,o){return n(r,t.produce(e(r),"function"==typeof o?o:function(){return o}))});return r},e.useImmerAtom=function(e,n){var i=o.useAtom(e,n),u=i[1];return[i[0],r.useCallback(function(e){return u(t.produce(e))},[u])]},e.withImmer=function(e){return r=function(){return n.atom(function(t){return t(e)},function(n,r,o){return r(e,t.produce(n(e),"function"==typeof o?o:function(){return o}))})},(i.has(o=e)?i:i.set(o,r())).get(o);var r,o}});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("immer"),require("jotai/vanilla"),require("jotai/react"),require("react")):"function"==typeof define&&define.amd?define(["exports","immer","jotai/vanilla","jotai/react","react"],t):t((e||self).jotaiImmer={},e.immer,e.vanilla,e.react,e.React)}(this,function(e,t,n,r,o){var u=new WeakMap;function i(e,n){var u=r.useSetAtom(e,n);return o.useCallback(function(e){return u(t.produce(e))},[u])}e.atomWithImmer=function(e){var r=n.atom(e,function(e,n,o){return n(r,t.produce(e(r),"function"==typeof o?o:function(){return o}))});return r},e.useImmerAtom=function(e,t){return[r.useAtomValue(e,t),i(e,t)]},e.useSetImmerAtom=i,e.withImmer=function(e){return r=function(){return n.atom(function(t){return t(e)},function(n,r,o){return r(e,t.produce(n(e),"function"==typeof o?o:function(){return o}))})},(u.has(o=e)?u:u.set(o,r())).get(o);var r,o}});
//# sourceMappingURL=index.umd.js.map
import type { Draft } from 'immer';
import type { WritableAtom } from 'jotai/vanilla';
export declare function atomWithImmer<Value>(initialValue: Value): WritableAtom<Value, [Value | ((draft: Draft<Value>) => void)], void>;
export { atomWithImmer } from './atomWithImmer';
export { withImmer } from './withImmer';
export { useImmerAtom } from './useImmerAtom';
export { useSetImmerAtom } from './useSetImmerAtom';
import type { Draft } from 'immer';
import { useAtom } from 'jotai/react';
import { useAtomValue } from 'jotai/react';
import type { WritableAtom } from 'jotai/vanilla';
type Scope = NonNullable<Parameters<typeof useAtom>[1]>;
export declare function useImmerAtom<Value, Result>(anAtom: WritableAtom<Value, [(draft: Draft<Value>) => void], Result>, scope?: Scope): [Value, (fn: (draft: Draft<Value>) => void) => Result];
export declare function useImmerAtom<Value, Result>(anAtom: WritableAtom<Value, [(value: Value) => Value], Result>, scope?: Scope): [Value, (fn: (draft: Draft<Value>) => void) => Result];
type Options = Parameters<typeof useAtomValue>[1];
export declare function useImmerAtom<Value, Result>(anAtom: WritableAtom<Value, [(draft: Draft<Value>) => void], Result>, options?: Options): [Value, (fn: (draft: Draft<Value>) => void) => Result];
export declare function useImmerAtom<Value, Result>(anAtom: WritableAtom<Value, [(value: Value) => Value], Result>, options?: Options): [Value, (fn: (draft: Draft<Value>) => void) => Result];
export {};

@@ -0,0 +0,0 @@ import type { Draft } from 'immer';

{
"name": "jotai-immer",
"description": "👻🪛",
"version": "0.2.0",
"version": "0.3.0",
"author": "Daishi Kato",

@@ -37,3 +37,4 @@ "repository": {

"examples:02_withImmer": "DIR=02_withImmer EXT=tsx webpack serve",
"examples:03_useImmerAtom": "DIR=03_useImmerAtom EXT=tsx webpack serve"
"examples:03_useImmerAtom": "DIR=03_useImmerAtom EXT=tsx webpack serve",
"examples:04_useSetImmerAtom": "DIR=04_useSetImmerAtom EXT=tsx webpack serve"
},

@@ -51,41 +52,41 @@ "jest": {

"license": "MIT",
"dependencies": {},
"devDependencies": {
"@testing-library/react": "^13.4.0",
"@types/jest": "^29.4.0",
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"@typescript-eslint/parser": "^5.50.0",
"eslint": "^8.33.0",
"eslint-config-prettier": "^8.6.0",
"@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",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.32.2",
"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.5.0",
"immer": "^9.0.19",
"jest": "^29.4.1",
"jest-environment-jsdom": "^29.4.1",
"jotai": "^2.0.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": "^2.8.3",
"prettier": "^3.1.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^3.1.4",
"ts-jest": "^29.0.5",
"ts-loader": "^9.4.2",
"typescript": "^4.9.5",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.11.1"
"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"
},
"peerDependencies": {
"immer": "*",
"jotai": ">=1.11.0",
"jotai": ">=2.0.0",
"react": ">=17.0.0"
}
}
export { atomWithImmer } from './atomWithImmer'
export { withImmer } from './withImmer'
export { useImmerAtom } from './useImmerAtom'
export { useSetImmerAtom } from './useSetImmerAtom'

@@ -1,12 +0,11 @@

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

@@ -16,3 +15,3 @@

anAtom: WritableAtom<Value, [(value: Value) => Value], Result>,
scope?: Scope
options?: Options
): [Value, (fn: (draft: Draft<Value>) => void) => Result]

@@ -22,10 +21,5 @@

anAtom: WritableAtom<Value, [(value: Value) => Value], Result>,
scope?: Scope
options?: Options
) {
const [state, setState] = useAtom(anAtom, scope)
const setStateWithImmer = useCallback(
(fn: (draft: Draft<Value>) => void) => setState(produce(fn)),
[setState]
)
return [state, setStateWithImmer]
return [useAtomValue(anAtom, options), useSetImmerAtom(anAtom, options)]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet