@signaldb/angular 2.0.0-rc.0 → 3.0.0

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.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,15 @@
1
+ import { CreateEffectOptions, EffectCleanupRegisterFn, EffectRef } from '@angular/core';
2
+ /**
3
+ * Drop-in replacement for Angular's `effect` that cleans up the SignalDB queries run in it
4
+ * automatically, before the effect runs again and when it is destroyed. Angular's `effect`
5
+ * gives SignalDB no way to do that, so queries run in it need a manual `cursor.cleanup()`.
6
+ * Queries run in a `computed` or a template still need it.
7
+ * @param effectFunction - The effect to run. It receives an `onCleanup` function that can be
8
+ * called any number of times, on every Angular version.
9
+ * @param options - The options passed on to Angular's `effect`.
10
+ * @returns The `EffectRef` of the created effect.
11
+ */
12
+ export declare function effect(effectFunction: (onCleanup: EffectCleanupRegisterFn) => void, options?: CreateEffectOptions): EffectRef;
1
13
  declare const angularReactivityAdapter: import('@signaldb/core').ReactivityAdapter<{
2
14
  depend: () => void;
3
15
  notify: () => void;
package/dist/index.mjs CHANGED
@@ -1,18 +1,53 @@
1
- import { signal as e, untracked as t } from "@angular/core";
2
- import { createReactivityAdapter as n } from "@signaldb/core";
3
- //#region src/index.ts
4
- var r = n({ create: () => {
5
- let n = e(0);
6
- return {
7
- depend: () => {
8
- n();
9
- },
10
- notify: () => {
11
- n.set(t(() => n() + 1));
1
+ import { assertNotInReactiveContext as e, effect as t, signal as n, untracked as r } from "@angular/core";
2
+ import { getActiveConsumer as i } from "@angular/core/primitives/signals";
3
+ import { createReactivityAdapter as a } from "@signaldb/core";
4
+ // src/index.ts
5
+ var o = [];
6
+ function s() {
7
+ try {
8
+ return e(s), !1;
9
+ } catch {
10
+ return !0;
11
+ }
12
+ }
13
+ function c(e, n) {
14
+ return t((t) => {
15
+ let n = [];
16
+ t(() => {
17
+ for (let e of n) e();
18
+ });
19
+ let r = (e) => {
20
+ n.push(e);
21
+ };
22
+ o.push({
23
+ consumer: i(),
24
+ register: r
25
+ });
26
+ try {
27
+ e(r);
28
+ } finally {
29
+ o.pop();
12
30
  }
13
- };
14
- } });
15
- //#endregion
16
- export { r as default };
31
+ }, n);
32
+ }
33
+ var l = a({
34
+ create: () => {
35
+ let e = n(0);
36
+ return {
37
+ depend: () => {
38
+ e();
39
+ },
40
+ notify: () => {
41
+ e.set(r(() => e() + 1));
42
+ }
43
+ };
44
+ },
45
+ isInScope: s,
46
+ onDispose: (e) => {
47
+ let t = o.at(-1);
48
+ t && t.consumer === i() && t.register(e);
49
+ }
50
+ });
51
+ export { l as default, c as effect };
17
52
 
18
53
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["angularReactivityAdapter","createReactivityAdapter","dependency","signal","untracked"],"sources":["../src/index.ts"],"sourcesContent":["import { signal, untracked } from '@angular/core'\nimport { createReactivityAdapter } from '@signaldb/core'\n\nconst angularReactivityAdapter = createReactivityAdapter({\n create: () => {\n const dependency = signal(0)\n return {\n depend: () => {\n dependency()\n },\n notify: () => {\n dependency.set(untracked(() => dependency() + 1))\n },\n }\n },\n})\n\nexport default angularReactivityAdapter\n"],"mappings":";;;AAGA,IAAMA,IAA2BC,EAAwB,EACvD,cAAc;CACZ,IAAMC,IAAaC,EAAO,CAAC;CAC3B,OAAO;EACL,cAAc;GACZ,EAAW;EACb;EACA,cAAc;GACZ,EAAW,IAAIC,QAAgBF,EAAW,IAAI,CAAC,CAAC;EAClD;CACF;AACF,EACF,CAAC"}
1
+ {"version":3,"file":"index.mjs","names":["angularEffect","assertNotInReactiveContext","effect$1","signal","untracked","getActiveConsumer","createReactivityAdapter","cleanupScopes","isInScope","effect","effectFunction","options","onCleanup","cleanups","cleanup","register","angularReactivityAdapter","dependency","callback","scope"],"sources":["../src/index.ts"],"sourcesContent":["import type { CreateEffectOptions, EffectCleanupRegisterFn, EffectRef } from '@angular/core'\nimport {\n assertNotInReactiveContext,\n effect as angularEffect,\n signal,\n untracked,\n} from '@angular/core'\nimport { getActiveConsumer } from '@angular/core/primitives/signals'\nimport { createReactivityAdapter } from '@signaldb/core'\n\ntype CleanupScope = {\n consumer: ReturnType<typeof getActiveConsumer>,\n register: (cleanup: () => void) => void,\n}\n\nconst cleanupScopes: CleanupScope[] = []\n\n/**\n * Checks whether the caller runs inside an Angular reactive context, such as an\n * `effect`, a `computed` or a template.\n * @returns `true` if a reactive context is active, otherwise `false`.\n */\nfunction isInScope() {\n try {\n assertNotInReactiveContext(isInScope)\n return false\n } catch {\n return true\n }\n}\n\n/**\n * Drop-in replacement for Angular's `effect` that cleans up the SignalDB queries run in it\n * automatically, before the effect runs again and when it is destroyed. Angular's `effect`\n * gives SignalDB no way to do that, so queries run in it need a manual `cursor.cleanup()`.\n * Queries run in a `computed` or a template still need it.\n * @param effectFunction - The effect to run. It receives an `onCleanup` function that can be\n * called any number of times, on every Angular version.\n * @param options - The options passed on to Angular's `effect`.\n * @returns The `EffectRef` of the created effect.\n */\nexport function effect(\n effectFunction: (onCleanup: EffectCleanupRegisterFn) => void,\n options?: CreateEffectOptions,\n): EffectRef {\n return angularEffect((onCleanup) => {\n const cleanups: (() => void)[] = []\n onCleanup(() => {\n for (const cleanup of cleanups) cleanup()\n })\n const register = (cleanup: () => void) => {\n cleanups.push(cleanup)\n }\n cleanupScopes.push({ consumer: getActiveConsumer(), register })\n try {\n effectFunction(register)\n } finally {\n cleanupScopes.pop()\n }\n }, options)\n}\n\nconst angularReactivityAdapter = createReactivityAdapter({\n create: () => {\n const dependency = signal(0)\n return {\n depend: () => {\n dependency()\n },\n notify: () => {\n dependency.set(untracked(() => dependency() + 1))\n },\n }\n },\n isInScope,\n onDispose: (callback) => {\n // A query in a `computed` read by the effect belongs to the `computed`, which may outlive\n // this run of the effect, so only queries run by the effect itself are cleaned up with it.\n const scope = cleanupScopes.at(-1)\n if (!scope || scope.consumer !== getActiveConsumer()) return\n scope.register(callback)\n },\n})\n\nexport default angularReactivityAdapter\n"],"mappings":";;;;AAeA,IAAMO,IAAgC,CAAC;AAOvC,SAASC,IAAY;CACnB,IAAI;EAEF,OADAP,EAA2BO,CAAS,GAC7B;CACT,QAAQ;EACN,OAAO;CACT;AACF;AAYA,SAAgBC,EACdC,GACAC,GACW;CACX,OAAOX,GAAeY,MAAc;EAClC,IAAMC,IAA2B,CAAC;EAClCD,QAAgB;GACd,KAAK,IAAME,KAAWD,GAAUC,EAAQ;EAC1C,CAAC;EACD,IAAMC,KAAYD,MAAwB;GACxCD,EAAS,KAAKC,CAAO;EACvB;EACAP,EAAc,KAAK;GAAE,UAAUF,EAAkB;GAAGU;EAAS,CAAC;EAC9D,IAAI;GACFL,EAAeK,CAAQ;EACzB,UAAU;GACRR,EAAc,IAAI;EACpB;CACF,GAAGI,CAAO;AACZ;AAEA,IAAMK,IAA2BV,EAAwB;CACvD,cAAc;EACZ,IAAMW,IAAad,EAAO,CAAC;EAC3B,OAAO;GACL,cAAc;IACZc,EAAW;GACb;GACA,cAAc;IACZA,EAAW,IAAIb,QAAgBa,EAAW,IAAI,CAAC,CAAC;GAClD;EACF;CACF;CACAT;CACA,YAAYU,MAAa;EAGvB,IAAMC,IAAQZ,EAAc,GAAG,EAAE;EAC5BY,KAASA,EAAM,aAAad,EAAkB,KACnDc,EAAM,SAASD,CAAQ;CACzB;AACF,CAAC"}
package/dist/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t(require("@angular/core"),require("@signaldb/core")):typeof define==`function`&&define.amd?define([`@angular/core`,`@signaldb/core`],t):(e=typeof globalThis<`u`?globalThis:e||self,e.SignalDB=t(e._angular_core,e._signaldb_core))})(this,function(e,t){return(0,t.createReactivityAdapter)({create:()=>{let t=(0,e.signal)(0);return{depend:()=>{t()},notify:()=>{t.set((0,e.untracked)(()=>t()+1))}}}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@angular/core"),require("@angular/core/primitives/signals"),require("@signaldb/core")):typeof define==`function`&&define.amd?define([`exports`,`@angular/core`,`@angular/core/primitives/signals`,`@signaldb/core`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.SignalDB={},e._angular_core,e._angular_core_primitives_signals,e._signaldb_core))})(this,function(e,t,n,r){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var i=[];function a(){try{return(0,t.assertNotInReactiveContext)(a),!1}catch{return!0}}e.default=(0,r.createReactivityAdapter)({create:()=>{let e=(0,t.signal)(0);return{depend:()=>{e()},notify:()=>{e.set((0,t.untracked)(()=>e()+1))}}},isInScope:a,onDispose:e=>{let t=i.at(-1);t&&t.consumer===(0,n.getActiveConsumer)()&&t.register(e)}}),e.effect=function(e,r){return(0,t.effect)(t=>{let r=[];t(()=>{for(let e of r)e()});let a=e=>{r.push(e)};i.push({consumer:(0,n.getActiveConsumer)(),register:a});try{e(a)}finally{i.pop()}},r)}});
2
2
  //# sourceMappingURL=index.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","names":["createReactivityAdapter","signal","untracked","factory","global","_signaldb_core","dependency","_angular_core"],"sources":["../src/index.ts"],"sourcesContent":["import { signal, untracked } from '@angular/core'\nimport { createReactivityAdapter } from '@signaldb/core'\n\nconst angularReactivityAdapter = createReactivityAdapter({\n create: () => {\n const dependency = signal(0)\n return {\n depend: () => {\n dependency()\n },\n notify: () => {\n dependency.set(untracked(() => dependency() + 1))\n },\n }\n },\n})\n\nexport default angularReactivityAdapter\n"],"mappings":"2UAGM,EAA2BA,EAAAA,wBAAAA,CAAwB,CACvD,WAAc,CACZ,IAAMM,GAAA,EAAaL,EAAAA,OAAAA,CAAO,CAAC,EAC3B,MAAO,CACL,WAAc,CACZK,EAAW,CACb,EACA,WAAc,CACZA,EAAW,KAAA,EAAIJ,EAAAA,UAAAA,KAAgBI,EAAW,EAAI,CAAC,CAAC,CAClD,CACF,CACF,CACF"}
1
+ {"version":3,"file":"index.umd.js","names":["assertNotInReactiveContext","angularEffect","getActiveConsumer","createReactivityAdapter","signal","untracked","global","factory","exports","_angular_core","_angular_core_primitives_signals","_signaldb_core","cleanupScopes","isInScope","dependency","callback","scope","effectFunction","options","onCleanup","cleanups","cleanup","register"],"sources":["../src/index.ts"],"sourcesContent":["import type { CreateEffectOptions, EffectCleanupRegisterFn, EffectRef } from '@angular/core'\nimport {\n assertNotInReactiveContext,\n effect as angularEffect,\n signal,\n untracked,\n} from '@angular/core'\nimport { getActiveConsumer } from '@angular/core/primitives/signals'\nimport { createReactivityAdapter } from '@signaldb/core'\n\ntype CleanupScope = {\n consumer: ReturnType<typeof getActiveConsumer>,\n register: (cleanup: () => void) => void,\n}\n\nconst cleanupScopes: CleanupScope[] = []\n\n/**\n * Checks whether the caller runs inside an Angular reactive context, such as an\n * `effect`, a `computed` or a template.\n * @returns `true` if a reactive context is active, otherwise `false`.\n */\nfunction isInScope() {\n try {\n assertNotInReactiveContext(isInScope)\n return false\n } catch {\n return true\n }\n}\n\n/**\n * Drop-in replacement for Angular's `effect` that cleans up the SignalDB queries run in it\n * automatically, before the effect runs again and when it is destroyed. Angular's `effect`\n * gives SignalDB no way to do that, so queries run in it need a manual `cursor.cleanup()`.\n * Queries run in a `computed` or a template still need it.\n * @param effectFunction - The effect to run. It receives an `onCleanup` function that can be\n * called any number of times, on every Angular version.\n * @param options - The options passed on to Angular's `effect`.\n * @returns The `EffectRef` of the created effect.\n */\nexport function effect(\n effectFunction: (onCleanup: EffectCleanupRegisterFn) => void,\n options?: CreateEffectOptions,\n): EffectRef {\n return angularEffect((onCleanup) => {\n const cleanups: (() => void)[] = []\n onCleanup(() => {\n for (const cleanup of cleanups) cleanup()\n })\n const register = (cleanup: () => void) => {\n cleanups.push(cleanup)\n }\n cleanupScopes.push({ consumer: getActiveConsumer(), register })\n try {\n effectFunction(register)\n } finally {\n cleanupScopes.pop()\n }\n }, options)\n}\n\nconst angularReactivityAdapter = createReactivityAdapter({\n create: () => {\n const dependency = signal(0)\n return {\n depend: () => {\n dependency()\n },\n notify: () => {\n dependency.set(untracked(() => dependency() + 1))\n },\n }\n },\n isInScope,\n onDispose: (callback) => {\n // A query in a `computed` read by the effect belongs to the `computed`, which may outlive\n // this run of the effect, so only queries run by the effect itself are cleaned up with it.\n const scope = cleanupScopes.at(-1)\n if (!scope || scope.consumer !== getActiveConsumer()) return\n scope.register(callback)\n },\n})\n\nexport default angularReactivityAdapter\n"],"mappings":"C,whBAeA,IAAMY,EAAgC,CAAC,EAOvC,SAASC,GAAY,CACnB,GAAI,CAEF,OADAb,EAAAA,EAAAA,2BAAAA,CAA2Ba,CAAS,EAC7B,EACT,MAAQ,CACN,MAAO,EACT,CACF,C,WAiCM,EAA2BV,EAAAA,wBAAAA,CAAwB,CACvD,WAAc,CACZ,IAAMW,GAAA,EAAaV,EAAAA,OAAAA,CAAO,CAAC,EAC3B,MAAO,CACL,WAAc,CACZU,EAAW,CACb,EACA,WAAc,CACZA,EAAW,KAAA,EAAIT,EAAAA,UAAAA,KAAgBS,EAAW,EAAI,CAAC,CAAC,CAClD,CACF,CACF,EACAD,YACA,UAAYE,GAAa,CAGvB,IAAMC,EAAQJ,EAAc,GAAG,EAAE,EAC5BI,GAASA,EAAM,YAAA,EAAad,EAAAA,kBAAAA,CAAkB,GACnDc,EAAM,SAASD,CAAQ,CACzB,CACF,C,WAzCA,SACEE,EACAC,EACW,CACX,OAAA,EAAOjB,EAAAA,OAAAA,CAAekB,GAAc,CAClC,IAAMC,EAA2B,CAAC,EAClCD,MAAgB,CACd,IAAK,IAAME,KAAWD,EAAUC,EAAQ,CAC1C,CAAC,EACD,IAAMC,EAAYD,GAAwB,CACxCD,EAAS,KAAKC,CAAO,CACvB,EACAT,EAAc,KAAK,CAAE,UAAA,EAAUV,EAAAA,kBAAAA,CAAkB,EAAGoB,UAAS,CAAC,EAC9D,GAAI,CACFL,EAAeK,CAAQ,CACzB,QAAU,CACRV,EAAc,IAAI,CACpB,CACF,EAAGM,CAAO,CACZ,C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signaldb/angular",
3
- "version": "2.0.0-rc.0",
3
+ "version": "3.0.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rimraf dist && vite build",
@@ -53,7 +53,7 @@
53
53
  "dist"
54
54
  ],
55
55
  "peerDependencies": {
56
- "@angular/core": "16.x.x || 17.x.x || 18.x || 19.x || 20.x || 21.x || 22.x",
56
+ "@angular/core": "17.x.x || 18.x || 19.x || 20.x || 21.x || 22.x",
57
57
  "@signaldb/core": "1.x || ^2.0.0-0"
58
58
  },
59
59
  "devDependencies": {