bansa 0.0.1 → 0.0.2

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.
@@ -0,0 +1 @@
1
+ var l=function(){};l.prototype.get=function(){if(this.n||(h(this),i(this)),this.state.promise)throw this.state.promise;if(this.state.error)throw this.state.error;return this.state.value};l.prototype.watch=function(e){return this.n||S(this),(this.l??=new Set).add(e),()=>{this.l.delete(e),this.l.size||i(this)}};l.prototype.subscribe=function(e){let t={f:e,V:{get signal(){return(t.t??=P()).signal}}};if(!this.n)S(this);else if(!this.state.promise&&!this.state.error)try{e(this.state.value,t.V)}catch(o){console.error(o)}return(this.s??=new Set).add(t),()=>{this.s.delete(t),t.t&&(t.t.abort(),t.t=void 0),this.s.size||i(this)}};l.prototype[Symbol.toPrimitive]=function(){return this.state.value};var s=function(e,t){this.c=t?.equals,this.state={promise:void 0,error:void 0,value:e},this.state.value=this.a=e};s.prototype.set=function(e){let t=e instanceof Function?e(this.a):e;y(t,this.state.value,this.c)||(this.a=t,A(this))};s.prototype.m=!0;s.prototype.n=!0;s.prototype.o=!1;Object.setPrototypeOf(s.prototype,l.prototype);var u=function(e,t){this.y=e,this.c=t?.equals,this.b=t?.persist,this.state={promise:v,error:void 0,value:void 0};let o=this;this.V={get signal(){return(o.t??=P()).signal}}};u.prototype.m=!1;u.prototype.n=!1;u.prototype.o=!1;u.prototype.i=0;Object.setPrototypeOf(u.prototype,l.prototype);var V=()=>V,g=()=>{};Object.setPrototypeOf(V,new Proxy(V,{get:(e,t)=>t===Symbol.toPrimitive?g:V}));var v=Promise.resolve(),k=(e,t)=>e instanceof Function?new u(e,t):new s(e,t),O=e=>k((t,o)=>{let r,n,m=e(x=>{try{return t(x)}catch(p){if(!p)throw p;b(p)?(r??=[]).push(p):n=p}return V},o);if(n)throw n;if(r)throw Promise.all(r);return m}),f=!1,a=[],S=e=>{e.u||(e.u=!0,A(e))},A=e=>{e.o||(e.o=!0,a.push(e),f||(f=!0,queueMicrotask(_)))},_=()=>{f=!1;{let t=a;a=[];for(let o of t)o.state.promise=void 0,o.state.error=o.A,o.state.value=o.a,I(o)}let e=a;a=[];for(let t=e.length;t--;){let o=e[t];o.d=!1,o.u&&(o.o=!0,h(o)),o.o&&w(o)}},w=e=>{if(e.o=!1,e.r)for(let t of e.r)t.u=!0;if(e.l)for(let t of e.l)t();if(e.s&&!e.state.promise&&!e.state.error)for(let t of e.s){t.t&&(t.t.abort(),t.t=void 0);try{t.f(e.state.value,t.V)}catch(o){console.error(o)}}},I=e=>{if(!e.d){if(e.d=!0,e.r)for(let t of e.r)I(t);a.push(e)}},c=class{e;constructor(t){this.e=t}},h=e=>{let t=++e.i;e.n=!0,e.u=!1,e.state.promise=void 0,e.t&&(e.t.abort(),e.t=void 0);let o=e.p;o&&(e.p=new Set);try{let r=e.y((n,m=!0)=>{if(t!==e.i)throw void 0;if(e!==n&&(n.n||(h(n),n.o&&(n.o=!1,w(n))),o?.delete(n),(e.p??=new Set).add(n),(n.r??=new Set).add(e)),!m)return n.state;if(n.state.promise)throw new c(n.state.promise);if(n.state.error)throw new c(n.state.error);return n.state.value},e.V);b(r)?(e.state.promise=r,r.then(n=>{t===e.i&&(y(n,e.state.value,e.c)?e.state.promise=void 0:(e.a=n,e.A=void 0,A(e)))},n=>{t===e.i&&(n instanceof Promise?e.state.promise=void 0:(e.A=n,A(e)))})):(++e.i,e.state.error=void 0,y(r,e.state.value,e.c)?e.o=!1:e.state.value=e.a=r)}catch(r){++e.i,r?(r instanceof c?r=r.e:console.error(r),b(r)?e.state.promise=r:e.state.error=r):e.o=!1}if(o)for(let r of o)r.r.delete(e),i(r)},d=!1,i=e=>{if(!e.m&&!e.b&&!e.r?.size&&!e.l?.size&&!e.s?.size){if(!d){setTimeout(()=>{d=!0,i(e),d=!1},0);return}if(e.state.promise=v,e.a=e.A=e.state.error=e.state.value=void 0,e.o=e.u=e.n=!1,e.t&&(e.t.abort(),e.t=void 0),e.p){for(let t of e.p)t.r.delete(e),i(t);e.p.clear()}}},y=(e,t,o)=>Object.is(e,t)||o!==void 0&&t!==void 0&&o(e,t),b=e=>typeof e?.then=="function",P=()=>{let e=new AbortController,t=e.signal,o=new Promise(r=>{t.then=n=>o.then(n),t.addEventListener("abort",r,{once:!0,passive:!0})});return{abort:()=>e.abort(),signal:t}};export{k as $,O as $$,v as inactive};
@@ -0,0 +1,80 @@
1
+ export type Atom<Value> = PrimitiveAtom<Value> | DerivedAtom<Value>;
2
+ export type CommonAtom<Value> = {
3
+ readonly get: () => Value;
4
+ readonly watch: (watcher: AtomWatcher) => () => void;
5
+ readonly subscribe: (subscriber: AtomSubscribe<Value>) => () => void;
6
+ readonly state: AtomState<Value>;
7
+ };
8
+ export type PrimitiveAtom<Value> = CommonAtom<Value> & {
9
+ readonly set: (value: AtomUpdater<Value>) => void;
10
+ readonly state: AtomSuccessState<Value>;
11
+ };
12
+ export type DerivedAtom<Value> = CommonAtom<Value>;
13
+ export type AtomWatcher = () => void;
14
+ export type AtomSubscribe<Value> = (value: Value, options: AtomSubscriberOptions) => void;
15
+ export type AtomInit<Value> = Value | AtomGetter<Value>;
16
+ export type AtomUpdater<Value> = Value | AtomReducer<Value>;
17
+ export type AtomInactiveState<Value> = {
18
+ promise: typeof inactive;
19
+ error: any;
20
+ value?: Value;
21
+ };
22
+ export type AtomPromiseState<Value> = {
23
+ promise: PromiseLike<Value>;
24
+ error: any;
25
+ value?: Value;
26
+ };
27
+ export type AtomSuccessState<Value> = {
28
+ promise: undefined;
29
+ error: undefined;
30
+ value: Value;
31
+ };
32
+ export type AtomErrorState<Value> = {
33
+ promise: undefined;
34
+ error: any;
35
+ value?: Value;
36
+ };
37
+ export type AtomState<Value> = AtomInactiveState<Value> | AtomPromiseState<Value> | AtomSuccessState<Value> | AtomErrorState<Value>;
38
+ export type AtomSubscriberOptions = {
39
+ readonly signal: ThenableSignal;
40
+ };
41
+ export type AtomGetter<Value> = (get: GetAtom, options: AtomGetOptions) => Value | PromiseLike<Value>;
42
+ export type AtomReducer<Value> = (value: Value) => Value;
43
+ export type AtomGetOptions = {
44
+ readonly signal: ThenableSignal;
45
+ };
46
+ export type ThenableSignal = AbortSignal & {
47
+ then: (f: () => void) => void;
48
+ };
49
+ export type GetAtom = {
50
+ <Value>(anotherAtom: Atom<Value>, unwrap?: true): Value;
51
+ <Value>(anotherAtom: Atom<Value>, unwrap: false): AtomState<Value>;
52
+ };
53
+ type CreateAtom = {
54
+ <Value>(init: AtomGetter<Value>, options?: AtomOptions<Value>): DerivedAtom<Value>;
55
+ <Value>(init: Value, options?: AtomOptions<Value>): PrimitiveAtom<Value>;
56
+ <Value>(init: Value | AtomGetter<Value>, options?: AtomOptions<Value>): Atom<Value>;
57
+ };
58
+ export type AtomOptions<Value> = {
59
+ equals?: AtomEquals<Value>;
60
+ persist?: boolean;
61
+ eager?: boolean;
62
+ };
63
+ export type AtomEquals<Value> = (value: Value, prevValue: Value) => boolean;
64
+ export type AtomScope = {
65
+ <Value>(baseAtom: PrimitiveAtom<Value>): PrimitiveAtom<Value>;
66
+ <Value>(baseAtom: DerivedAtom<Value>): DerivedAtom<Value>;
67
+ <Value>(baseAtom: Atom<Value>): Atom<Value>;
68
+ } & {
69
+ get: {
70
+ <Value>(baseAtom: PrimitiveAtom<Value>): PrimitiveAtom<Value>;
71
+ <Value>(baseAtom: DerivedAtom<Value>): DerivedAtom<Value>;
72
+ <Value>(baseAtom: Atom<Value>): Atom<Value>;
73
+ };
74
+ };
75
+ export type SetLike<Key> = Key[] | Set<Key> | (Key extends object ? WeakSet<Key> : never);
76
+ export type MapLike<Key, Value> = Map<Key, Value> | (Key extends object ? WeakMap<Key, Value> : never) | (Key extends string | number | symbol ? Record<Key, Value> : never);
77
+ export declare const inactive: Promise<void>;
78
+ export declare const $: CreateAtom;
79
+ export declare const $$: <Value>(init: AtomGetter<Value>) => DerivedAtom<Value>;
80
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,368 @@
1
+ const AtomPrototype = function() {
2
+ };
3
+ AtomPrototype.prototype.get = function() {
4
+ if (!this.c) {
5
+ execute(this);
6
+ disableAtom(this);
7
+ }
8
+ if (this.state.promise) throw this.state.promise;
9
+ if (this.state.error) throw this.state.error;
10
+ return this.state.value;
11
+ };
12
+ AtomPrototype.prototype.watch = function(watcher) {
13
+ if (!this.c) {
14
+ requestActivate(this);
15
+ }
16
+ (this.h ??= /* @__PURE__ */ new Set()).add(watcher);
17
+ return () => {
18
+ this.h.delete(watcher);
19
+ if (!this.h.size) {
20
+ disableAtom(this);
21
+ }
22
+ };
23
+ };
24
+ AtomPrototype.prototype.subscribe = function(subscriber) {
25
+ const atomSubscriber = {
26
+ q: subscriber,
27
+ l: {
28
+ get signal() {
29
+ return (atomSubscriber.a ??= createThenableSignal()).signal;
30
+ }
31
+ }
32
+ };
33
+ if (!this.c) {
34
+ requestActivate(this);
35
+ } else if (!this.state.promise && !this.state.error) {
36
+ try {
37
+ subscriber(this.state.value, atomSubscriber.l);
38
+ } catch (e) {
39
+ console.error(e);
40
+ }
41
+ }
42
+ (this.i ??= /* @__PURE__ */ new Set()).add(atomSubscriber);
43
+ return () => {
44
+ this.i.delete(atomSubscriber);
45
+ if (atomSubscriber.a) {
46
+ atomSubscriber.a.abort();
47
+ atomSubscriber.a = void 0;
48
+ }
49
+ if (!this.i.size) {
50
+ disableAtom(this);
51
+ }
52
+ };
53
+ };
54
+ AtomPrototype.prototype[Symbol.toPrimitive] = function() {
55
+ return this.state.value;
56
+ };
57
+ const PrimitiveAtomPrototype = function(init, options) {
58
+ this.m = options?.equals;
59
+ this.state = {
60
+ promise: void 0,
61
+ error: void 0,
62
+ value: init
63
+ };
64
+ this.state.value = this.f = init;
65
+ };
66
+ PrimitiveAtomPrototype.prototype.set = function(value) {
67
+ const nextValue = value instanceof Function ? value(this.f) : value;
68
+ if (!equals(nextValue, this.state.value, this.m)) {
69
+ this.f = nextValue;
70
+ requestPropagate(this);
71
+ }
72
+ };
73
+ PrimitiveAtomPrototype.prototype.o = true;
74
+ PrimitiveAtomPrototype.prototype.c = true;
75
+ PrimitiveAtomPrototype.prototype.b = false;
76
+ Object.setPrototypeOf(
77
+ PrimitiveAtomPrototype.prototype,
78
+ AtomPrototype.prototype
79
+ );
80
+ const DerivedAtomPrototype = function(init, options) {
81
+ this.r = init;
82
+ this.m = options?.equals;
83
+ this.s = options?.persist;
84
+ this.state = {
85
+ promise: inactive,
86
+ error: void 0,
87
+ value: void 0
88
+ };
89
+ const self = this;
90
+ this.l = {
91
+ get signal() {
92
+ return (self.a ??= createThenableSignal()).signal;
93
+ }
94
+ };
95
+ };
96
+ DerivedAtomPrototype.prototype.o = false;
97
+ DerivedAtomPrototype.prototype.c = false;
98
+ DerivedAtomPrototype.prototype.b = false;
99
+ DerivedAtomPrototype.prototype.g = 0;
100
+ Object.setPrototypeOf(DerivedAtomPrototype.prototype, AtomPrototype.prototype);
101
+ const ouroboros = () => ouroboros;
102
+ const toUndefined = () => void 0;
103
+ Object.setPrototypeOf(
104
+ ouroboros,
105
+ new Proxy(ouroboros, {
106
+ get: (_, k) => k === Symbol.toPrimitive ? toUndefined : ouroboros
107
+ })
108
+ );
109
+ const inactive = Promise.resolve();
110
+ const $ = (init, options) => {
111
+ if (init instanceof Function)
112
+ return new DerivedAtomPrototype(init, options);
113
+ return new PrimitiveAtomPrototype(init, options);
114
+ };
115
+ const $$ = (init) => $((get, options) => {
116
+ let promises;
117
+ let error;
118
+ const result = init((atom) => {
119
+ try {
120
+ return get(atom);
121
+ } catch (e) {
122
+ if (!e) {
123
+ throw e;
124
+ }
125
+ if (isPromiseLike(e)) {
126
+ (promises ??= []).push(e);
127
+ } else {
128
+ error = e;
129
+ }
130
+ }
131
+ return ouroboros;
132
+ }, options);
133
+ if (error) throw error;
134
+ if (promises) throw Promise.all(promises);
135
+ return result;
136
+ });
137
+ let pendingUpdateAtoms = false;
138
+ let stack = [];
139
+ const requestActivate = (atom) => {
140
+ if (!atom.j) {
141
+ atom.j = true;
142
+ requestPropagate(atom);
143
+ }
144
+ };
145
+ const requestPropagate = (atom) => {
146
+ if (!atom.b) {
147
+ atom.b = true;
148
+ stack.push(atom);
149
+ if (!pendingUpdateAtoms) {
150
+ pendingUpdateAtoms = true;
151
+ queueMicrotask(updateAtoms);
152
+ }
153
+ }
154
+ };
155
+ const updateAtoms = () => {
156
+ pendingUpdateAtoms = false;
157
+ {
158
+ const updatedAtoms = stack;
159
+ stack = [];
160
+ for (const atom of updatedAtoms) {
161
+ atom.state.promise = void 0;
162
+ atom.state.error = atom.n;
163
+ atom.state.value = atom.f;
164
+ mark(atom);
165
+ }
166
+ }
167
+ const markedAtoms = stack;
168
+ stack = [];
169
+ for (let i = markedAtoms.length; i--; ) {
170
+ const atom = markedAtoms[i];
171
+ atom.p = false;
172
+ if (atom.j) {
173
+ atom.b = true;
174
+ execute(atom);
175
+ }
176
+ if (atom.b) {
177
+ propagate(atom);
178
+ }
179
+ }
180
+ };
181
+ const propagate = (atom) => {
182
+ atom.b = false;
183
+ if (atom.d) {
184
+ for (const child of atom.d) {
185
+ child.j = true;
186
+ }
187
+ }
188
+ if (atom.h) {
189
+ for (const watcher of atom.h) {
190
+ watcher();
191
+ }
192
+ }
193
+ if (atom.i && !atom.state.promise && !atom.state.error) {
194
+ for (const subscriber of atom.i) {
195
+ if (subscriber.a) {
196
+ subscriber.a.abort();
197
+ subscriber.a = void 0;
198
+ }
199
+ try {
200
+ subscriber.q(atom.state.value, subscriber.l);
201
+ } catch (e) {
202
+ console.error(e);
203
+ }
204
+ }
205
+ }
206
+ };
207
+ const mark = (atom) => {
208
+ if (!atom.p) {
209
+ atom.p = true;
210
+ if (atom.d) {
211
+ for (const child of atom.d) {
212
+ mark(child);
213
+ }
214
+ }
215
+ stack.push(atom);
216
+ }
217
+ };
218
+ class Wrapped {
219
+ e;
220
+ constructor(e) {
221
+ this.e = e;
222
+ }
223
+ }
224
+ const execute = (atom) => {
225
+ const counter = ++atom.g;
226
+ atom.c = true;
227
+ atom.j = false;
228
+ atom.state.promise = void 0;
229
+ if (atom.a) {
230
+ atom.a.abort();
231
+ atom.a = void 0;
232
+ }
233
+ const oldDependencies = atom.k;
234
+ if (oldDependencies) {
235
+ atom.k = /* @__PURE__ */ new Set();
236
+ }
237
+ try {
238
+ const value = atom.r(
239
+ (anotherAtom, unwrap = true) => {
240
+ if (counter !== atom.g) throw void 0;
241
+ if (atom !== anotherAtom) {
242
+ if (!anotherAtom.c) {
243
+ execute(anotherAtom);
244
+ if (anotherAtom.b) {
245
+ anotherAtom.b = false;
246
+ propagate(anotherAtom);
247
+ }
248
+ }
249
+ oldDependencies?.delete(anotherAtom);
250
+ (atom.k ??= /* @__PURE__ */ new Set()).add(anotherAtom);
251
+ (anotherAtom.d ??= /* @__PURE__ */ new Set()).add(atom);
252
+ }
253
+ if (!unwrap) return anotherAtom.state;
254
+ if (anotherAtom.state.promise)
255
+ throw new Wrapped(anotherAtom.state.promise);
256
+ if (anotherAtom.state.error)
257
+ throw new Wrapped(anotherAtom.state.error);
258
+ return anotherAtom.state.value;
259
+ },
260
+ atom.l
261
+ );
262
+ if (isPromiseLike(value)) {
263
+ atom.state.promise = value;
264
+ value.then(
265
+ (value2) => {
266
+ if (counter === atom.g) {
267
+ if (equals(value2, atom.state.value, atom.m)) {
268
+ atom.state.promise = void 0;
269
+ } else {
270
+ atom.f = value2;
271
+ atom.n = void 0;
272
+ requestPropagate(atom);
273
+ }
274
+ }
275
+ },
276
+ (error) => {
277
+ if (counter === atom.g) {
278
+ if (error instanceof Promise) {
279
+ atom.state.promise = void 0;
280
+ } else {
281
+ atom.n = error;
282
+ requestPropagate(atom);
283
+ }
284
+ }
285
+ }
286
+ );
287
+ } else {
288
+ ++atom.g;
289
+ atom.state.error = void 0;
290
+ if (equals(value, atom.state.value, atom.m)) {
291
+ atom.b = false;
292
+ } else {
293
+ atom.state.value = atom.f = value;
294
+ }
295
+ }
296
+ } catch (e) {
297
+ ++atom.g;
298
+ if (!e) {
299
+ atom.b = false;
300
+ } else {
301
+ if (e instanceof Wrapped) {
302
+ e = e.e;
303
+ } else {
304
+ console.error(e);
305
+ }
306
+ if (isPromiseLike(e)) {
307
+ atom.state.promise = e;
308
+ } else {
309
+ atom.state.error = e;
310
+ }
311
+ }
312
+ }
313
+ if (oldDependencies) {
314
+ for (const dep of oldDependencies) {
315
+ dep.d.delete(atom);
316
+ disableAtom(dep);
317
+ }
318
+ }
319
+ };
320
+ let disabling = false;
321
+ const disableAtom = (atom) => {
322
+ if (!atom.o && !atom.s && !atom.d?.size && !atom.h?.size && !atom.i?.size) {
323
+ if (!disabling) {
324
+ setTimeout(() => {
325
+ disabling = true;
326
+ disableAtom(atom);
327
+ disabling = false;
328
+ }, 0);
329
+ return;
330
+ }
331
+ atom.state.promise = inactive;
332
+ atom.f = atom.n = atom.state.error = atom.state.value = void 0;
333
+ atom.b = atom.j = atom.c = false;
334
+ if (atom.a) {
335
+ atom.a.abort();
336
+ atom.a = void 0;
337
+ }
338
+ if (atom.k) {
339
+ for (const dep of atom.k) {
340
+ dep.d.delete(atom);
341
+ disableAtom(dep);
342
+ }
343
+ atom.k.clear();
344
+ }
345
+ }
346
+ };
347
+ const equals = (value, prevValue, equalsFn) => Object.is(value, prevValue) || equalsFn !== void 0 && prevValue !== void 0 && equalsFn(value, prevValue);
348
+ const isPromiseLike = (x) => typeof x?.then === "function";
349
+ const createThenableSignal = () => {
350
+ const ctrl = new AbortController();
351
+ const signal = ctrl.signal;
352
+ const promise = new Promise((resolve) => {
353
+ signal.then = (f) => promise.then(f);
354
+ signal.addEventListener("abort", resolve, {
355
+ once: true,
356
+ passive: true
357
+ });
358
+ });
359
+ return {
360
+ abort: () => ctrl.abort(),
361
+ signal
362
+ };
363
+ };
364
+ export {
365
+ $,
366
+ $$,
367
+ inactive
368
+ };
@@ -0,0 +1,6 @@
1
+ import type { Atom, DerivedAtom, PrimitiveAtom } from '.';
2
+ export * from '.';
3
+ export declare const useAtom: <Value>(atom: PrimitiveAtom<Value>) => readonly [Value, (value: import(".").AtomUpdater<Value>) => void];
4
+ export declare const useAtomValue: <Value>(atom: Atom<Value>) => Value;
5
+ export declare const useAtomState: <Value>(atom: DerivedAtom<Value>) => import(".").AtomState<Value>;
6
+ export declare const useStateAtom: <Value>(atom: PrimitiveAtom<Value>) => readonly [Value, (newState: Value) => void];
package/dist/react.js ADDED
@@ -0,0 +1,25 @@
1
+ import { useState, useSyncExternalStore } from "react";
2
+ export * from ".";
3
+ const useAtom = (atom) => [useSyncExternalStore(atom.watch, atom.get), atom.set];
4
+ const useAtomValue = (atom) => useSyncExternalStore(atom.watch, atom.get);
5
+ const useAtomState = (atom) => useSyncExternalStore(atom.watch, () => {
6
+ try {
7
+ atom.get();
8
+ } catch (_) {
9
+ }
10
+ return atom.state;
11
+ });
12
+ const useStateAtom = (atom) => {
13
+ const [state, setState] = useState(() => atom.get());
14
+ const setStateWithAtom = (newState) => {
15
+ setState(newState);
16
+ atom.set(newState);
17
+ };
18
+ return [state, setStateWithAtom];
19
+ };
20
+ export {
21
+ useAtom,
22
+ useAtomState,
23
+ useAtomValue,
24
+ useStateAtom
25
+ };
package/package.json CHANGED
@@ -1,14 +1,43 @@
1
1
  {
2
2
  "name": "bansa",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "",
5
5
  "type": "module",
6
+ "main": "./index.js",
7
+ "types": "./index.d.ts",
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ ".": {
11
+ "react": {
12
+ "types": "./dist/react.d.ts",
13
+ "default": "./dist/react.js"
14
+ },
15
+ "default": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ }
19
+ }
20
+ },
6
21
  "devDependencies": {
7
22
  "@biomejs/biome": "2.0.0-beta.6",
8
23
  "@types/react": "^19.1.8",
9
24
  "@types/react-dom": "^19.1.6",
25
+ "esbuild": "^0.25.5",
26
+ "typescript": "^5.8.3",
10
27
  "vitest": "^3.1.4"
11
28
  },
