@vielzeug/ripple 26.10.14 → 26.10.16

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.
@@ -1 +1 @@
1
- {"version":3,"file":"_async.cjs","names":[],"sources":["../src/_async.ts"],"sourcesContent":["import { RippleDisposedError } from './errors';\nimport { REACTIVE } from './runtime';\nimport type { Disposable, EffectHandle, Readable, Signal } from './types';\n\nexport type AsyncState<T> =\n | { readonly previous?: T; readonly status: 'pending' }\n | { readonly status: 'success'; readonly value: T }\n | { readonly error: unknown; readonly previous?: T; readonly status: 'error' };\n\nexport interface Resource<T> extends Readable<AsyncState<T>>, Disposable {\n reload(): void;\n}\n\nexport type ResourceOptions = {\n name?: string;\n};\n\ntype AsyncRuntime = {\n effect(callback: () => undefined | (() => void), options?: { name?: string }): EffectHandle;\n signal<T>(initial: T, options?: { name?: string }): Signal<T>;\n};\n\n/** Resource only depends on primitive runtime methods; graph binding stays private. */\nexport const createResource =\n (runtime: AsyncRuntime) =>\n <Source, Value>(\n source: () => Source,\n loader: (source: Source, context: { readonly signal: AbortSignal }) => Promise<Value>,\n options?: ResourceOptions,\n ): Resource<Value> => {\n const state = runtime.signal<AsyncState<Value>>({ status: 'pending' }, { name: options?.name });\n const reloadEpoch = runtime.signal(0);\n let active: AbortController | undefined;\n let hasPrevious = false;\n let previousValue: Value | undefined;\n\n const run = (): void => {\n void reloadEpoch.value;\n active?.abort();\n\n let input: Source;\n\n try {\n input = source();\n } catch (error) {\n state.value = hasPrevious\n ? { error, previous: previousValue as Value, status: 'error' }\n : { error, status: 'error' };\n\n return;\n }\n\n const next = new AbortController();\n\n active = next;\n state.value = hasPrevious ? { previous: previousValue as Value, status: 'pending' } : { status: 'pending' };\n\n let request: Promise<Value>;\n\n try {\n request = Promise.resolve(loader(input, { signal: next.signal }));\n } catch (error) {\n request = Promise.reject(error);\n }\n\n void request.then(\n (value) => {\n if (!stop.disposed && !next.signal.aborted) {\n hasPrevious = true;\n previousValue = value;\n state.value = { status: 'success', value };\n }\n },\n (error: unknown) => {\n if (!stop.disposed && !next.signal.aborted) {\n state.value = hasPrevious\n ? { error, previous: previousValue as Value, status: 'error' }\n : { error, status: 'error' };\n }\n },\n );\n };\n\n const stop = runtime.effect(\n () => {\n run();\n\n return () => active?.abort();\n },\n { name: options?.name },\n );\n\n const assertActive = (): void => {\n if (stop.disposed) throw new RippleDisposedError('Cannot use a disposed resource.');\n };\n const resource: Resource<Value> = {\n get disposalSignal() {\n return stop.disposalSignal;\n },\n dispose: () => stop.dispose(),\n get disposed() {\n return stop.disposed;\n },\n get name() {\n return state.name;\n },\n peek: () => state.peek(),\n reload: () => {\n assertActive();\n reloadEpoch.value = reloadEpoch.peek() + 1;\n },\n subscribe: (listener) => {\n assertActive();\n return state.subscribe(listener);\n },\n [Symbol.dispose]() {\n this.dispose();\n },\n get value() {\n return state.value;\n },\n };\n\n Object.defineProperty(resource, REACTIVE, { value: true });\n\n return resource;\n };\n"],"mappings":"2DAuBA,IAAa,eACV,IAEC,EACA,EACA,IACoB,CACpB,IAAM,EAAQ,EAAQ,OAA0B,CAAE,OAAQ,SAAU,EAAG,CAAE,KAAM,GAAS,IAAK,CAAC,EACxF,EAAc,EAAQ,OAAO,CAAC,EAChC,EACA,EAAc,GACd,EAEE,QAAkB,CACtB,EAAiB,MACjB,GAAQ,MAAM,EAEd,IAAI,EAEJ,GAAI,CACF,EAAQ,EAAO,CACjB,OAAS,EAAO,CACd,EAAM,MAAQ,EACV,CAAE,QAAO,SAAU,EAAwB,OAAQ,OAAQ,EAC3D,CAAE,QAAO,OAAQ,OAAQ,EAE7B,MACF,CAEA,IAAM,EAAO,IAAI,gBAEjB,EAAS,EACT,EAAM,MAAQ,EAAc,CAAE,SAAU,EAAwB,OAAQ,SAAU,EAAI,CAAE,OAAQ,SAAU,EAE1G,IAAI,EAEJ,GAAI,CACF,EAAU,QAAQ,QAAQ,EAAO,EAAO,CAAE,OAAQ,EAAK,MAAO,CAAC,CAAC,CAClE,OAAS,EAAO,CACd,EAAU,QAAQ,OAAO,CAAK,CAChC,CAEA,EAAa,KACV,GAAU,CACL,CAAC,EAAK,UAAY,CAAC,EAAK,OAAO,UACjC,EAAc,GACd,EAAgB,EAChB,EAAM,MAAQ,CAAE,OAAQ,UAAW,OAAM,EAE7C,EACC,GAAmB,CACd,CAAC,EAAK,UAAY,CAAC,EAAK,OAAO,UACjC,EAAM,MAAQ,EACV,CAAE,QAAO,SAAU,EAAwB,OAAQ,OAAQ,EAC3D,CAAE,QAAO,OAAQ,OAAQ,EAEjC,CACF,CACF,EAEM,EAAO,EAAQ,YAEjB,IAAI,MAES,GAAQ,MAAM,GAE7B,CAAE,KAAM,GAAS,IAAK,CACxB,EAEM,iBAA2B,CAC/B,GAAI,EAAK,SAAU,MAAM,IAAI,EAAA,oBAAoB,iCAAiC,CACpF,EACM,EAA4B,CAChC,IAAI,gBAAiB,CACnB,OAAO,EAAK,cACd,EACA,YAAe,EAAK,QAAQ,EAC5B,IAAI,UAAW,CACb,OAAO,EAAK,QACd,EACA,IAAI,MAAO,CACT,OAAO,EAAM,IACf,EACA,SAAY,EAAM,KAAK,EACvB,WAAc,CACZ,aAAa,EACb,EAAY,MAAQ,EAAY,KAAK,EAAI,CAC3C,EACA,UAAY,IACV,aAAa,EACN,EAAM,UAAU,CAAQ,GAEjC,CAAC,OAAO,UAAW,CACjB,KAAK,QAAQ,CACf,EACA,IAAI,OAAQ,CACV,OAAO,EAAM,KACf,CACF,EAIA,OAFA,OAAO,eAAe,EAAU,EAAA,SAAU,CAAE,MAAO,EAAK,CAAC,EAElD,CACT"}
1
+ {"version":3,"file":"_async.cjs","names":["RippleDisposedError","REACTIVE","require_errors","require_runtime","state","runtime","options","reloadEpoch","active","hasPrevious","previousValue","input","source","error","next","request","loader","stop","value","resource","listener"],"sources":["../src/_async.ts"],"sourcesContent":["import { RippleDisposedError } from './errors';\nimport { REACTIVE } from './runtime';\nimport type { Disposable, EffectHandle, Readable, Signal } from './types';\n\nexport type AsyncState<T> =\n | { readonly previous?: T; readonly status: 'pending' }\n | { readonly status: 'success'; readonly value: T }\n | { readonly error: unknown; readonly previous?: T; readonly status: 'error' };\n\nexport interface Resource<T> extends Readable<AsyncState<T>>, Disposable {\n reload(): void;\n}\n\nexport type ResourceOptions = {\n name?: string;\n};\n\ntype AsyncRuntime = {\n effect(callback: () => undefined | (() => void), options?: { name?: string }): EffectHandle;\n signal<T>(initial: T, options?: { name?: string }): Signal<T>;\n};\n\n/** Resource only depends on primitive runtime methods; graph binding stays private. */\nexport const createResource =\n (runtime: AsyncRuntime) =>\n <Source, Value>(\n source: () => Source,\n loader: (source: Source, context: { readonly signal: AbortSignal }) => Promise<Value>,\n options?: ResourceOptions,\n ): Resource<Value> => {\n const state = runtime.signal<AsyncState<Value>>({ status: 'pending' }, { name: options?.name });\n const reloadEpoch = runtime.signal(0);\n let active: AbortController | undefined;\n let hasPrevious = false;\n let previousValue: Value | undefined;\n\n const run = (): void => {\n void reloadEpoch.value;\n active?.abort();\n\n let input: Source;\n\n try {\n input = source();\n } catch (error) {\n state.value = hasPrevious\n ? { error, previous: previousValue as Value, status: 'error' }\n : { error, status: 'error' };\n\n return;\n }\n\n const next = new AbortController();\n\n active = next;\n state.value = hasPrevious ? { previous: previousValue as Value, status: 'pending' } : { status: 'pending' };\n\n let request: Promise<Value>;\n\n try {\n request = Promise.resolve(loader(input, { signal: next.signal }));\n } catch (error) {\n request = Promise.reject(error);\n }\n\n void request.then(\n (value) => {\n if (!stop.disposed && !next.signal.aborted) {\n hasPrevious = true;\n previousValue = value;\n state.value = { status: 'success', value };\n }\n },\n (error: unknown) => {\n if (!stop.disposed && !next.signal.aborted) {\n state.value = hasPrevious\n ? { error, previous: previousValue as Value, status: 'error' }\n : { error, status: 'error' };\n }\n },\n );\n };\n\n const stop = runtime.effect(\n () => {\n run();\n\n return () => active?.abort();\n },\n { name: options?.name },\n );\n\n const assertActive = (): void => {\n if (stop.disposed) throw new RippleDisposedError('Cannot use a disposed resource.');\n };\n const resource: Resource<Value> = {\n get disposalSignal() {\n return stop.disposalSignal;\n },\n dispose: () => stop.dispose(),\n get disposed() {\n return stop.disposed;\n },\n get name() {\n return state.name;\n },\n peek: () => state.peek(),\n reload: () => {\n assertActive();\n reloadEpoch.value = reloadEpoch.peek() + 1;\n },\n subscribe: (listener) => {\n assertActive();\n return state.subscribe(listener);\n },\n [Symbol.dispose]() {\n this.dispose();\n },\n get value() {\n return state.value;\n },\n };\n\n Object.defineProperty(resource, REACTIVE, { value: true });\n\n return resource;\n };\n"],"mappings":"A,2DAuBA,IAAa,eACV,IAEC,EACA,EACA,IACoB,CACpB,IAAMI,EAAQC,EAAQ,OAA0B,CAAE,OAAQ,SAAU,EAAG,CAAE,KAAMC,GAAS,IAAK,CAAC,EACxFC,EAAcF,EAAQ,OAAO,CAAC,EAChCG,EACAC,EAAc,GACdC,EAEE,QAAkB,CACtBH,EAAiB,MACjBC,GAAQ,MAAM,EAEd,IAAIG,EAEJ,GAAI,CACF,EAAQC,EAAO,CACjB,OAASC,EAAO,CACd,EAAM,MAAQJ,EACV,CAAE,QAAO,SAAUC,EAAwB,OAAQ,OAAQ,EAC3D,CAAE,QAAO,OAAQ,OAAQ,EAE7B,MACF,CAEA,IAAMI,EAAO,IAAI,gBAEjB,EAASA,EACT,EAAM,MAAQL,EAAc,CAAE,SAAUC,EAAwB,OAAQ,SAAU,EAAI,CAAE,OAAQ,SAAU,EAE1G,IAAIK,EAEJ,GAAI,CACF,EAAU,QAAQ,QAAQC,EAAOL,EAAO,CAAE,OAAQG,EAAK,MAAO,CAAC,CAAC,CAClE,OAASD,EAAO,CACd,EAAU,QAAQ,OAAOA,CAAK,CAChC,CAEAE,EAAa,KACV,GAAU,CACL,CAACE,EAAK,UAAY,CAACH,EAAK,OAAO,UACjC,EAAc,GACd,EAAgBI,EAChB,EAAM,MAAQ,CAAE,OAAQ,UAAW,OAAM,EAE7C,EACC,GAAmB,CACd,CAACD,EAAK,UAAY,CAACH,EAAK,OAAO,UACjC,EAAM,MAAQL,EACV,CAAE,QAAO,SAAUC,EAAwB,OAAQ,OAAQ,EAC3D,CAAE,QAAO,OAAQ,OAAQ,EAEjC,CACF,CACF,EAEMO,EAAOZ,EAAQ,YAEjB,IAAI,MAESG,GAAQ,MAAM,GAE7B,CAAE,KAAMF,GAAS,IAAK,CACxB,EAEM,iBAA2B,CAC/B,GAAIW,EAAK,SAAU,MAAM,IAAIjB,EAAAA,oBAAoB,iCAAiC,CACpF,EACMmB,EAA4B,CAChC,IAAI,gBAAiB,CACnB,OAAOF,EAAK,cACd,EACA,YAAeA,EAAK,QAAQ,EAC5B,IAAI,UAAW,CACb,OAAOA,EAAK,QACd,EACA,IAAI,MAAO,CACT,OAAOb,EAAM,IACf,EACA,SAAYA,EAAM,KAAK,EACvB,WAAc,CACZ,aAAa,EACb,EAAY,MAAQG,EAAY,KAAK,EAAI,CAC3C,EACA,UAAY,IACV,aAAa,EACNH,EAAM,UAAUgB,CAAQ,GAEjC,CAAC,OAAO,UAAW,CACjB,KAAK,QAAQ,CACf,EACA,IAAI,OAAQ,CACV,OAAOhB,EAAM,KACf,CACF,EAIA,OAFA,OAAO,eAAee,EAAUlB,EAAAA,SAAU,CAAE,MAAO,EAAK,CAAC,EAElDkB,CACT,E"}
package/dist/_async.js CHANGED
@@ -1,2 +1,77 @@
1
- import{RippleDisposedError as e}from"./errors.js";import{REACTIVE as t}from"./runtime.js";var createResource=n=>(r,i,a)=>{let o=n.signal({status:`pending`},{name:a?.name}),s=n.signal(0),c,l=!1,u,run=()=>{s.value,c?.abort();let e;try{e=r()}catch(e){o.value=l?{error:e,previous:u,status:`error`}:{error:e,status:`error`};return}let t=new AbortController;c=t,o.value=l?{previous:u,status:`pending`}:{status:`pending`};let n;try{n=Promise.resolve(i(e,{signal:t.signal}))}catch(e){n=Promise.reject(e)}n.then(e=>{!d.disposed&&!t.signal.aborted&&(l=!0,u=e,o.value={status:`success`,value:e})},e=>{!d.disposed&&!t.signal.aborted&&(o.value=l?{error:e,previous:u,status:`error`}:{error:e,status:`error`})})},d=n.effect(()=>(run(),()=>c?.abort()),{name:a?.name}),assertActive=()=>{if(d.disposed)throw new e(`Cannot use a disposed resource.`)},f={get disposalSignal(){return d.disposalSignal},dispose:()=>d.dispose(),get disposed(){return d.disposed},get name(){return o.name},peek:()=>o.peek(),reload:()=>{assertActive(),s.value=s.peek()+1},subscribe:e=>(assertActive(),o.subscribe(e)),[Symbol.dispose](){this.dispose()},get value(){return o.value}};return Object.defineProperty(f,t,{value:!0}),f};export{createResource};
1
+ import { RippleDisposedError as e } from "./errors.js";
2
+ import { REACTIVE as t } from "./runtime.js";
3
+ //#region src/_async.ts
4
+ var createResource = (n) => (r, i, a) => {
5
+ let o = n.signal({ status: "pending" }, { name: a?.name }), s = n.signal(0), c, l = !1, u, run = () => {
6
+ s.value, c?.abort();
7
+ let e;
8
+ try {
9
+ e = r();
10
+ } catch (e) {
11
+ o.value = l ? {
12
+ error: e,
13
+ previous: u,
14
+ status: "error"
15
+ } : {
16
+ error: e,
17
+ status: "error"
18
+ };
19
+ return;
20
+ }
21
+ let t = new AbortController();
22
+ c = t, o.value = l ? {
23
+ previous: u,
24
+ status: "pending"
25
+ } : { status: "pending" };
26
+ let n;
27
+ try {
28
+ n = Promise.resolve(i(e, { signal: t.signal }));
29
+ } catch (e) {
30
+ n = Promise.reject(e);
31
+ }
32
+ n.then((e) => {
33
+ !d.disposed && !t.signal.aborted && (l = !0, u = e, o.value = {
34
+ status: "success",
35
+ value: e
36
+ });
37
+ }, (e) => {
38
+ !d.disposed && !t.signal.aborted && (o.value = l ? {
39
+ error: e,
40
+ previous: u,
41
+ status: "error"
42
+ } : {
43
+ error: e,
44
+ status: "error"
45
+ });
46
+ });
47
+ }, d = n.effect(() => (run(), () => c?.abort()), { name: a?.name }), assertActive = () => {
48
+ if (d.disposed) throw new e("Cannot use a disposed resource.");
49
+ }, f = {
50
+ get disposalSignal() {
51
+ return d.disposalSignal;
52
+ },
53
+ dispose: () => d.dispose(),
54
+ get disposed() {
55
+ return d.disposed;
56
+ },
57
+ get name() {
58
+ return o.name;
59
+ },
60
+ peek: () => o.peek(),
61
+ reload: () => {
62
+ assertActive(), s.value = s.peek() + 1;
63
+ },
64
+ subscribe: (e) => (assertActive(), o.subscribe(e)),
65
+ [Symbol.dispose]() {
66
+ this.dispose();
67
+ },
68
+ get value() {
69
+ return o.value;
70
+ }
71
+ };
72
+ return Object.defineProperty(f, t, { value: !0 }), f;
73
+ };
74
+ //#endregion
75
+ export { createResource };
76
+
2
77
  //# sourceMappingURL=_async.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_async.js","names":[],"sources":["../src/_async.ts"],"sourcesContent":["import { RippleDisposedError } from './errors';\nimport { REACTIVE } from './runtime';\nimport type { Disposable, EffectHandle, Readable, Signal } from './types';\n\nexport type AsyncState<T> =\n | { readonly previous?: T; readonly status: 'pending' }\n | { readonly status: 'success'; readonly value: T }\n | { readonly error: unknown; readonly previous?: T; readonly status: 'error' };\n\nexport interface Resource<T> extends Readable<AsyncState<T>>, Disposable {\n reload(): void;\n}\n\nexport type ResourceOptions = {\n name?: string;\n};\n\ntype AsyncRuntime = {\n effect(callback: () => undefined | (() => void), options?: { name?: string }): EffectHandle;\n signal<T>(initial: T, options?: { name?: string }): Signal<T>;\n};\n\n/** Resource only depends on primitive runtime methods; graph binding stays private. */\nexport const createResource =\n (runtime: AsyncRuntime) =>\n <Source, Value>(\n source: () => Source,\n loader: (source: Source, context: { readonly signal: AbortSignal }) => Promise<Value>,\n options?: ResourceOptions,\n ): Resource<Value> => {\n const state = runtime.signal<AsyncState<Value>>({ status: 'pending' }, { name: options?.name });\n const reloadEpoch = runtime.signal(0);\n let active: AbortController | undefined;\n let hasPrevious = false;\n let previousValue: Value | undefined;\n\n const run = (): void => {\n void reloadEpoch.value;\n active?.abort();\n\n let input: Source;\n\n try {\n input = source();\n } catch (error) {\n state.value = hasPrevious\n ? { error, previous: previousValue as Value, status: 'error' }\n : { error, status: 'error' };\n\n return;\n }\n\n const next = new AbortController();\n\n active = next;\n state.value = hasPrevious ? { previous: previousValue as Value, status: 'pending' } : { status: 'pending' };\n\n let request: Promise<Value>;\n\n try {\n request = Promise.resolve(loader(input, { signal: next.signal }));\n } catch (error) {\n request = Promise.reject(error);\n }\n\n void request.then(\n (value) => {\n if (!stop.disposed && !next.signal.aborted) {\n hasPrevious = true;\n previousValue = value;\n state.value = { status: 'success', value };\n }\n },\n (error: unknown) => {\n if (!stop.disposed && !next.signal.aborted) {\n state.value = hasPrevious\n ? { error, previous: previousValue as Value, status: 'error' }\n : { error, status: 'error' };\n }\n },\n );\n };\n\n const stop = runtime.effect(\n () => {\n run();\n\n return () => active?.abort();\n },\n { name: options?.name },\n );\n\n const assertActive = (): void => {\n if (stop.disposed) throw new RippleDisposedError('Cannot use a disposed resource.');\n };\n const resource: Resource<Value> = {\n get disposalSignal() {\n return stop.disposalSignal;\n },\n dispose: () => stop.dispose(),\n get disposed() {\n return stop.disposed;\n },\n get name() {\n return state.name;\n },\n peek: () => state.peek(),\n reload: () => {\n assertActive();\n reloadEpoch.value = reloadEpoch.peek() + 1;\n },\n subscribe: (listener) => {\n assertActive();\n return state.subscribe(listener);\n },\n [Symbol.dispose]() {\n this.dispose();\n },\n get value() {\n return state.value;\n },\n };\n\n Object.defineProperty(resource, REACTIVE, { value: true });\n\n return resource;\n };\n"],"mappings":"0FAuBA,IAAa,eACV,IAEC,EACA,EACA,IACoB,CACpB,IAAM,EAAQ,EAAQ,OAA0B,CAAE,OAAQ,SAAU,EAAG,CAAE,KAAM,GAAS,IAAK,CAAC,EACxF,EAAc,EAAQ,OAAO,CAAC,EAChC,EACA,EAAc,GACd,EAEE,QAAkB,CACtB,EAAiB,MACjB,GAAQ,MAAM,EAEd,IAAI,EAEJ,GAAI,CACF,EAAQ,EAAO,CACjB,OAAS,EAAO,CACd,EAAM,MAAQ,EACV,CAAE,QAAO,SAAU,EAAwB,OAAQ,OAAQ,EAC3D,CAAE,QAAO,OAAQ,OAAQ,EAE7B,MACF,CAEA,IAAM,EAAO,IAAI,gBAEjB,EAAS,EACT,EAAM,MAAQ,EAAc,CAAE,SAAU,EAAwB,OAAQ,SAAU,EAAI,CAAE,OAAQ,SAAU,EAE1G,IAAI,EAEJ,GAAI,CACF,EAAU,QAAQ,QAAQ,EAAO,EAAO,CAAE,OAAQ,EAAK,MAAO,CAAC,CAAC,CAClE,OAAS,EAAO,CACd,EAAU,QAAQ,OAAO,CAAK,CAChC,CAEA,EAAa,KACV,GAAU,CACL,CAAC,EAAK,UAAY,CAAC,EAAK,OAAO,UACjC,EAAc,GACd,EAAgB,EAChB,EAAM,MAAQ,CAAE,OAAQ,UAAW,OAAM,EAE7C,EACC,GAAmB,CACd,CAAC,EAAK,UAAY,CAAC,EAAK,OAAO,UACjC,EAAM,MAAQ,EACV,CAAE,QAAO,SAAU,EAAwB,OAAQ,OAAQ,EAC3D,CAAE,QAAO,OAAQ,OAAQ,EAEjC,CACF,CACF,EAEM,EAAO,EAAQ,YAEjB,IAAI,MAES,GAAQ,MAAM,GAE7B,CAAE,KAAM,GAAS,IAAK,CACxB,EAEM,iBAA2B,CAC/B,GAAI,EAAK,SAAU,MAAM,IAAI,EAAoB,iCAAiC,CACpF,EACM,EAA4B,CAChC,IAAI,gBAAiB,CACnB,OAAO,EAAK,cACd,EACA,YAAe,EAAK,QAAQ,EAC5B,IAAI,UAAW,CACb,OAAO,EAAK,QACd,EACA,IAAI,MAAO,CACT,OAAO,EAAM,IACf,EACA,SAAY,EAAM,KAAK,EACvB,WAAc,CACZ,aAAa,EACb,EAAY,MAAQ,EAAY,KAAK,EAAI,CAC3C,EACA,UAAY,IACV,aAAa,EACN,EAAM,UAAU,CAAQ,GAEjC,CAAC,OAAO,UAAW,CACjB,KAAK,QAAQ,CACf,EACA,IAAI,OAAQ,CACV,OAAO,EAAM,KACf,CACF,EAIA,OAFA,OAAO,eAAe,EAAU,EAAU,CAAE,MAAO,EAAK,CAAC,EAElD,CACT"}
