You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

j-atom

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

j-atom - npm Package Compare versions

Comparing version
0.0.1
to
0.1.0
+1
-1
index.d.ts

@@ -5,3 +5,3 @@ export interface Atom<T> {

sub(subscriber: (val: T, old?: T) => void | (() => void), options?: {
now?: boolean;
defer?: boolean;
skip?(val: T, old?: T): boolean;

@@ -8,0 +8,0 @@ }): () => void;

@@ -20,7 +20,7 @@ export function makeAtom(initial) {

},
sub(subscriber, { now = false, skip } = {}) {
sub(subscriber, { defer = false, skip } = {}) {
const id = count++;
subscribers[id] = {
subscriber,
cleanup: now && !skip?.(value, undefined) ? subscriber(value, undefined) : undefined,
cleanup: !defer && !skip?.(value, undefined) ? subscriber(value, undefined) : undefined,
skip,

@@ -27,0 +27,0 @@ };

{
"name": "j-atom",
"version": "0.0.1",
"version": "0.1.0",
"type": "module",
"scripts": {
"prepublishOnly": "npx tsc index.ts react.ts --lib esnext,dom --target esnext --declaration --skipLibCheck --moduleResolution bundler --module esnext",
"test": "vitest run *.test.ts",
"test:coverage": "vitest run --coverage *.test.ts"
"prepublishOnly": "npx tsc",
"test": "vitest run useAtom.test.ts && node --test makeAtom.test.ts",
"test:coverage": "vitest run --coverage useAtom.test.ts && node --test --experimental-test-coverage makeAtom.test.ts"
},

@@ -31,2 +32,3 @@ "exports": {

"@testing-library/react": "^16.3.0",
"@types/node": "^25.3.5",
"@types/react": "^19.2.7",

@@ -33,0 +35,0 @@ "@types/react-dom": "^19.2.3",

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

import type { Atom } from './index';
import type { Atom } from './index.js';
export declare function useAtom<T>(atom: Atom<T>): T;

@@ -33,4 +33,4 @@ # j-atom - Javascript State Management Library

// subscribe and run immediately
const unsub4 = atom.sub((newVal, oldVal) => console.log(newVal, oldVal), {now: true})
// subscribe without running immediately
const unsub4 = atom.sub((newVal, oldVal) => console.log(newVal, oldVal), {defer: true})

@@ -55,3 +55,3 @@ // subscribe with conditional updates

- Options:
- `now: boolean` - Call subscriber immediately with current value
- `defer: boolean` - If true, skip the immediate call with current value (default: false)
- `skip: (newVal, oldVal) => boolean` - Skip subscriber if returns true