29
+ "peerDependencies": {
30
+ "@types/react": ">=17.0.0",
31
+ "react": ">=17.0.0"
32
+ },
33
+ "peerDependenciesMeta": {
34
+ "@types/react": {
35
+ "optional": true
36
+ },
37
+ "react": {
38
+ "optional": true
39
+ }
40
+ },
12
41
  "author": "cgiosy",
13
42
  "license": "MIT",
14
43
  "repository": {
@@ -25,6 +54,11 @@
25
54
  "react"
26
55
  ],
27
56
  "scripts": {
57
+ "build": "pnpm run \"/^build:.*/\"",
58
+ "build:types": "tsc --noEmit false --emitDeclarationOnly --outDir dist",
59
+ "build:index": "esbuild src/index.ts --mangle-props=^_ --format=esm --target=es2022 --outfile=dist/index.js",
60
+ "build:index-browser": "esbuild src/index.ts --mangle-props=^_ --minify --bundle --format=esm --target=es2022 --platform=browser --outfile=dist/index.browser.js",
61
+ "build:react": "esbuild src/react.tsx --mangle-props=^_ --format=esm --target=es2022 --outfile=dist/react.js",
28
62
  "test": "vitest",
29
63
  "format": "biome format --write ./src"
30
64
  }
package/src/react.tsx CHANGED
@@ -1,6 +1,8 @@
1
1
  import { useState, useSyncExternalStore } from 'react';