1
+ {"version":3,"file":"_async.js","names":["state","runtime","options","reloadEpoch","active","hasPrevious","previousValue","input","source","error","next","request","loader","stop","value","RippleDisposedError","resource","listener","REACTIVE"],"sources":["../src/_async.ts"],"sourcesContent":["import { RippleDisposedError } from './errors';\nimport { REACTIVE } from './runtime';\nimport type { Disposable, EffectHandle, Readable, Signal } from './types';\n\nexport type AsyncState<T> =\n | { readonly previous?: T; readonly status: 'pending' }\n | { readonly status: 'success'; readonly value: T }\n | { readonly error: unknown; readonly previous?: T; readonly status: 'error' };\n\nexport interface Resource<T> extends Readable<AsyncState<T>>, Disposable {\n reload(): void;\n}\n\nexport type ResourceOptions = {\n name?: string;\n};\n\ntype AsyncRuntime = {\n effect(callback: () => undefined | (() => void), options?: { name?: string }): EffectHandle;\n signal<T>(initial: T, options?: { name?: string }): Signal<T>;\n};\n\n/** Resource only depends on primitive runtime methods; graph binding stays private. */\nexport const createResource =\n (runtime: AsyncRuntime) =>\n <Source, Value>(\n source: () => Source,\n loader: (source: Source, context: { readonly signal: AbortSignal }) => Promise<Value>,\n options?: ResourceOptions,\n ): Resource<Value> => {\n const state = runtime.signal<AsyncState<Value>>({ status: 'pending' }, { name: options?.name });\n const reloadEpoch = runtime.signal(0);\n let active: AbortController | undefined;\n let hasPrevious = false;\n let previousValue: Value | undefined;\n\n const run = (): void => {\n void reloadEpoch.value;\n active?.abort();\n\n let input: Source;\n\n try {\n input = source();\n } catch (error) {\n state.value = hasPrevious\n ? { error, previous: previousValue as Value, status: 'error' }\n : { error, status: 'error' };\n\n return;\n }\n\n const next = new AbortController();\n\n active = next;\n state.value = hasPrevious ? { previous: previousValue as Value, status: 'pending' } : { status: 'pending' };\n\n let request: Promise<Value>;\n\n try {\n request = Promise.resolve(loader(input, { signal: next.signal }));\n } catch (error) {\n request = Promise.reject(error);\n }\n\n void request.then(\n (value) => {\n if (!stop.disposed && !next.signal.aborted) {\n hasPrevious = true;\n previousValue = value;\n state.value = { status: 'success', value };\n }\n },\n (error: unknown) => {\n if (!stop.disposed && !next.signal.aborted) {\n state.value = hasPrevious\n ? { error, previous: previousValue as Value, status: 'error' }\n : { error, status: 'error' };\n }\n },\n );\n };\n\n const stop = runtime.effect(\n () => {\n run();\n\n return () => active?.abort();\n },\n { name: options?.name },\n );\n\n const assertActive = (): void => {\n if (stop.disposed) throw new RippleDisposedError('Cannot use a disposed resource.');\n };\n const resource: Resource<Value> = {\n get disposalSignal() {\n return stop.disposalSignal;\n },\n dispose: () => stop.dispose(),\n get disposed() {\n return stop.disposed;\n },\n get name() {\n return state.name;\n },\n peek: () => state.peek(),\n reload: () => {\n assertActive();\n reloadEpoch.value = reloadEpoch.peek() + 1;\n },\n subscribe: (listener) => {\n assertActive();\n return state.subscribe(listener);\n },\n [Symbol.dispose]() {\n this.dispose();\n },\n get value() {\n return state.value;\n },\n };\n\n Object.defineProperty(resource, REACTIVE, { value: true });\n\n return resource;\n };\n"],"mappings":";;;AAuBA,IAAa,kBACV,OAEC,GACA,GACA,MACoB;CACpB,IAAMA,IAAQC,EAAQ,OAA0B,EAAE,QAAQ,UAAU,GAAG,EAAE,MAAMC,GAAS,KAAK,CAAC,GACxFC,IAAcF,EAAQ,OAAO,CAAC,GAChCG,GACAC,IAAc,IACdC,GAEE,YAAkB;EAEtB,AADAH,EAAiB,OACjBC,GAAQ,MAAM;EAEd,IAAIG;EAEJ,IAAI;GACF,IAAQC,EAAO;EACjB,SAASC,GAAO;GACd,EAAM,QAAQJ,IACV;IAAE;IAAO,UAAUC;IAAwB,QAAQ;GAAQ,IAC3D;IAAE;IAAO,QAAQ;GAAQ;GAE7B;EACF;EAEA,IAAMI,IAAO,IAAI,gBAAgB;EAGjC,AADA,IAASA,GACT,EAAM,QAAQL,IAAc;GAAE,UAAUC;GAAwB,QAAQ;EAAU,IAAI,EAAE,QAAQ,UAAU;EAE1G,IAAIK;EAEJ,IAAI;GACF,IAAU,QAAQ,QAAQC,EAAOL,GAAO,EAAE,QAAQG,EAAK,OAAO,CAAC,CAAC;EAClE,SAASD,GAAO;GACd,IAAU,QAAQ,OAAOA,CAAK;EAChC;EAEA,EAAa,MACV,MAAU;GACT,AAAI,CAACI,EAAK,YAAY,CAACH,EAAK,OAAO,YACjC,IAAc,IACd,IAAgBI,GAChB,EAAM,QAAQ;IAAE,QAAQ;IAAW;GAAM;EAE7C,IACC,MAAmB;GAClB,AAAI,CAACD,EAAK,YAAY,CAACH,EAAK,OAAO,YACjC,EAAM,QAAQL,IACV;IAAE;IAAO,UAAUC;IAAwB,QAAQ;GAAQ,IAC3D;IAAE;IAAO,QAAQ;GAAQ;EAEjC,CACF;CACF,GAEMO,IAAOZ,EAAQ,cAEjB,IAAI,SAESG,GAAQ,MAAM,IAE7B,EAAE,MAAMF,GAAS,KAAK,CACxB,GAEM,qBAA2B;EAC/B,IAAIW,EAAK,UAAU,MAAM,IAAIE,EAAoB,iCAAiC;CACpF,GACMC,IAA4B;EAChC,IAAI,iBAAiB;GACnB,OAAOH,EAAK;EACd;EACA,eAAeA,EAAK,QAAQ;EAC5B,IAAI,WAAW;GACb,OAAOA,EAAK;EACd;EACA,IAAI,OAAO;GACT,OAAOb,EAAM;EACf;EACA,YAAYA,EAAM,KAAK;EACvB,cAAc;GAEZ,AADA,aAAa,GACb,EAAY,QAAQG,EAAY,KAAK,IAAI;EAC3C;EACA,YAAY,OACV,aAAa,GACNH,EAAM,UAAUiB,CAAQ;EAEjC,CAAC,OAAO,WAAW;GACjB,KAAK,QAAQ;EACf;EACA,IAAI,QAAQ;GACV,OAAOjB,EAAM;EACf;CACF;CAIA,OAFA,OAAO,eAAegB,GAAUE,GAAU,EAAE,OAAO,GAAK,CAAC,GAElDF;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"_default.cjs","names":[],"sources":["../src/_default.ts"],"sourcesContent":["import { createResource, type Resource, type ResourceOptions } from './_async';\nimport { type BridgedReadable, createFromSubscribable, type FromSubscribableOptions } from './_subscribable';\nimport { createWatch, type WatchOptions } from './_watch';\nimport { ReactiveRuntime } from './runtime';\nimport type {\n Cleanup,\n ComputedOptions,\n Disposable,\n EffectHandle,\n EffectOptions,\n Readable,\n RippleOptions,\n Scope,\n Signal,\n SignalOptions,\n Subscribable,\n} from './types';\n\nexport interface Ripple extends Disposable {\n batch<T>(fn: () => T): T;\n computed<T>(derive: () => T, options?: ComputedOptions<T>): Readable<T>;\n createScope(name?: string): Scope;\n effect(callback: () => Cleanup | undefined, options?: EffectOptions): EffectHandle;\n fromSubscribable<T>(source: Subscribable<T>, options?: FromSubscribableOptions): BridgedReadable<T>;\n resource<Source, Value>(\n source: () => Source,\n loader: (source: Source, context: { readonly signal: AbortSignal }) => Promise<Value>,\n options?: ResourceOptions,\n ): Resource<Value>;\n signal<T>(initial: T, options?: SignalOptions<T>): Signal<T>;\n untrack<T>(fn: () => T): T;\n watch<T>(\n source: Readable<T> | (() => T),\n callback: (value: T, previous: T | undefined) => void,\n options?: WatchOptions<T>,\n ): EffectHandle;\n}\n\n/**\n * Creates one complete reactive graph with its own ownership boundary. All\n * factories on the returned object share its runtime. Use this for tests, SSR\n * requests, embedded applications, or independently disposable features.\n * `dispose()` is terminal: create a new graph for a new lifetime.\n */\nexport const createRipple = (options?: RippleOptions): Ripple => {\n const runtime = new ReactiveRuntime(options);\n const fromSubscribable = createFromSubscribable(runtime);\n const resource = createResource(runtime);\n\n return {\n batch: runtime.batch,\n computed: runtime.computed,\n createScope: runtime.createScope,\n get disposalSignal() {\n return runtime.disposalSignal;\n },\n dispose: () => runtime.dispose(),\n get disposed() {\n return runtime.disposed;\n },\n effect: runtime.effect,\n fromSubscribable,\n resource,\n signal: runtime.signal,\n untrack: runtime.untrack,\n watch: createWatch(runtime),\n [Symbol.dispose]: () => runtime.dispose(),\n };\n};\n\n/**\n * The shared default reactive graph: process-lifetime. Root helpers\n * (`signal`, `computed`, `effect`, `batch`, `createScope`, `untrack`, `watch`, `resource`, `fromSubscribable`)\n * are re-exported from the package root as bound methods on this single graph\n * instance. Use these only when the application has one graph for its entire\n * lifetime; they are never disposed. For isolated, disposable graphs (tests,\n * SSR, embedded features) use `createRipple()` instead.\n */\nexport const defaultRipple = createRipple();\n"],"mappings":"sHA4CA,IAAa,aAAgB,GAAoC,CAC/D,IAAM,EAAU,IAAI,EAAA,gBAAgB,CAAO,EACrC,EAAmB,EAAA,uBAAuB,CAAO,EACjD,EAAW,EAAA,eAAe,CAAO,EAEvC,MAAO,CACL,MAAO,EAAQ,MACf,SAAU,EAAQ,SAClB,YAAa,EAAQ,YACrB,IAAI,gBAAiB,CACnB,OAAO,EAAQ,cACjB,EACA,YAAe,EAAQ,QAAQ,EAC/B,IAAI,UAAW,CACb,OAAO,EAAQ,QACjB,EACA,OAAQ,EAAQ,OAChB,mBACA,WACA,OAAQ,EAAQ,OAChB,QAAS,EAAQ,QACjB,MAAO,EAAA,YAAY,CAAO,GACzB,OAAO,aAAgB,EAAQ,QAAQ,CAC1C,CACF,EAUa,EAAgB,aAAa"}
1
+ {"version":3,"file":"_default.cjs","names":["ReactiveRuntime","createFromSubscribable","createResource","createWatch","require_runtime","require__async","require__subscribable","require__watch","runtime","options","fromSubscribable","resource","defaultRipple"],"sources":["../src/_default.ts"],"sourcesContent":["import { createResource, type Resource, type ResourceOptions } from './_async';\nimport { type BridgedReadable, createFromSubscribable, type FromSubscribableOptions } from './_subscribable';\nimport { createWatch, type WatchOptions } from './_watch';\nimport { ReactiveRuntime } from './runtime';\nimport type {\n Cleanup,\n ComputedOptions,\n Disposable,\n EffectHandle,\n EffectOptions,\n Readable,\n RippleOptions,\n Scope,\n Signal,\n SignalOptions,\n Subscribable,\n} from './types';\n\nexport interface Ripple extends Disposable {\n batch<T>(fn: () => T): T;\n computed<T>(derive: () => T, options?: ComputedOptions<T>): Readable<T>;\n createScope(name?: string): Scope;\n effect(callback: () => Cleanup | undefined, options?: EffectOptions): EffectHandle;\n fromSubscribable<T>(source: Subscribable<T>, options?: FromSubscribableOptions): BridgedReadable<T>;\n resource<Source, Value>(\n source: () => Source,\n loader: (source: Source, context: { readonly signal: AbortSignal }) => Promise<Value>,\n options?: ResourceOptions,\n ): Resource<Value>;\n signal<T>(initial: T, options?: SignalOptions<T>): Signal<T>;\n untrack<T>(fn: () => T): T;\n watch<T>(\n source: Readable<T> | (() => T),\n callback: (value: T, previous: T | undefined) => void,\n options?: WatchOptions<T>,\n ): EffectHandle;\n}\n\n/**\n * Creates one complete reactive graph with its own ownership boundary. All\n * factories on the returned object share its runtime. Use this for tests, SSR\n * requests, embedded applications, or independently disposable features.\n * `dispose()` is terminal: create a new graph for a new lifetime.\n */\nexport const createRipple = (options?: RippleOptions): Ripple => {\n const runtime = new ReactiveRuntime(options);\n const fromSubscribable = createFromSubscribable(runtime);\n const resource = createResource(runtime);\n\n return {\n batch: runtime.batch,\n computed: runtime.computed,\n createScope: runtime.createScope,\n get disposalSignal() {\n return runtime.disposalSignal;\n },\n dispose: () => runtime.dispose(),\n get disposed() {\n return runtime.disposed;\n },\n effect: runtime.effect,\n fromSubscribable,\n resource,\n signal: runtime.signal,\n untrack: runtime.untrack,\n watch: createWatch(runtime),\n [Symbol.dispose]: () => runtime.dispose(),\n };\n};\n\n/**\n * The shared default reactive graph: process-lifetime. Root helpers\n * (`signal`, `computed`, `effect`, `batch`, `createScope`, `untrack`, `watch`, `resource`, `fromSubscribable`)\n * are re-exported from the package root as bound methods on this single graph\n * instance. Use these only when the application has one graph for its entire\n * lifetime; they are never disposed. For isolated, disposable graphs (tests,\n * SSR, embedded features) use `createRipple()` instead.\n */\nexport const defaultRipple = createRipple();\n"],"mappings":"A,sHA4CA,IAAa,aAAgB,GAAoC,CAC/D,IAAMQ,EAAU,IAAIR,EAAAA,gBAAgBS,CAAO,EACrCC,EAAmBT,EAAAA,uBAAuBO,CAAO,EACjDG,EAAWT,EAAAA,eAAeM,CAAO,EAEvC,MAAO,CACL,MAAOA,EAAQ,MACf,SAAUA,EAAQ,SAClB,YAAaA,EAAQ,YACrB,IAAI,gBAAiB,CACnB,OAAOA,EAAQ,cACjB,EACA,YAAeA,EAAQ,QAAQ,EAC/B,IAAI,UAAW,CACb,OAAOA,EAAQ,QACjB,EACA,OAAQA,EAAQ,OAChB,mBACA,WACA,OAAQA,EAAQ,OAChB,QAASA,EAAQ,QACjB,MAAOL,EAAAA,YAAYK,CAAO,GACzB,OAAO,aAAgBA,EAAQ,QAAQ,CAC1C,CACF,EAUaI,EAAgB,aAAa,E"}
package/dist/_default.js CHANGED
@@ -1,2 +1,31 @@
1
- import{ReactiveRuntime as e}from"./runtime.js";import{createResource as t}from"./_async.js";import{createFromSubscribable as n}from"./_subscribable.js";import{createWatch as r}from"./_watch.js";var createRipple=i=>{let a=new e(i),o=n(a),s=t(a);return{batch:a.batch,computed:a.computed,createScope:a.createScope,get disposalSignal(){return a.disposalSignal},dispose:()=>a.dispose(),get disposed(){return a.disposed},effect:a.effect,fromSubscribable:o,resource:s,signal:a.signal,untrack:a.untrack,watch:r(a),[Symbol.dispose]:()=>a.dispose()}},i=createRipple();export{createRipple,i as defaultRipple};
1
+ import { ReactiveRuntime as e } from "./runtime.js";
2
+ import { createResource as t } from "./_async.js";
3
+ import { createFromSubscribable as n } from "./_subscribable.js";
4
+ import { createWatch as r } from "./_watch.js";
5
+ //#region src/_default.ts
6
+ var createRipple = (i) => {
7
+ let a = new e(i), o = n(a), s = t(a);
8
+ return {
9
+ batch: a.batch,
10
+ computed: a.computed,
11
+ createScope: a.createScope,
12
+ get disposalSignal() {
13
+ return a.disposalSignal;
14
+ },
15
+ dispose: () => a.dispose(),
16
+ get disposed() {
17
+ return a.disposed;
18
+ },
19
+ effect: a.effect,
20
+ fromSubscribable: o,
21
+ resource: s,
22
+ signal: a.signal,
23
+ untrack: a.untrack,
24
+ watch: r(a),
25
+ [Symbol.dispose]: () => a.dispose()
26
+ };
27
+ }, i = createRipple();
28
+ //#endregion
29
+ export { createRipple, i as defaultRipple };
30
+
2
31
  //# sourceMappingURL=_default.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_default.js","names":[],"sources":["../src/_default.ts"],"sourcesContent":["import { createResource, type Resource, type ResourceOptions } from './_async';\nimport { type BridgedReadable, createFromSubscribable, type FromSubscribableOptions } from './_subscribable';\nimport { createWatch, type WatchOptions } from './_watch';\nimport { ReactiveRuntime } from './runtime';\nimport type {\n Cleanup,\n ComputedOptions,\n Disposable,\n EffectHandle,\n EffectOptions,\n Readable,\n RippleOptions,\n Scope,\n Signal,\n SignalOptions,\n Subscribable,\n} from './types';\n\nexport interface Ripple extends Disposable {\n batch<T>(fn: () => T): T;\n computed<T>(derive: () => T, options?: ComputedOptions<T>): Readable<T>;\n createScope(name?: string): Scope;\n effect(callback: () => Cleanup | undefined, options?: EffectOptions): EffectHandle;\n fromSubscribable<T>(source: Subscribable<T>, options?: FromSubscribableOptions): BridgedReadable<T>;\n resource<Source, Value>(\n source: () => Source,\n loader: (source: Source, context: { readonly signal: AbortSignal }) => Promise<Value>,\n options?: ResourceOptions,\n ): Resource<Value>;\n signal<T>(initial: T, options?: SignalOptions<T>): Signal<T>;\n untrack<T>(fn: () => T): T;\n watch<T>(\n source: Readable<T> | (() => T),\n callback: (value: T, previous: T | undefined) => void,\n options?: WatchOptions<T>,\n ): EffectHandle;\n}\n\n/**\n * Creates one complete reactive graph with its own ownership boundary. All\n * factories on the returned object share its runtime. Use this for tests, SSR\n * requests, embedded applications, or independently disposable features.\n * `dispose()` is terminal: create a new graph for a new lifetime.\n */\nexport const createRipple = (options?: RippleOptions): Ripple => {\n const runtime = new ReactiveRuntime(options);\n const fromSubscribable = createFromSubscribable(runtime);\n const resource = createResource(runtime);\n\n return {\n batch: runtime.batch,\n computed: runtime.computed,\n createScope: runtime.createScope,\n get disposalSignal() {\n return runtime.disposalSignal;\n },\n dispose: () => runtime.dispose(),\n get disposed() {\n return runtime.disposed;\n },\n effect: runtime.effect,\n fromSubscribable,\n resource,\n signal: runtime.signal,\n untrack: runtime.untrack,\n watch: createWatch(runtime),\n [Symbol.dispose]: () => runtime.dispose(),\n };\n};\n\n/**\n * The shared default reactive graph: process-lifetime. Root helpers\n * (`signal`, `computed`, `effect`, `batch`, `createScope`, `untrack`, `watch`, `resource`, `fromSubscribable`)\n * are re-exported from the package root as bound methods on this single graph\n * instance. Use these only when the application has one graph for its entire\n * lifetime; they are never disposed. For isolated, disposable graphs (tests,\n * SSR, embedded features) use `createRipple()` instead.\n */\nexport const defaultRipple = createRipple();\n"],"mappings":"kMA4CA,IAAa,aAAgB,GAAoC,CAC/D,IAAM,EAAU,IAAI,EAAgB,CAAO,EACrC,EAAmB,EAAuB,CAAO,EACjD,EAAW,EAAe,CAAO,EAEvC,MAAO,CACL,MAAO,EAAQ,MACf,SAAU,EAAQ,SAClB,YAAa,EAAQ,YACrB,IAAI,gBAAiB,CACnB,OAAO,EAAQ,cACjB,EACA,YAAe,EAAQ,QAAQ,EAC/B,IAAI,UAAW,CACb,OAAO,EAAQ,QACjB,EACA,OAAQ,EAAQ,OAChB,mBACA,WACA,OAAQ,EAAQ,OAChB,QAAS,EAAQ,QACjB,MAAO,EAAY,CAAO,GACzB,OAAO,aAAgB,EAAQ,QAAQ,CAC1C,CACF,EAUa,EAAgB,aAAa"}
1
+ {"version":3,"file":"_default.js","names":["runtime","ReactiveRuntime","options","fromSubscribable","createFromSubscribable","resource","createResource","createWatch","defaultRipple"],"sources":["../src/_default.ts"],"sourcesContent":["import { createResource, type Resource, type ResourceOptions } from './_async';\nimport { type BridgedReadable, createFromSubscribable, type FromSubscribableOptions } from './_subscribable';\nimport { createWatch, type WatchOptions } from './_watch';\nimport { ReactiveRuntime } from './runtime';\nimport type {\n Cleanup,\n ComputedOptions,\n Disposable,\n EffectHandle,\n EffectOptions,\n Readable,\n RippleOptions,\n Scope,\n Signal,\n SignalOptions,\n Subscribable,\n} from './types';\n\nexport interface Ripple extends Disposable {\n batch<T>(fn: () => T): T;\n computed<T>(derive: () => T, options?: ComputedOptions<T>): Readable<T>;\n createScope(name?: string): Scope;\n effect(callback: () => Cleanup | undefined, options?: EffectOptions): EffectHandle;\n fromSubscribable<T>(source: Subscribable<T>, options?: FromSubscribableOptions): BridgedReadable<T>;\n resource<Source, Value>(\n source: () => Source,\n loader: (source: Source, context: { readonly signal: AbortSignal }) => Promise<Value>,\n options?: ResourceOptions,\n ): Resource<Value>;\n signal<T>(initial: T, options?: SignalOptions<T>): Signal<T>;\n untrack<T>(fn: () => T): T;\n watch<T>(\n source: Readable<T> | (() => T),\n callback: (value: T, previous: T | undefined) => void,\n options?: WatchOptions<T>,\n ): EffectHandle;\n}\n\n/**\n * Creates one complete reactive graph with its own ownership boundary. All\n * factories on the returned object share its runtime. Use this for tests, SSR\n * requests, embedded applications, or independently disposable features.\n * `dispose()` is terminal: create a new graph for a new lifetime.\n */\nexport const createRipple = (options?: RippleOptions): Ripple => {\n const runtime = new ReactiveRuntime(options);\n const fromSubscribable = createFromSubscribable(runtime);\n const resource = createResource(runtime);\n\n return {\n batch: runtime.batch,\n computed: runtime.computed,\n createScope: runtime.createScope,\n get disposalSignal() {\n return runtime.disposalSignal;\n },\n dispose: () => runtime.dispose(),\n get disposed() {\n return runtime.disposed;\n },\n effect: runtime.effect,\n fromSubscribable,\n resource,\n signal: runtime.signal,\n untrack: runtime.untrack,\n watch: createWatch(runtime),\n [Symbol.dispose]: () => runtime.dispose(),\n };\n};\n\n/**\n * The shared default reactive graph: process-lifetime. Root helpers\n * (`signal`, `computed`, `effect`, `batch`, `createScope`, `untrack`, `watch`, `resource`, `fromSubscribable`)\n * are re-exported from the package root as bound methods on this single graph\n * instance. Use these only when the application has one graph for its entire\n * lifetime; they are never disposed. For isolated, disposable graphs (tests,\n * SSR, embedded features) use `createRipple()` instead.\n */\nexport const defaultRipple = createRipple();\n"],"mappings":";;;;;AA4CA,IAAa,gBAAgB,MAAoC;CAC/D,IAAMA,IAAU,IAAIC,EAAgBC,CAAO,GACrCC,IAAmBC,EAAuBJ,CAAO,GACjDK,IAAWC,EAAeN,CAAO;CAEvC,OAAO;EACL,OAAOA,EAAQ;EACf,UAAUA,EAAQ;EAClB,aAAaA,EAAQ;EACrB,IAAI,iBAAiB;GACnB,OAAOA,EAAQ;EACjB;EACA,eAAeA,EAAQ,QAAQ;EAC/B,IAAI,WAAW;GACb,OAAOA,EAAQ;EACjB;EACA,QAAQA,EAAQ;EAChB;EACA;EACA,QAAQA,EAAQ;EAChB,SAASA,EAAQ;EACjB,OAAOO,EAAYP,CAAO;GACzB,OAAO,gBAAgBA,EAAQ,QAAQ;CAC1C;AACF,GAUaQ,IAAgB,aAAa"}
@@ -1 +1 @@
1
- {"version":3,"file":"_subscribable.cjs","names":[],"sources":["../src/_subscribable.ts"],"sourcesContent":["import { RippleError } from './errors';\nimport { REACTIVE } from './runtime';\nimport type { Disposable, EffectHandle, Readable, Signal, Subscribable } from './types';\n\ntype BridgeRuntime = {\n effect(callback: () => undefined | (() => void), options?: { name?: string }): EffectHandle;\n signal<T>(initial: T, options?: { name?: string }): Signal<T>;\n};\n\nexport type BridgedReadable<T> = Readable<T> & Disposable;\nexport type FromSubscribableOptions = { name?: string; signal?: AbortSignal };\n\nexport const createFromSubscribable =\n (runtime: BridgeRuntime) =>\n <T>(source: Subscribable<T>, options?: FromSubscribableOptions): BridgedReadable<T> => {\n const node = runtime.signal<T>(source.getSnapshot(), { name: options?.name });\n const stop = runtime.effect(\n () => {\n const sync = () => {\n node.value = source.getSnapshot();\n };\n let unsubscribe: (() => void) | undefined;\n\n try {\n unsubscribe = source.subscribe(sync);\n sync();\n } catch (error) {\n unsubscribe?.();\n throw error;\n }\n\n return unsubscribe;\n },\n { name: options?.name },\n );\n const abort = () => stop.dispose();\n\n options?.signal?.addEventListener('abort', abort, { once: true });\n if (options?.signal?.aborted) stop.dispose();\n\n const assertActive = (): void => {\n if (stop.disposed) throw new RippleError('Cannot subscribe to a disposed bridge.');\n };\n const dispose = (): void => {\n options?.signal?.removeEventListener('abort', abort);\n stop.dispose();\n };\n const readable: BridgedReadable<T> = {\n get disposalSignal() {\n return stop.disposalSignal;\n },\n dispose,\n get disposed() {\n return stop.disposed;\n },\n get name() {\n return node.name;\n },\n peek: () => node.peek(),\n subscribe(listener) {\n assertActive();\n return node.subscribe(listener);\n },\n [Symbol.dispose]: dispose,\n get value() {\n return node.value;\n },\n };\n\n Object.defineProperty(readable, REACTIVE, { value: true });\n return readable;\n };\n"],"mappings":"2DAYA,IAAa,uBACV,IACG,EAAyB,IAA0D,CACrF,IAAM,EAAO,EAAQ,OAAU,EAAO,YAAY,EAAG,CAAE,KAAM,GAAS,IAAK,CAAC,EACtE,EAAO,EAAQ,WACb,CACJ,IAAM,SAAa,CACjB,EAAK,MAAQ,EAAO,YAAY,CAClC,EACI,EAEJ,GAAI,CACF,EAAc,EAAO,UAAU,IAAI,EACnC,KAAK,CACP,OAAS,EAAO,CAEd,MADA,IAAc,EACR,CACR,CAEA,OAAO,CACT,EACA,CAAE,KAAM,GAAS,IAAK,CACxB,EACM,UAAc,EAAK,QAAQ,EAEjC,GAAS,QAAQ,iBAAiB,QAAS,MAAO,CAAE,KAAM,EAAK,CAAC,EAC5D,GAAS,QAAQ,SAAS,EAAK,QAAQ,EAE3C,IAAM,iBAA2B,CAC/B,GAAI,EAAK,SAAU,MAAM,IAAI,EAAA,YAAY,wCAAwC,CACnF,EACM,YAAsB,CAC1B,GAAS,QAAQ,oBAAoB,QAAS,KAAK,EACnD,EAAK,QAAQ,CACf,EACM,EAA+B,CACnC,IAAI,gBAAiB,CACnB,OAAO,EAAK,cACd,EACA,QACA,IAAI,UAAW,CACb,OAAO,EAAK,QACd,EACA,IAAI,MAAO,CACT,OAAO,EAAK,IACd,EACA,SAAY,EAAK,KAAK,EACtB,UAAU,EAAU,CAElB,OADA,aAAa,EACN,EAAK,UAAU,CAAQ,CAChC,GACC,OAAO,SAAU,QAClB,IAAI,OAAQ,CACV,OAAO,EAAK,KACd,CACF,EAGA,OADA,OAAO,eAAe,EAAU,EAAA,SAAU,CAAE,MAAO,EAAK,CAAC,EAClD,CACT"}
1
+ {"version":3,"file":"_subscribable.cjs","names":["RippleError","REACTIVE","require_errors","require_runtime","node","runtime","source","options","stop","unsubscribe","error","readable","listener"],"sources":["../src/_subscribable.ts"],"sourcesContent":["import { RippleError } from './errors';\nimport { REACTIVE } from './runtime';\nimport type { Disposable, EffectHandle, Readable, Signal, Subscribable } from './types';\n\ntype BridgeRuntime = {\n effect(callback: () => undefined | (() => void), options?: { name?: string }): EffectHandle;\n signal<T>(initial: T, options?: { name?: string }): Signal<T>;\n};\n\nexport type BridgedReadable<T> = Readable<T> & Disposable;\nexport type FromSubscribableOptions = { name?: string; signal?: AbortSignal };\n\nexport const createFromSubscribable =\n (runtime: BridgeRuntime) =>\n <T>(source: Subscribable<T>, options?: FromSubscribableOptions): BridgedReadable<T> => {\n const node = runtime.signal<T>(source.getSnapshot(), { name: options?.name });\n const stop = runtime.effect(\n () => {\n const sync = () => {\n node.value = source.getSnapshot();\n };\n let unsubscribe: (() => void) | undefined;\n\n try {\n unsubscribe = source.subscribe(sync);\n sync();\n } catch (error) {\n unsubscribe?.();\n throw error;\n }\n\n return unsubscribe;\n },\n { name: options?.name },\n );\n const abort = () => stop.dispose();\n\n options?.signal?.addEventListener('abort', abort, { once: true });\n if (options?.signal?.aborted) stop.dispose();\n\n const assertActive = (): void => {\n if (stop.disposed) throw new RippleError('Cannot subscribe to a disposed bridge.');\n };\n const dispose = (): void => {\n options?.signal?.removeEventListener('abort', abort);\n stop.dispose();\n };\n const readable: BridgedReadable<T> = {\n get disposalSignal() {\n return stop.disposalSignal;\n },\n dispose,\n get disposed() {\n return stop.disposed;\n },\n get name() {\n return node.name;\n },\n peek: () => node.peek(),\n subscribe(listener) {\n assertActive();\n return node.subscribe(listener);\n },\n [Symbol.dispose]: dispose,\n get value() {\n return node.value;\n },\n };\n\n Object.defineProperty(readable, REACTIVE, { value: true });\n return readable;\n };\n"],"mappings":"A,2DAYA,IAAa,uBACV,IACG,EAAyB,IAA0D,CACrF,IAAMI,EAAOC,EAAQ,OAAUC,EAAO,YAAY,EAAG,CAAE,KAAMC,GAAS,IAAK,CAAC,EACtEC,EAAOH,EAAQ,WACb,CACJ,IAAM,SAAa,CACjB,EAAK,MAAQC,EAAO,YAAY,CAClC,EACIG,EAEJ,GAAI,CACF,EAAcH,EAAO,UAAU,IAAI,EACnC,KAAK,CACP,OAASI,EAAO,CAEd,MADAD,IAAc,EACRC,CACR,CAEA,OAAOD,CACT,EACA,CAAE,KAAMF,GAAS,IAAK,CACxB,EACM,UAAcC,EAAK,QAAQ,EAEjCD,GAAS,QAAQ,iBAAiB,QAAS,MAAO,CAAE,KAAM,EAAK,CAAC,EAC5DA,GAAS,QAAQ,SAASC,EAAK,QAAQ,EAE3C,IAAM,iBAA2B,CAC/B,GAAIA,EAAK,SAAU,MAAM,IAAIR,EAAAA,YAAY,wCAAwC,CACnF,EACM,YAAsB,CAC1BO,GAAS,QAAQ,oBAAoB,QAAS,KAAK,EACnDC,EAAK,QAAQ,CACf,EACMG,EAA+B,CACnC,IAAI,gBAAiB,CACnB,OAAOH,EAAK,cACd,EACA,QACA,IAAI,UAAW,CACb,OAAOA,EAAK,QACd,EACA,IAAI,MAAO,CACT,OAAOJ,EAAK,IACd,EACA,SAAYA,EAAK,KAAK,EACtB,UAAU,EAAU,CAElB,OADA,aAAa,EACNA,EAAK,UAAUQ,CAAQ,CAChC,GACC,OAAO,SAAU,QAClB,IAAI,OAAQ,CACV,OAAOR,EAAK,KACd,CACF,EAGA,OADA,OAAO,eAAeO,EAAUV,EAAAA,SAAU,CAAE,MAAO,EAAK,CAAC,EAClDU,CACT,E"}
@@ -1,2 +1,46 @@
1
- import{RippleError as e}from"./errors.js";import{REACTIVE as t}from"./runtime.js";var createFromSubscribable=n=>(r,i)=>{let a=n.signal(r.getSnapshot(),{name:i?.name}),o=n.effect(()=>{let sync=()=>{a.value=r.getSnapshot()},e;try{e=r.subscribe(sync),sync()}catch(t){throw e?.(),t}return e},{name:i?.name}),abort=()=>o.dispose();i?.signal?.addEventListener(`abort`,abort,{once:!0}),i?.signal?.aborted&&o.dispose();let assertActive=()=>{if(o.disposed)throw new e(`Cannot subscribe to a disposed bridge.`)},dispose=()=>{i?.signal?.removeEventListener(`abort`,abort),o.dispose()},s={get disposalSignal(){return o.disposalSignal},dispose,get disposed(){return o.disposed},get name(){return a.name},peek:()=>a.peek(),subscribe(e){return assertActive(),a.subscribe(e)},[Symbol.dispose]:dispose,get value(){return a.value}};return Object.defineProperty(s,t,{value:!0}),s};export{createFromSubscribable};
1
+ import { RippleError as e } from "./errors.js";
2
+ import { REACTIVE as t } from "./runtime.js";
3
+ //#region src/_subscribable.ts
4
+ var createFromSubscribable = (n) => (r, i) => {
5
+ let a = n.signal(r.getSnapshot(), { name: i?.name }), o = n.effect(() => {
6
+ let sync = () => {
7
+ a.value = r.getSnapshot();
8
+ }, e;
9
+ try {
10
+ e = r.subscribe(sync), sync();
11
+ } catch (t) {
12
+ throw e?.(), t;
13
+ }
14
+ return e;
15
+ }, { name: i?.name }), abort = () => o.dispose();
16
+ i?.signal?.addEventListener("abort", abort, { once: !0 }), i?.signal?.aborted && o.dispose();
17
+ let assertActive = () => {
18
+ if (o.disposed) throw new e("Cannot subscribe to a disposed bridge.");
19
+ }, dispose = () => {
20
+ i?.signal?.removeEventListener("abort", abort), o.dispose();
21
+ }, s = {
22
+ get disposalSignal() {
23
+ return o.disposalSignal;
24
+ },
25
+ dispose,
26
+ get disposed() {
27
+ return o.disposed;
28
+ },
29
+ get name() {
30
+ return a.name;
31
+ },
32
+ peek: () => a.peek(),
33
+ subscribe(e) {
34
+ return assertActive(), a.subscribe(e);
35
+ },
36
+ [Symbol.dispose]: dispose,
37
+ get value() {
38
+ return a.value;
39
+ }
40
+ };
41
+ return Object.defineProperty(s, t, { value: !0 }), s;
42
+ };
43
+ //#endregion
44
+ export { createFromSubscribable };
45
+
2
46
  //# sourceMappingURL=_subscribable.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_subscribable.js","names":[],"sources":["../src/_subscribable.ts"],"sourcesContent":["import { RippleError } from './errors';\nimport { REACTIVE } from './runtime';\nimport type { Disposable, EffectHandle, Readable, Signal, Subscribable } from './types';\n\ntype BridgeRuntime = {\n effect(callback: () => undefined | (() => void), options?: { name?: string }): EffectHandle;\n signal<T>(initial: T, options?: { name?: string }): Signal<T>;\n};\n\nexport type BridgedReadable<T> = Readable<T> & Disposable;\nexport type FromSubscribableOptions = { name?: string; signal?: AbortSignal };\n\nexport const createFromSubscribable =\n (runtime: BridgeRuntime) =>\n <T>(source: Subscribable<T>, options?: FromSubscribableOptions): BridgedReadable<T> => {\n const node = runtime.signal<T>(source.getSnapshot(), { name: options?.name });\n const stop = runtime.effect(\n () => {\n const sync = () => {\n node.value = source.getSnapshot();\n };\n let unsubscribe: (() => void) | undefined;\n\n try {\n unsubscribe = source.subscribe(sync);\n sync();\n } catch (error) {\n unsubscribe?.();\n throw error;\n }\n\n return unsubscribe;\n },\n { name: options?.name },\n );\n const abort = () => stop.dispose();\n\n options?.signal?.addEventListener('abort', abort, { once: true });\n if (options?.signal?.aborted) stop.dispose();\n\n const assertActive = (): void => {\n if (stop.disposed) throw new RippleError('Cannot subscribe to a disposed bridge.');\n };\n const dispose = (): void => {\n options?.signal?.removeEventListener('abort', abort);\n stop.dispose();\n };\n const readable: BridgedReadable<T> = {\n get disposalSignal() {\n return stop.disposalSignal;\n },\n dispose,\n get disposed() {\n return stop.disposed;\n },\n get name() {\n return node.name;\n },\n peek: () => node.peek(),\n subscribe(listener) {\n assertActive();\n return node.subscribe(listener);\n },\n [Symbol.dispose]: dispose,\n get value() {\n return node.value;\n },\n };\n\n Object.defineProperty(readable, REACTIVE, { value: true });\n return readable;\n };\n"],"mappings":"kFAYA,IAAa,uBACV,IACG,EAAyB,IAA0D,CACrF,IAAM,EAAO,EAAQ,OAAU,EAAO,YAAY,EAAG,CAAE,KAAM,GAAS,IAAK,CAAC,EACtE,EAAO,EAAQ,WACb,CACJ,IAAM,SAAa,CACjB,EAAK,MAAQ,EAAO,YAAY,CAClC,EACI,EAEJ,GAAI,CACF,EAAc,EAAO,UAAU,IAAI,EACnC,KAAK,CACP,OAAS,EAAO,CAEd,MADA,IAAc,EACR,CACR,CAEA,OAAO,CACT,EACA,CAAE,KAAM,GAAS,IAAK,CACxB,EACM,UAAc,EAAK,QAAQ,EAEjC,GAAS,QAAQ,iBAAiB,QAAS,MAAO,CAAE,KAAM,EAAK,CAAC,EAC5D,GAAS,QAAQ,SAAS,EAAK,QAAQ,EAE3C,IAAM,iBAA2B,CAC/B,GAAI,EAAK,SAAU,MAAM,IAAI,EAAY,wCAAwC,CACnF,EACM,YAAsB,CAC1B,GAAS,QAAQ,oBAAoB,QAAS,KAAK,EACnD,EAAK,QAAQ,CACf,EACM,EAA+B,CACnC,IAAI,gBAAiB,CACnB,OAAO,EAAK,cACd,EACA,QACA,IAAI,UAAW,CACb,OAAO,EAAK,QACd,EACA,IAAI,MAAO,CACT,OAAO,EAAK,IACd,EACA,SAAY,EAAK,KAAK,EACtB,UAAU,EAAU,CAElB,OADA,aAAa,EACN,EAAK,UAAU,CAAQ,CAChC,GACC,OAAO,SAAU,QAClB,IAAI,OAAQ,CACV,OAAO,EAAK,KACd,CACF,EAGA,OADA,OAAO,eAAe,EAAU,EAAU,CAAE,MAAO,EAAK,CAAC,EAClD,CACT"}
1
+ {"version":3,"file":"_subscribable.js","names":["node","runtime","source","options","stop","unsubscribe","error","RippleError","readable","listener","REACTIVE"],"sources":["../src/_subscribable.ts"],"sourcesContent":["import { RippleError } from './errors';\nimport { REACTIVE } from './runtime';\nimport type { Disposable, EffectHandle, Readable, Signal, Subscribable } from './types';\n\ntype BridgeRuntime = {\n effect(callback: () => undefined | (() => void), options?: { name?: string }): EffectHandle;\n signal<T>(initial: T, options?: { name?: string }): Signal<T>;\n};\n\nexport type BridgedReadable<T> = Readable<T> & Disposable;\nexport type FromSubscribableOptions = { name?: string; signal?: AbortSignal };\n\nexport const createFromSubscribable =\n (runtime: BridgeRuntime) =>\n <T>(source: Subscribable<T>, options?: FromSubscribableOptions): BridgedReadable<T> => {\n const node = runtime.signal<T>(source.getSnapshot(), { name: options?.name });\n const stop = runtime.effect(\n () => {\n const sync = () => {\n node.value = source.getSnapshot();\n };\n let unsubscribe: (() => void) | undefined;\n\n try {\n unsubscribe = source.subscribe(sync);\n sync();\n } catch (error) {\n unsubscribe?.();\n throw error;\n }\n\n return unsubscribe;\n },\n { name: options?.name },\n );\n const abort = () => stop.dispose();\n\n options?.signal?.addEventListener('abort', abort, { once: true });\n if (options?.signal?.aborted) stop.dispose();\n\n const assertActive = (): void => {\n if (stop.disposed) throw new RippleError('Cannot subscribe to a disposed bridge.');\n };\n const dispose = (): void => {\n options?.signal?.removeEventListener('abort', abort);\n stop.dispose();\n };\n const readable: BridgedReadable<T> = {\n get disposalSignal() {\n return stop.disposalSignal;\n },\n dispose,\n get disposed() {\n return stop.disposed;\n },\n get name() {\n return node.name;\n },\n peek: () => node.peek(),\n subscribe(listener) {\n assertActive();\n return node.subscribe(listener);\n },\n [Symbol.dispose]: dispose,\n get value() {\n return node.value;\n },\n };\n\n Object.defineProperty(readable, REACTIVE, { value: true });\n return readable;\n };\n"],"mappings":";;;AAYA,IAAa,0BACV,OACG,GAAyB,MAA0D;CACrF,IAAMA,IAAOC,EAAQ,OAAUC,EAAO,YAAY,GAAG,EAAE,MAAMC,GAAS,KAAK,CAAC,GACtEC,IAAOH,EAAQ,aACb;EACJ,IAAM,aAAa;GACjB,EAAK,QAAQC,EAAO,YAAY;EAClC,GACIG;EAEJ,IAAI;GAEF,AADA,IAAcH,EAAO,UAAU,IAAI,GACnC,KAAK;EACP,SAASI,GAAO;GAEd,MADAD,IAAc,GACRC;EACR;EAEA,OAAOD;CACT,GACA,EAAE,MAAMF,GAAS,KAAK,CACxB,GACM,cAAcC,EAAK,QAAQ;CAGjC,AADAD,GAAS,QAAQ,iBAAiB,SAAS,OAAO,EAAE,MAAM,GAAK,CAAC,GAC5DA,GAAS,QAAQ,WAASC,EAAK,QAAQ;CAE3C,IAAM,qBAA2B;EAC/B,IAAIA,EAAK,UAAU,MAAM,IAAIG,EAAY,wCAAwC;CACnF,GACM,gBAAsB;EAE1B,AADAJ,GAAS,QAAQ,oBAAoB,SAAS,KAAK,GACnDC,EAAK,QAAQ;CACf,GACMI,IAA+B;EACnC,IAAI,iBAAiB;GACnB,OAAOJ,EAAK;EACd;EACA;EACA,IAAI,WAAW;GACb,OAAOA,EAAK;EACd;EACA,IAAI,OAAO;GACT,OAAOJ,EAAK;EACd;EACA,YAAYA,EAAK,KAAK;EACtB,UAAU,GAAU;GAElB,OADA,aAAa,GACNA,EAAK,UAAUS,CAAQ;EAChC;GACC,OAAO,UAAU;EAClB,IAAI,QAAQ;GACV,OAAOT,EAAK;EACd;CACF;CAGA,OADA,OAAO,eAAeQ,GAAUE,GAAU,EAAE,OAAO,GAAK,CAAC,GAClDF;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"_watch.cjs","names":[],"sources":["../src/_watch.ts"],"sourcesContent":["import type { EffectHandle, Equality, Readable } from './types';\n\nexport type WatchOptions<T> = {\n equals?: Equality<T>;\n /** Run the callback once at setup, before returning the handle. */\n immediate?: boolean;\n name?: string;\n};\n\ntype WatchRuntime = {\n effect(callback: () => undefined | (() => void), options?: { name?: string }): EffectHandle;\n untrack<T>(fn: () => T): T;\n};\n\nexport const createWatch =\n (runtime: WatchRuntime) =>\n <T>(\n source: Readable<T> | (() => T),\n callback: (value: T, previous: T | undefined) => void,\n options?: WatchOptions<T>,\n ): EffectHandle => {\n const read = typeof source === 'function' ? source : () => source.value;\n const equals = options?.equals ?? Object.is;\n let initial = true;\n let previous: T | undefined;\n\n return runtime.effect(\n () => {\n const value = read();\n\n if (initial) {\n initial = false;\n previous = value;\n\n if (options?.immediate) runtime.untrack(() => callback(value, undefined));\n\n return;\n }\n\n if (equals(previous as T, value)) return;\n\n const oldValue = previous;\n\n previous = value;\n runtime.untrack(() => callback(value, oldValue));\n },\n { name: options?.name },\n );\n };\n"],"mappings":"AAcA,IAAa,YACV,IAEC,EACA,EACA,IACiB,CACjB,IAAM,EAAO,OAAO,GAAW,WAAa,MAAe,EAAO,MAC5D,EAAS,GAAS,QAAU,OAAO,GACrC,EAAU,GACV,EAEJ,OAAO,EAAQ,WACP,CACJ,IAAM,EAAQ,EAAK,EAEnB,GAAI,EAAS,CACX,EAAU,GACV,EAAW,EAEP,GAAS,WAAW,EAAQ,YAAc,EAAS,EAAO,IAAA,EAAS,CAAC,EAExE,MACF,CAEA,GAAI,EAAO,EAAe,CAAK,EAAG,OAElC,IAAM,EAAW,EAEjB,EAAW,EACX,EAAQ,YAAc,EAAS,EAAO,CAAQ,CAAC,CACjD,EACA,CAAE,KAAM,GAAS,IAAK,CACxB,CACF"}
1
+ {"version":3,"file":"_watch.cjs","names":["read","source","equals","options","initial","previous","runtime","value","callback","oldValue"],"sources":["../src/_watch.ts"],"sourcesContent":["import type { EffectHandle, Equality, Readable } from './types';\n\nexport type WatchOptions<T> = {\n equals?: Equality<T>;\n /** Run the callback once at setup, before returning the handle. */\n immediate?: boolean;\n name?: string;\n};\n\ntype WatchRuntime = {\n effect(callback: () => undefined | (() => void), options?: { name?: string }): EffectHandle;\n untrack<T>(fn: () => T): T;\n};\n\nexport const createWatch =\n (runtime: WatchRuntime) =>\n <T>(\n source: Readable<T> | (() => T),\n callback: (value: T, previous: T | undefined) => void,\n options?: WatchOptions<T>,\n ): EffectHandle => {\n const read = typeof source === 'function' ? source : () => source.value;\n const equals = options?.equals ?? Object.is;\n let initial = true;\n let previous: T | undefined;\n\n return runtime.effect(\n () => {\n const value = read();\n\n if (initial) {\n initial = false;\n previous = value;\n\n if (options?.immediate) runtime.untrack(() => callback(value, undefined));\n\n return;\n }\n\n if (equals(previous as T, value)) return;\n\n const oldValue = previous;\n\n previous = value;\n runtime.untrack(() => callback(value, oldValue));\n },\n { name: options?.name },\n );\n };\n"],"mappings":"AAcA,IAAa,YACV,IAEC,EACA,EACA,IACiB,CACjB,IAAMA,EAAO,OAAOC,GAAW,WAAaA,MAAeA,EAAO,MAC5DC,EAASC,GAAS,QAAU,OAAO,GACrCC,EAAU,GACVC,EAEJ,OAAOC,EAAQ,WACP,CACJ,IAAMC,EAAQP,EAAK,EAEnB,GAAII,EAAS,CACX,EAAU,GACV,EAAWG,EAEPJ,GAAS,WAAWG,EAAQ,YAAcE,EAASD,EAAO,IAAA,EAAS,CAAC,EAExE,MACF,CAEA,GAAIL,EAAOG,EAAeE,CAAK,EAAG,OAElC,IAAME,EAAWJ,EAEjB,EAAWE,EACXD,EAAQ,YAAcE,EAASD,EAAOE,CAAQ,CAAC,CACjD,EACA,CAAE,KAAMN,GAAS,IAAK,CACxB,CACF,E"}
package/dist/_watch.js CHANGED
@@ -1,2 +1,18 @@
1
- var createWatch=e=>(t,n,r)=>{let i=typeof t==`function`?t:()=>t.value,a=r?.equals??Object.is,o=!0,s;return e.effect(()=>{let t=i();if(o){o=!1,s=t,r?.immediate&&e.untrack(()=>n(t,void 0));return}if(a(s,t))return;let c=s;s=t,e.untrack(()=>n(t,c))},{name:r?.name})};export{createWatch};
1
+ //#region src/_watch.ts
2
+ var createWatch = (e) => (t, n, r) => {
3
+ let i = typeof t == "function" ? t : () => t.value, a = r?.equals ?? Object.is, o = !0, s;
4
+ return e.effect(() => {
5
+ let t = i();
6
+ if (o) {
7
+ o = !1, s = t, r?.immediate && e.untrack(() => n(t, void 0));
8
+ return;
9
+ }
10
+ if (a(s, t)) return;
11
+ let c = s;
12
+ s = t, e.untrack(() => n(t, c));
13
+ }, { name: r?.name });
14
+ };
15
+ //#endregion
16
+ export { createWatch };
17
+
2
18
  //# sourceMappingURL=_watch.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_watch.js","names":[],"sources":["../src/_watch.ts"],"sourcesContent":["import type { EffectHandle, Equality, Readable } from './types';\n\nexport type WatchOptions<T> = {\n equals?: Equality<T>;\n /** Run the callback once at setup, before returning the handle. */\n immediate?: boolean;\n name?: string;\n};\n\ntype WatchRuntime = {\n effect(callback: () => undefined | (() => void), options?: { name?: string }): EffectHandle;\n untrack<T>(fn: () => T): T;\n};\n\nexport const createWatch =\n (runtime: WatchRuntime) =>\n <T>(\n source: Readable<T> | (() => T),\n callback: (value: T, previous: T | undefined) => void,\n options?: WatchOptions<T>,\n ): EffectHandle => {\n const read = typeof source === 'function' ? source : () => source.value;\n const equals = options?.equals ?? Object.is;\n let initial = true;\n let previous: T | undefined;\n\n return runtime.effect(\n () => {\n const value = read();\n\n if (initial) {\n initial = false;\n previous = value;\n\n if (options?.immediate) runtime.untrack(() => callback(value, undefined));\n\n return;\n }\n\n if (equals(previous as T, value)) return;\n\n const oldValue = previous;\n\n previous = value;\n runtime.untrack(() => callback(value, oldValue));\n },\n { name: options?.name },\n );\n };\n"],"mappings":"AAcA,IAAa,YACV,IAEC,EACA,EACA,IACiB,CACjB,IAAM,EAAO,OAAO,GAAW,WAAa,MAAe,EAAO,MAC5D,EAAS,GAAS,QAAU,OAAO,GACrC,EAAU,GACV,EAEJ,OAAO,EAAQ,WACP,CACJ,IAAM,EAAQ,EAAK,EAEnB,GAAI,EAAS,CACX,EAAU,GACV,EAAW,EAEP,GAAS,WAAW,EAAQ,YAAc,EAAS,EAAO,IAAA,EAAS,CAAC,EAExE,MACF,CAEA,GAAI,EAAO,EAAe,CAAK,EAAG,OAElC,IAAM,EAAW,EAEjB,EAAW,EACX,EAAQ,YAAc,EAAS,EAAO,CAAQ,CAAC,CACjD,EACA,CAAE,KAAM,GAAS,IAAK,CACxB,CACF"}
1
+ {"version":3,"file":"_watch.js","names":["read","source","equals","options","initial","previous","runtime","value","callback","oldValue"],"sources":["../src/_watch.ts"],"sourcesContent":["import type { EffectHandle, Equality, Readable } from './types';\n\nexport type WatchOptions<T> = {\n equals?: Equality<T>;\n /** Run the callback once at setup, before returning the handle. */\n immediate?: boolean;\n name?: string;\n};\n\ntype WatchRuntime = {\n effect(callback: () => undefined | (() => void), options?: { name?: string }): EffectHandle;\n untrack<T>(fn: () => T): T;\n};\n\nexport const createWatch =\n (runtime: WatchRuntime) =>\n <T>(\n source: Readable<T> | (() => T),\n callback: (value: T, previous: T | undefined) => void,\n options?: WatchOptions<T>,\n ): EffectHandle => {\n const read = typeof source === 'function' ? source : () => source.value;\n const equals = options?.equals ?? Object.is;\n let initial = true;\n let previous: T | undefined;\n\n return runtime.effect(\n () => {\n const value = read();\n\n if (initial) {\n initial = false;\n previous = value;\n\n if (options?.immediate) runtime.untrack(() => callback(value, undefined));\n\n return;\n }\n\n if (equals(previous as T, value)) return;\n\n const oldValue = previous;\n\n previous = value;\n runtime.untrack(() => callback(value, oldValue));\n },\n { name: options?.name },\n );\n };\n"],"mappings":";AAcA,IAAa,eACV,OAEC,GACA,GACA,MACiB;CACjB,IAAMA,IAAO,OAAOC,KAAW,aAAaA,UAAeA,EAAO,OAC5DC,IAASC,GAAS,UAAU,OAAO,IACrCC,IAAU,IACVC;CAEJ,OAAOC,EAAQ,aACP;EACJ,IAAMC,IAAQP,EAAK;EAEnB,IAAII,GAAS;GAIX,AAHA,IAAU,IACV,IAAWG,GAEPJ,GAAS,aAAWG,EAAQ,cAAcE,EAASD,GAAO,KAAA,CAAS,CAAC;GAExE;EACF;EAEA,IAAIL,EAAOG,GAAeE,CAAK,GAAG;EAElC,IAAME,IAAWJ;EAGjB,AADA,IAAWE,GACXD,EAAQ,cAAcE,EAASD,GAAOE,CAAQ,CAAC;CACjD,GACA,EAAE,MAAMN,GAAS,KAAK,CACxB;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["export class RippleError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** User code that never settles: a computed cycle or a runaway flush loop. */\nexport class RippleCycleError extends RippleError {}\n\n/** Any operation against a disposed runtime, scope, resource, or bridge. */\nexport class RippleDisposedError extends RippleError {}\n"],"mappings":"AAAA,IAAa,YAAb,cAAiC,KAAM,CACrC,YAAY,EAAiB,EAAwB,CACnD,MAAM,EAAS,CAAO,EACtB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,iBAAb,cAAsC,WAAY,CAAC,EAGtC,oBAAb,cAAyC,WAAY,CAAC"}
1
+ {"version":3,"file":"errors.cjs","names":["message","options"],"sources":["../src/errors.ts"],"sourcesContent":["export class RippleError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** User code that never settles: a computed cycle or a runaway flush loop. */\nexport class RippleCycleError extends RippleError {}\n\n/** Any operation against a disposed runtime, scope, resource, or bridge. */\nexport class RippleDisposedError extends RippleError {}\n"],"mappings":"AAAA,IAAa,YAAb,cAAiC,KAAM,CACrC,YAAY,EAAiB,EAAwB,CACnD,MAAMA,EAASC,CAAO,EACtB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,iBAAb,cAAsC,WAAY,CAAC,EAGtC,oBAAb,cAAyC,WAAY,CAAC,E"}
package/dist/errors.js CHANGED
@@ -1,2 +1,10 @@
1
- var RippleError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},RippleCycleError=class extends RippleError{},RippleDisposedError=class extends RippleError{};export{RippleCycleError,RippleDisposedError,RippleError};
1
+ //#region src/errors.ts
2
+ var RippleError = class extends Error {
3
+ constructor(e, t) {
4
+ super(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);
5
+ }
6
+ }, RippleCycleError = class extends RippleError {}, RippleDisposedError = class extends RippleError {};
7
+ //#endregion
8
+ export { RippleCycleError, RippleDisposedError, RippleError };
9
+
2
10
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["export class RippleError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** User code that never settles: a computed cycle or a runaway flush loop. */\nexport class RippleCycleError extends RippleError {}\n\n/** Any operation against a disposed runtime, scope, resource, or bridge. */\nexport class RippleDisposedError extends RippleError {}\n"],"mappings":"AAAA,IAAa,YAAb,cAAiC,KAAM,CACrC,YAAY,EAAiB,EAAwB,CACnD,MAAM,EAAS,CAAO,EACtB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,iBAAb,cAAsC,WAAY,CAAC,EAGtC,oBAAb,cAAyC,WAAY,CAAC"}
1
+ {"version":3,"file":"errors.js","names":["message","options"],"sources":["../src/errors.ts"],"sourcesContent":["export class RippleError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** User code that never settles: a computed cycle or a runaway flush loop. */\nexport class RippleCycleError extends RippleError {}\n\n/** Any operation against a disposed runtime, scope, resource, or bridge. */\nexport class RippleDisposedError extends RippleError {}\n"],"mappings":";AAAA,IAAa,cAAb,cAAiC,MAAM;CACrC,YAAY,GAAiB,GAAwB;EAGnD,AAFA,MAAMA,GAASC,CAAO,GACtB,KAAK,OAAO,WAAW,MACvB,OAAO,eAAe,MAAM,WAAW,SAAS;CAClD;AACF,GAGa,mBAAb,cAAsC,YAAY,CAAC,GAGtC,sBAAb,cAAyC,YAAY,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["export type { AsyncState, Resource, ResourceOptions } from './_async';\nexport { createRipple, type Ripple } from './_default';\nexport type { BridgedReadable, FromSubscribableOptions } from './_subscribable';\nexport type { WatchOptions } from './_watch';\nexport { RippleCycleError, RippleDisposedError, RippleError } from './errors';\nexport { isReactive } from './runtime';\nexport type {\n Cleanup,\n ComputedOptions,\n Disposable,\n EffectHandle,\n EffectOptions,\n Equality,\n Readable,\n RippleErrorContext,\n RippleOptions,\n Scope,\n Signal,\n SignalOptions,\n Subscribable,\n Unsubscribe,\n} from './types';\n\nimport { defaultRipple } from './_default';\n\nexport const signal = defaultRipple.signal;\nexport const computed = defaultRipple.computed;\nexport const effect = defaultRipple.effect;\nexport const batch = defaultRipple.batch;\nexport const createScope = defaultRipple.createScope;\nexport const untrack = defaultRipple.untrack;\nexport const watch = defaultRipple.watch;\nexport const resource = defaultRipple.resource;\nexport const fromSubscribable = defaultRipple.fromSubscribable;\n"],"mappings":"0JAyBA,IAAa,EAAS,EAAA,cAAc,OACvB,EAAW,EAAA,cAAc,SACzB,EAAS,EAAA,cAAc,OACvB,EAAQ,EAAA,cAAc,MACtB,EAAc,EAAA,cAAc,YAC5B,EAAU,EAAA,cAAc,QACxB,EAAQ,EAAA,cAAc,MACtB,EAAW,EAAA,cAAc,SACzB,EAAmB,EAAA,cAAc"}
1
+ {"version":3,"file":"index.cjs","names":["defaultRipple","require_errors","require_runtime","require__default","signal","computed","effect","batch","createScope","untrack","watch","resource","fromSubscribable"],"sources":["../src/index.ts"],"sourcesContent":["export type { AsyncState, Resource, ResourceOptions } from './_async';\nexport { createRipple, type Ripple } from './_default';\nexport type { BridgedReadable, FromSubscribableOptions } from './_subscribable';\nexport type { WatchOptions } from './_watch';\nexport { RippleCycleError, RippleDisposedError, RippleError } from './errors';\nexport { isReactive } from './runtime';\nexport type {\n Cleanup,\n ComputedOptions,\n Disposable,\n EffectHandle,\n EffectOptions,\n Equality,\n Readable,\n RippleErrorContext,\n RippleOptions,\n Scope,\n Signal,\n SignalOptions,\n Subscribable,\n Unsubscribe,\n} from './types';\n\nimport { defaultRipple } from './_default';\n\nexport const signal = defaultRipple.signal;\nexport const computed = defaultRipple.computed;\nexport const effect = defaultRipple.effect;\nexport const batch = defaultRipple.batch;\nexport const createScope = defaultRipple.createScope;\nexport const untrack = defaultRipple.untrack;\nexport const watch = defaultRipple.watch;\nexport const resource = defaultRipple.resource;\nexport const fromSubscribable = defaultRipple.fromSubscribable;\n"],"mappings":"A,0JAyBA,IAAaI,EAASJ,EAAAA,cAAc,OACvBK,EAAWL,EAAAA,cAAc,SACzBM,EAASN,EAAAA,cAAc,OACvBO,EAAQP,EAAAA,cAAc,MACtBQ,EAAcR,EAAAA,cAAc,YAC5BS,EAAUT,EAAAA,cAAc,QACxBU,EAAQV,EAAAA,cAAc,MACtBW,EAAWX,EAAAA,cAAc,SACzBY,EAAmBZ,EAAAA,cAAc,iB"}
package/dist/index.js CHANGED
@@ -1,2 +1,9 @@
1
- import{RippleCycleError as e,RippleDisposedError as t,RippleError as n}from"./errors.js";import{isReactive as r}from"./runtime.js";import{createRipple as i,defaultRipple as a}from"./_default.js";var o=a.signal,s=a.computed,c=a.effect,l=a.batch,u=a.createScope,d=a.untrack,f=a.watch,p=a.resource,m=a.fromSubscribable;export{e as RippleCycleError,t as RippleDisposedError,n as RippleError,l as batch,s as computed,i as createRipple,u as createScope,c as effect,m as fromSubscribable,r as isReactive,p as resource,o as signal,d as untrack,f as watch};
1
+ import { RippleCycleError as e, RippleDisposedError as t, RippleError as n } from "./errors.js";
2
+ import { isReactive as r } from "./runtime.js";
3
+ import { createRipple as i, defaultRipple as a } from "./_default.js";
4
+ //#region src/index.ts
5
+ var o = a.signal, s = a.computed, c = a.effect, l = a.batch, u = a.createScope, d = a.untrack, f = a.watch, p = a.resource, m = a.fromSubscribable;
6
+ //#endregion
7
+ export { e as RippleCycleError, t as RippleDisposedError, n as RippleError, l as batch, s as computed, i as createRipple, u as createScope, c as effect, m as fromSubscribable, r as isReactive, p as resource, o as signal, d as untrack, f as watch };
8
+
2
9
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export type { AsyncState, Resource, ResourceOptions } from './_async';\nexport { createRipple, type Ripple } from './_default';\nexport type { BridgedReadable, FromSubscribableOptions } from './_subscribable';\nexport type { WatchOptions } from './_watch';\nexport { RippleCycleError, RippleDisposedError, RippleError } from './errors';\nexport { isReactive } from './runtime';\nexport type {\n Cleanup,\n ComputedOptions,\n Disposable,\n EffectHandle,\n EffectOptions,\n Equality,\n Readable,\n RippleErrorContext,\n RippleOptions,\n Scope,\n Signal,\n SignalOptions,\n Subscribable,\n Unsubscribe,\n} from './types';\n\nimport { defaultRipple } from './_default';\n\nexport const signal = defaultRipple.signal;\nexport const computed = defaultRipple.computed;\nexport const effect = defaultRipple.effect;\nexport const batch = defaultRipple.batch;\nexport const createScope = defaultRipple.createScope;\nexport const untrack = defaultRipple.untrack;\nexport const watch = defaultRipple.watch;\nexport const resource = defaultRipple.resource;\nexport const fromSubscribable = defaultRipple.fromSubscribable;\n"],"mappings":"mMAyBA,IAAa,EAAS,EAAc,OACvB,EAAW,EAAc,SACzB,EAAS,EAAc,OACvB,EAAQ,EAAc,MACtB,EAAc,EAAc,YAC5B,EAAU,EAAc,QACxB,EAAQ,EAAc,MACtB,EAAW,EAAc,SACzB,EAAmB,EAAc"}
1
+ {"version":3,"file":"index.js","names":["signal","defaultRipple","computed","effect","batch","createScope","untrack","watch","resource","fromSubscribable","RippleCycleError","RippleDisposedError","RippleError","createRipple","isReactive"],"sources":["../src/index.ts"],"sourcesContent":["export type { AsyncState, Resource, ResourceOptions } from './_async';\nexport { createRipple, type Ripple } from './_default';\nexport type { BridgedReadable, FromSubscribableOptions } from './_subscribable';\nexport type { WatchOptions } from './_watch';\nexport { RippleCycleError, RippleDisposedError, RippleError } from './errors';\nexport { isReactive } from './runtime';\nexport type {\n Cleanup,\n ComputedOptions,\n Disposable,\n EffectHandle,\n EffectOptions,\n Equality,\n Readable,\n RippleErrorContext,\n RippleOptions,\n Scope,\n Signal,\n SignalOptions,\n Subscribable,\n Unsubscribe,\n} from './types';\n\nimport { defaultRipple } from './_default';\n\nexport const signal = defaultRipple.signal;\nexport const computed = defaultRipple.computed;\nexport const effect = defaultRipple.effect;\nexport const batch = defaultRipple.batch;\nexport const createScope = defaultRipple.createScope;\nexport const untrack = defaultRipple.untrack;\nexport const watch = defaultRipple.watch;\nexport const resource = defaultRipple.resource;\nexport const fromSubscribable = defaultRipple.fromSubscribable;\n"],"mappings":";;;;AAyBA,IAAaA,IAASC,EAAc,QACvBC,IAAWD,EAAc,UACzBE,IAASF,EAAc,QACvBG,IAAQH,EAAc,OACtBI,IAAcJ,EAAc,aAC5BK,IAAUL,EAAc,SACxBM,IAAQN,EAAc,OACtBO,IAAWP,EAAc,UACzBQ,IAAmBR,EAAc"}