2
2
  import type { Atom, DerivedAtom, PrimitiveAtom } from '.';
3
3
 
4
+ export * from '.';
5
+
4
6
  export const useAtom = <Value,>(atom: PrimitiveAtom<Value>) =>
5
7
  [useSyncExternalStore(atom.watch, atom.get), atom.set] as const;
6
8
 
package/tsconfig.json CHANGED
@@ -6,6 +6,7 @@
6
6
  "module": "ESNext",
7
7
  "skipLibCheck": true,
8
8
  "useDefineForClassFields": true,
9
+ "declaration": true,
9
10
 
10
11
  /* Bundler mode */
11
12
  "moduleResolution": "bundler",
package/biome.json DELETED
@@ -1,39 +0,0 @@
1
- {
2
- "files": {
3
- "maxSize": 16777216,
4
- "ignoreUnknown": true
5
- },
6
- "formatter": {
7
- "enabled": true,
8
- "lineWidth": 80,
9
- "indentStyle": "tab",
10
- "indentWidth": 4
11
- },
12
- "javascript": {
13
- "formatter": {
14
- "quoteStyle": "single"
15
- }
16
- },
17
- "linter": {
18
- "rules": {
19
- "correctness": {
20
- "noConstantCondition": "off",
21
- "noEmptyCharacterClassInRegex": "off"
22
- },
23
- "security": {
24
- "noDangerouslySetInnerHtml": "off"
25
- },
26
- "style": {
27
- "noParameterAssign": "off",
28
- "noNonNullAssertion": "off"
29
- },
30
- "suspicious": {
31
- "noAssignInExpressions": "off",
32
- "noCatchAssign": "off",
33
- "noConfusingLabels": "off",
34
- "noExplicitAny": "off",
35
- "noThenProperty": "off"
36
- }
37
- }
38
- }
39
- }