@iadev93/zuno-angular 0.0.2 → 0.0.3
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.cjs +93 -0
- package/dist/{index.mjs.map → index.cjs.map} +1 -1
- package/dist/index.js +21 -44
- package/dist/index.js.map +1 -1
- package/package.json +12 -6
- package/dist/index.mjs +0 -70
- /package/dist/{index.d.mts → index.d.cts} +0 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
ZUNO_OPTIONS: () => ZUNO_OPTIONS,
|
|
25
|
+
ZunoService: () => ZunoService,
|
|
26
|
+
provideZuno: () => provideZuno
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
var import_core = require("@angular/core");
|
|
30
|
+
var import_rxjs_interop = require("@angular/core/rxjs-interop");
|
|
31
|
+
var import_zuno = require("@iadev93/zuno");
|
|
32
|
+
var import_rxjs = require("rxjs");
|
|
33
|
+
__reExport(index_exports, require("@iadev93/zuno"), module.exports);
|
|
34
|
+
var ZUNO_OPTIONS = new import_core.InjectionToken(
|
|
35
|
+
"ZUNO_OPTIONS"
|
|
36
|
+
);
|
|
37
|
+
var ZunoService = class {
|
|
38
|
+
constructor() {
|
|
39
|
+
const options = (0, import_core.inject)(ZUNO_OPTIONS, { optional: true }) || {};
|
|
40
|
+
this.zuno = (0, import_zuno.createZuno)(options);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create or retrieve a Zuno store with Angular bindings.
|
|
44
|
+
*/
|
|
45
|
+
store(key, init, reducer, equals) {
|
|
46
|
+
const baseStore = this.zuno.store(key, init, reducer, equals);
|
|
47
|
+
const asObservable = () => new import_rxjs.Observable((subscriber) => {
|
|
48
|
+
subscriber.next(baseStore.get());
|
|
49
|
+
const sub = baseStore.subscribe((state) => {
|
|
50
|
+
subscriber.next(state);
|
|
51
|
+
});
|
|
52
|
+
return () => sub();
|
|
53
|
+
}).pipe(
|
|
54
|
+
(0, import_rxjs.distinctUntilChanged)(
|
|
55
|
+
(previous, current) => baseStore.equals(previous, current)
|
|
56
|
+
)
|
|
57
|
+
);
|
|
58
|
+
const asSignal = () => {
|
|
59
|
+
return (0, import_rxjs_interop.toSignal)(asObservable(), { initialValue: baseStore.get() });
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
...baseStore,
|
|
63
|
+
asObservable,
|
|
64
|
+
asSignal
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
get(key, init) {
|
|
68
|
+
return this.zuno.get(key, init);
|
|
69
|
+
}
|
|
70
|
+
set(key, next, init) {
|
|
71
|
+
return this.zuno.set(key, next, init);
|
|
72
|
+
}
|
|
73
|
+
mutate(key, intent) {
|
|
74
|
+
return this.zuno.mutate(key, intent);
|
|
75
|
+
}
|
|
76
|
+
snapshot() {
|
|
77
|
+
return this.zuno.universe.snapshot();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
function provideZuno(options = {}) {
|
|
81
|
+
return (0, import_core.makeEnvironmentProviders)([
|
|
82
|
+
{ provide: ZUNO_OPTIONS, useValue: options },
|
|
83
|
+
ZunoService
|
|
84
|
+
]);
|
|
85
|
+
}
|
|
86
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
+
0 && (module.exports = {
|
|
88
|
+
ZUNO_OPTIONS,
|
|
89
|
+
ZunoService,
|
|
90
|
+
provideZuno,
|
|
91
|
+
...require("@iadev93/zuno")
|
|
92
|
+
});
|
|
93
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import {\n\ttype EnvironmentProviders,\n\tInjectionToken,\n\tinject,\n\tmakeEnvironmentProviders,\n\ttype Signal,\n} from \"@angular/core\";\nimport { toSignal } from \"@angular/core/rxjs-interop\";\nimport {\n\ttype BoundStore,\n\ttype CreateZunoOptions,\n\tcreateZuno,\n} from \"@iadev93/zuno\";\nimport { distinctUntilChanged, Observable } from \"rxjs\";\n\nexport const ZUNO_OPTIONS = new InjectionToken<CreateZunoOptions>(\n\t\"ZUNO_OPTIONS\",\n);\n\n/**\n * An Angular-enhanced Zuno store.\n */\nexport type AngularBoundStore<T> = BoundStore<T> & {\n\t/**\n\t * Returns the store state as an RxJS Observable.\n\t * The Observable emits distinct values based on the store's equality check.\n\t */\n\tasObservable: () => Observable<T>;\n\n\t/**\n\t * Returns the store state as an Angular Signal.\n\t * WARNING: Must be called within an injection context (e.g. constructor)\n\t * so that cleanup can be handled automatically.\n\t */\n\tasSignal: () => Signal<T>;\n};\n\n// --- Service ---\n// Note: We use the function-based DI pattern or Injectable.\n// Biome suggested removing Injectable if not used as a decorator, but it IS used.\n\n/**\n * ZunoService provides access to Zuno stores in Angular.\n */\nexport class ZunoService {\n\tprivate zuno;\n\n\tconstructor() {\n\t\tconst options = inject(ZUNO_OPTIONS, { optional: true }) || {};\n\t\tthis.zuno = createZuno(options);\n\t}\n\n\t/**\n\t * Create or retrieve a Zuno store with Angular bindings.\n\t */\n\tstore<T>(\n\t\tkey: string,\n\t\tinit: () => T,\n\t\treducer?: (prev: T, intent: unknown) => T,\n\t\tequals?: (v1: unknown, v2: unknown) => boolean,\n\t): AngularBoundStore<T> {\n\t\tconst baseStore = this.zuno.store<T>(key, init, reducer, equals);\n\n\t\tconst asObservable: () => Observable<T> = () =>\n\t\t\tnew Observable<T>((subscriber) => {\n\t\t\t\tsubscriber.next(baseStore.get());\n\t\t\t\tconst sub = baseStore.subscribe((state) => {\n\t\t\t\t\tsubscriber.next(state);\n\t\t\t\t});\n\t\t\t\treturn () => sub();\n\t\t\t}).pipe(\n\t\t\t\tdistinctUntilChanged((previous: T, current: T) =>\n\t\t\t\t\tbaseStore.equals(previous, current),\n\t\t\t\t),\n\t\t\t);\n\n\t\tconst asSignal: () => Signal<T> = () => {\n\t\t\treturn toSignal(asObservable(), { initialValue: baseStore.get() });\n\t\t};\n\n\t\treturn {\n\t\t\t...baseStore,\n\t\t\tasObservable,\n\t\t\tasSignal,\n\t\t};\n\t}\n\n\tget<T>(key: string, init?: () => T): T {\n\t\treturn this.zuno.get(key, init);\n\t}\n\n\tset<T>(key: string, next: T | ((prev: T) => T), init?: () => T) {\n\t\treturn this.zuno.set(key, next, init);\n\t}\n\n\tmutate(key: string, intent: { type: string; payload?: unknown }) {\n\t\treturn this.zuno.mutate(key, intent);\n\t}\n\n\tsnapshot() {\n\t\treturn this.zuno.universe.snapshot();\n\t}\n}\n\n/**\n * Configures Zuno for the application.\n */\nexport function provideZuno(\n\toptions: CreateZunoOptions = {},\n): EnvironmentProviders {\n\treturn makeEnvironmentProviders([\n\t\t{ provide: ZUNO_OPTIONS, useValue: options },\n\t\tZunoService,\n\t]);\n}\n\n// Re-export core types\nexport * from \"@iadev93/zuno\";\n"],"mappings":";AAAA;AAAA
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import {\n\ttype EnvironmentProviders,\n\tInjectionToken,\n\tinject,\n\tmakeEnvironmentProviders,\n\ttype Signal,\n} from \"@angular/core\";\nimport { toSignal } from \"@angular/core/rxjs-interop\";\nimport {\n\ttype BoundStore,\n\ttype CreateZunoOptions,\n\tcreateZuno,\n} from \"@iadev93/zuno\";\nimport { distinctUntilChanged, Observable } from \"rxjs\";\n\nexport const ZUNO_OPTIONS = new InjectionToken<CreateZunoOptions>(\n\t\"ZUNO_OPTIONS\",\n);\n\n/**\n * An Angular-enhanced Zuno store.\n */\nexport type AngularBoundStore<T> = BoundStore<T> & {\n\t/**\n\t * Returns the store state as an RxJS Observable.\n\t * The Observable emits distinct values based on the store's equality check.\n\t */\n\tasObservable: () => Observable<T>;\n\n\t/**\n\t * Returns the store state as an Angular Signal.\n\t * WARNING: Must be called within an injection context (e.g. constructor)\n\t * so that cleanup can be handled automatically.\n\t */\n\tasSignal: () => Signal<T>;\n};\n\n// --- Service ---\n// Note: We use the function-based DI pattern or Injectable.\n// Biome suggested removing Injectable if not used as a decorator, but it IS used.\n\n/**\n * ZunoService provides access to Zuno stores in Angular.\n */\nexport class ZunoService {\n\tprivate zuno;\n\n\tconstructor() {\n\t\tconst options = inject(ZUNO_OPTIONS, { optional: true }) || {};\n\t\tthis.zuno = createZuno(options);\n\t}\n\n\t/**\n\t * Create or retrieve a Zuno store with Angular bindings.\n\t */\n\tstore<T>(\n\t\tkey: string,\n\t\tinit: () => T,\n\t\treducer?: (prev: T, intent: unknown) => T,\n\t\tequals?: (v1: unknown, v2: unknown) => boolean,\n\t): AngularBoundStore<T> {\n\t\tconst baseStore = this.zuno.store<T>(key, init, reducer, equals);\n\n\t\tconst asObservable: () => Observable<T> = () =>\n\t\t\tnew Observable<T>((subscriber) => {\n\t\t\t\tsubscriber.next(baseStore.get());\n\t\t\t\tconst sub = baseStore.subscribe((state) => {\n\t\t\t\t\tsubscriber.next(state);\n\t\t\t\t});\n\t\t\t\treturn () => sub();\n\t\t\t}).pipe(\n\t\t\t\tdistinctUntilChanged((previous: T, current: T) =>\n\t\t\t\t\tbaseStore.equals(previous, current),\n\t\t\t\t),\n\t\t\t);\n\n\t\tconst asSignal: () => Signal<T> = () => {\n\t\t\treturn toSignal(asObservable(), { initialValue: baseStore.get() });\n\t\t};\n\n\t\treturn {\n\t\t\t...baseStore,\n\t\t\tasObservable,\n\t\t\tasSignal,\n\t\t};\n\t}\n\n\tget<T>(key: string, init?: () => T): T {\n\t\treturn this.zuno.get(key, init);\n\t}\n\n\tset<T>(key: string, next: T | ((prev: T) => T), init?: () => T) {\n\t\treturn this.zuno.set(key, next, init);\n\t}\n\n\tmutate(key: string, intent: { type: string; payload?: unknown }) {\n\t\treturn this.zuno.mutate(key, intent);\n\t}\n\n\tsnapshot() {\n\t\treturn this.zuno.universe.snapshot();\n\t}\n}\n\n/**\n * Configures Zuno for the application.\n */\nexport function provideZuno(\n\toptions: CreateZunoOptions = {},\n): EnvironmentProviders {\n\treturn makeEnvironmentProviders([\n\t\t{ provide: ZUNO_OPTIONS, useValue: options },\n\t\tZunoService,\n\t]);\n}\n\n// Re-export core types\nexport * from \"@iadev93/zuno\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAMO;AACP,0BAAyB;AACzB,kBAIO;AACP,kBAAiD;AAwGjD,0BAAc,0BArHd;AAeO,IAAM,eAAe,IAAI;AAAA,EAC/B;AACD;AA2BO,IAAM,cAAN,MAAkB;AAAA,EAGxB,cAAc;AACb,UAAM,cAAU,oBAAO,cAAc,EAAE,UAAU,KAAK,CAAC,KAAK,CAAC;AAC7D,SAAK,WAAO,wBAAW,OAAO;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA,EAKA,MACC,KACA,MACA,SACA,QACuB;AACvB,UAAM,YAAY,KAAK,KAAK,MAAS,KAAK,MAAM,SAAS,MAAM;AAE/D,UAAM,eAAoC,MACzC,IAAI,uBAAc,CAAC,eAAe;AACjC,iBAAW,KAAK,UAAU,IAAI,CAAC;AAC/B,YAAM,MAAM,UAAU,UAAU,CAAC,UAAU;AAC1C,mBAAW,KAAK,KAAK;AAAA,MACtB,CAAC;AACD,aAAO,MAAM,IAAI;AAAA,IAClB,CAAC,EAAE;AAAA,UACF;AAAA,QAAqB,CAAC,UAAa,YAClC,UAAU,OAAO,UAAU,OAAO;AAAA,MACnC;AAAA,IACD;AAED,UAAM,WAA4B,MAAM;AACvC,iBAAO,8BAAS,aAAa,GAAG,EAAE,cAAc,UAAU,IAAI,EAAE,CAAC;AAAA,IAClE;AAEA,WAAO;AAAA,MACN,GAAG;AAAA,MACH;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAAA,EAEA,IAAO,KAAa,MAAmB;AACtC,WAAO,KAAK,KAAK,IAAI,KAAK,IAAI;AAAA,EAC/B;AAAA,EAEA,IAAO,KAAa,MAA4B,MAAgB;AAC/D,WAAO,KAAK,KAAK,IAAI,KAAK,MAAM,IAAI;AAAA,EACrC;AAAA,EAEA,OAAO,KAAa,QAA6C;AAChE,WAAO,KAAK,KAAK,OAAO,KAAK,MAAM;AAAA,EACpC;AAAA,EAEA,WAAW;AACV,WAAO,KAAK,KAAK,SAAS,SAAS;AAAA,EACpC;AACD;AAKO,SAAS,YACf,UAA6B,CAAC,GACP;AACvB,aAAO,sCAAyB;AAAA,IAC/B,EAAE,SAAS,cAAc,UAAU,QAAQ;AAAA,IAC3C;AAAA,EACD,CAAC;AACF;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -1,62 +1,41 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
|
|
21
1
|
// src/index.ts
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var ZUNO_OPTIONS = new import_core.InjectionToken(
|
|
2
|
+
import {
|
|
3
|
+
InjectionToken,
|
|
4
|
+
inject,
|
|
5
|
+
makeEnvironmentProviders
|
|
6
|
+
} from "@angular/core";
|
|
7
|
+
import { toSignal } from "@angular/core/rxjs-interop";
|
|
8
|
+
import {
|
|
9
|
+
createZuno
|
|
10
|
+
} from "@iadev93/zuno";
|
|
11
|
+
import { distinctUntilChanged, Observable } from "rxjs";
|
|
12
|
+
export * from "@iadev93/zuno";
|
|
13
|
+
var ZUNO_OPTIONS = new InjectionToken(
|
|
35
14
|
"ZUNO_OPTIONS"
|
|
36
15
|
);
|
|
37
16
|
var ZunoService = class {
|
|
38
17
|
constructor() {
|
|
39
|
-
const options =
|
|
40
|
-
this.zuno =
|
|
18
|
+
const options = inject(ZUNO_OPTIONS, { optional: true }) || {};
|
|
19
|
+
this.zuno = createZuno(options);
|
|
41
20
|
}
|
|
42
21
|
/**
|
|
43
22
|
* Create or retrieve a Zuno store with Angular bindings.
|
|
44
23
|
*/
|
|
45
24
|
store(key, init, reducer, equals) {
|
|
46
25
|
const baseStore = this.zuno.store(key, init, reducer, equals);
|
|
47
|
-
const asObservable = () => new
|
|
26
|
+
const asObservable = () => new Observable((subscriber) => {
|
|
48
27
|
subscriber.next(baseStore.get());
|
|
49
28
|
const sub = baseStore.subscribe((state) => {
|
|
50
29
|
subscriber.next(state);
|
|
51
30
|
});
|
|
52
31
|
return () => sub();
|
|
53
32
|
}).pipe(
|
|
54
|
-
|
|
33
|
+
distinctUntilChanged(
|
|
55
34
|
(previous, current) => baseStore.equals(previous, current)
|
|
56
35
|
)
|
|
57
36
|
);
|
|
58
37
|
const asSignal = () => {
|
|
59
|
-
return
|
|
38
|
+
return toSignal(asObservable(), { initialValue: baseStore.get() });
|
|
60
39
|
};
|
|
61
40
|
return {
|
|
62
41
|
...baseStore,
|
|
@@ -78,16 +57,14 @@ var ZunoService = class {
|
|
|
78
57
|
}
|
|
79
58
|
};
|
|
80
59
|
function provideZuno(options = {}) {
|
|
81
|
-
return
|
|
60
|
+
return makeEnvironmentProviders([
|
|
82
61
|
{ provide: ZUNO_OPTIONS, useValue: options },
|
|
83
62
|
ZunoService
|
|
84
63
|
]);
|
|
85
64
|
}
|
|
86
|
-
|
|
87
|
-
0 && (module.exports = {
|
|
65
|
+
export {
|
|
88
66
|
ZUNO_OPTIONS,
|
|
89
67
|
ZunoService,
|
|
90
|
-
provideZuno
|
|
91
|
-
|
|
92
|
-
});
|
|
68
|
+
provideZuno
|
|
69
|
+
};
|
|
93
70
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import {\n\ttype EnvironmentProviders,\n\tInjectionToken,\n\tinject,\n\tmakeEnvironmentProviders,\n\ttype Signal,\n} from \"@angular/core\";\nimport { toSignal } from \"@angular/core/rxjs-interop\";\nimport {\n\ttype BoundStore,\n\ttype CreateZunoOptions,\n\tcreateZuno,\n} from \"@iadev93/zuno\";\nimport { distinctUntilChanged, Observable } from \"rxjs\";\n\nexport const ZUNO_OPTIONS = new InjectionToken<CreateZunoOptions>(\n\t\"ZUNO_OPTIONS\",\n);\n\n/**\n * An Angular-enhanced Zuno store.\n */\nexport type AngularBoundStore<T> = BoundStore<T> & {\n\t/**\n\t * Returns the store state as an RxJS Observable.\n\t * The Observable emits distinct values based on the store's equality check.\n\t */\n\tasObservable: () => Observable<T>;\n\n\t/**\n\t * Returns the store state as an Angular Signal.\n\t * WARNING: Must be called within an injection context (e.g. constructor)\n\t * so that cleanup can be handled automatically.\n\t */\n\tasSignal: () => Signal<T>;\n};\n\n// --- Service ---\n// Note: We use the function-based DI pattern or Injectable.\n// Biome suggested removing Injectable if not used as a decorator, but it IS used.\n\n/**\n * ZunoService provides access to Zuno stores in Angular.\n */\nexport class ZunoService {\n\tprivate zuno;\n\n\tconstructor() {\n\t\tconst options = inject(ZUNO_OPTIONS, { optional: true }) || {};\n\t\tthis.zuno = createZuno(options);\n\t}\n\n\t/**\n\t * Create or retrieve a Zuno store with Angular bindings.\n\t */\n\tstore<T>(\n\t\tkey: string,\n\t\tinit: () => T,\n\t\treducer?: (prev: T, intent: unknown) => T,\n\t\tequals?: (v1: unknown, v2: unknown) => boolean,\n\t): AngularBoundStore<T> {\n\t\tconst baseStore = this.zuno.store<T>(key, init, reducer, equals);\n\n\t\tconst asObservable: () => Observable<T> = () =>\n\t\t\tnew Observable<T>((subscriber) => {\n\t\t\t\tsubscriber.next(baseStore.get());\n\t\t\t\tconst sub = baseStore.subscribe((state) => {\n\t\t\t\t\tsubscriber.next(state);\n\t\t\t\t});\n\t\t\t\treturn () => sub();\n\t\t\t}).pipe(\n\t\t\t\tdistinctUntilChanged((previous: T, current: T) =>\n\t\t\t\t\tbaseStore.equals(previous, current),\n\t\t\t\t),\n\t\t\t);\n\n\t\tconst asSignal: () => Signal<T> = () => {\n\t\t\treturn toSignal(asObservable(), { initialValue: baseStore.get() });\n\t\t};\n\n\t\treturn {\n\t\t\t...baseStore,\n\t\t\tasObservable,\n\t\t\tasSignal,\n\t\t};\n\t}\n\n\tget<T>(key: string, init?: () => T): T {\n\t\treturn this.zuno.get(key, init);\n\t}\n\n\tset<T>(key: string, next: T | ((prev: T) => T), init?: () => T) {\n\t\treturn this.zuno.set(key, next, init);\n\t}\n\n\tmutate(key: string, intent: { type: string; payload?: unknown }) {\n\t\treturn this.zuno.mutate(key, intent);\n\t}\n\n\tsnapshot() {\n\t\treturn this.zuno.universe.snapshot();\n\t}\n}\n\n/**\n * Configures Zuno for the application.\n */\nexport function provideZuno(\n\toptions: CreateZunoOptions = {},\n): EnvironmentProviders {\n\treturn makeEnvironmentProviders([\n\t\t{ provide: ZUNO_OPTIONS, useValue: options },\n\t\tZunoService,\n\t]);\n}\n\n// Re-export core types\nexport * from \"@iadev93/zuno\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import {\n\ttype EnvironmentProviders,\n\tInjectionToken,\n\tinject,\n\tmakeEnvironmentProviders,\n\ttype Signal,\n} from \"@angular/core\";\nimport { toSignal } from \"@angular/core/rxjs-interop\";\nimport {\n\ttype BoundStore,\n\ttype CreateZunoOptions,\n\tcreateZuno,\n} from \"@iadev93/zuno\";\nimport { distinctUntilChanged, Observable } from \"rxjs\";\n\nexport const ZUNO_OPTIONS = new InjectionToken<CreateZunoOptions>(\n\t\"ZUNO_OPTIONS\",\n);\n\n/**\n * An Angular-enhanced Zuno store.\n */\nexport type AngularBoundStore<T> = BoundStore<T> & {\n\t/**\n\t * Returns the store state as an RxJS Observable.\n\t * The Observable emits distinct values based on the store's equality check.\n\t */\n\tasObservable: () => Observable<T>;\n\n\t/**\n\t * Returns the store state as an Angular Signal.\n\t * WARNING: Must be called within an injection context (e.g. constructor)\n\t * so that cleanup can be handled automatically.\n\t */\n\tasSignal: () => Signal<T>;\n};\n\n// --- Service ---\n// Note: We use the function-based DI pattern or Injectable.\n// Biome suggested removing Injectable if not used as a decorator, but it IS used.\n\n/**\n * ZunoService provides access to Zuno stores in Angular.\n */\nexport class ZunoService {\n\tprivate zuno;\n\n\tconstructor() {\n\t\tconst options = inject(ZUNO_OPTIONS, { optional: true }) || {};\n\t\tthis.zuno = createZuno(options);\n\t}\n\n\t/**\n\t * Create or retrieve a Zuno store with Angular bindings.\n\t */\n\tstore<T>(\n\t\tkey: string,\n\t\tinit: () => T,\n\t\treducer?: (prev: T, intent: unknown) => T,\n\t\tequals?: (v1: unknown, v2: unknown) => boolean,\n\t): AngularBoundStore<T> {\n\t\tconst baseStore = this.zuno.store<T>(key, init, reducer, equals);\n\n\t\tconst asObservable: () => Observable<T> = () =>\n\t\t\tnew Observable<T>((subscriber) => {\n\t\t\t\tsubscriber.next(baseStore.get());\n\t\t\t\tconst sub = baseStore.subscribe((state) => {\n\t\t\t\t\tsubscriber.next(state);\n\t\t\t\t});\n\t\t\t\treturn () => sub();\n\t\t\t}).pipe(\n\t\t\t\tdistinctUntilChanged((previous: T, current: T) =>\n\t\t\t\t\tbaseStore.equals(previous, current),\n\t\t\t\t),\n\t\t\t);\n\n\t\tconst asSignal: () => Signal<T> = () => {\n\t\t\treturn toSignal(asObservable(), { initialValue: baseStore.get() });\n\t\t};\n\n\t\treturn {\n\t\t\t...baseStore,\n\t\t\tasObservable,\n\t\t\tasSignal,\n\t\t};\n\t}\n\n\tget<T>(key: string, init?: () => T): T {\n\t\treturn this.zuno.get(key, init);\n\t}\n\n\tset<T>(key: string, next: T | ((prev: T) => T), init?: () => T) {\n\t\treturn this.zuno.set(key, next, init);\n\t}\n\n\tmutate(key: string, intent: { type: string; payload?: unknown }) {\n\t\treturn this.zuno.mutate(key, intent);\n\t}\n\n\tsnapshot() {\n\t\treturn this.zuno.universe.snapshot();\n\t}\n}\n\n/**\n * Configures Zuno for the application.\n */\nexport function provideZuno(\n\toptions: CreateZunoOptions = {},\n): EnvironmentProviders {\n\treturn makeEnvironmentProviders([\n\t\t{ provide: ZUNO_OPTIONS, useValue: options },\n\t\tZunoService,\n\t]);\n}\n\n// Re-export core types\nexport * from \"@iadev93/zuno\";\n"],"mappings":";AAAA;AAAA,EAEC;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AACP,SAAS,gBAAgB;AACzB;AAAA,EAGC;AAAA,OACM;AACP,SAAS,sBAAsB,kBAAkB;AAwGjD,cAAc;AAtGP,IAAM,eAAe,IAAI;AAAA,EAC/B;AACD;AA2BO,IAAM,cAAN,MAAkB;AAAA,EAGxB,cAAc;AACb,UAAM,UAAU,OAAO,cAAc,EAAE,UAAU,KAAK,CAAC,KAAK,CAAC;AAC7D,SAAK,OAAO,WAAW,OAAO;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA,EAKA,MACC,KACA,MACA,SACA,QACuB;AACvB,UAAM,YAAY,KAAK,KAAK,MAAS,KAAK,MAAM,SAAS,MAAM;AAE/D,UAAM,eAAoC,MACzC,IAAI,WAAc,CAAC,eAAe;AACjC,iBAAW,KAAK,UAAU,IAAI,CAAC;AAC/B,YAAM,MAAM,UAAU,UAAU,CAAC,UAAU;AAC1C,mBAAW,KAAK,KAAK;AAAA,MACtB,CAAC;AACD,aAAO,MAAM,IAAI;AAAA,IAClB,CAAC,EAAE;AAAA,MACF;AAAA,QAAqB,CAAC,UAAa,YAClC,UAAU,OAAO,UAAU,OAAO;AAAA,MACnC;AAAA,IACD;AAED,UAAM,WAA4B,MAAM;AACvC,aAAO,SAAS,aAAa,GAAG,EAAE,cAAc,UAAU,IAAI,EAAE,CAAC;AAAA,IAClE;AAEA,WAAO;AAAA,MACN,GAAG;AAAA,MACH;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAAA,EAEA,IAAO,KAAa,MAAmB;AACtC,WAAO,KAAK,KAAK,IAAI,KAAK,IAAI;AAAA,EAC/B;AAAA,EAEA,IAAO,KAAa,MAA4B,MAAgB;AAC/D,WAAO,KAAK,KAAK,IAAI,KAAK,MAAM,IAAI;AAAA,EACrC;AAAA,EAEA,OAAO,KAAa,QAA6C;AAChE,WAAO,KAAK,KAAK,OAAO,KAAK,MAAM;AAAA,EACpC;AAAA,EAEA,WAAW;AACV,WAAO,KAAK,KAAK,SAAS,SAAS;AAAA,EACpC;AACD;AAKO,SAAS,YACf,UAA6B,CAAC,GACP;AACvB,SAAO,yBAAyB;AAAA,IAC/B,EAAE,SAAS,cAAc,UAAU,QAAQ;AAAA,IAC3C;AAAA,EACD,CAAC;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iadev93/zuno-angular",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
5
7
|
"types": "./dist/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=22"
|
|
11
|
+
},
|
|
6
12
|
"files": [
|
|
7
13
|
"dist",
|
|
8
14
|
"README.md",
|
|
@@ -11,14 +17,14 @@
|
|
|
11
17
|
"exports": {
|
|
12
18
|
".": {
|
|
13
19
|
"types": "./dist/index.d.ts",
|
|
14
|
-
"import": "./dist/index.
|
|
15
|
-
"require": "./dist/index.
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"require": "./dist/index.cjs"
|
|
16
22
|
}
|
|
17
23
|
},
|
|
18
24
|
"peerDependencies": {
|
|
19
25
|
"@angular/core": "^19.0.0",
|
|
20
26
|
"rxjs": "^7.8.0",
|
|
21
|
-
"@iadev93/zuno": "0.0.
|
|
27
|
+
"@iadev93/zuno": "0.0.15"
|
|
22
28
|
},
|
|
23
29
|
"devDependencies": {
|
|
24
30
|
"@angular/core": "^19.0.0",
|
|
@@ -29,7 +35,7 @@
|
|
|
29
35
|
"tsup": "^8.5.1",
|
|
30
36
|
"typescript": "5.8.3",
|
|
31
37
|
"zone.js": "^0.15.0",
|
|
32
|
-
"@iadev93/zuno": "0.0.
|
|
38
|
+
"@iadev93/zuno": "0.0.15"
|
|
33
39
|
},
|
|
34
40
|
"keywords": [
|
|
35
41
|
"zuno",
|
package/dist/index.mjs
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import {
|
|
3
|
-
InjectionToken,
|
|
4
|
-
inject,
|
|
5
|
-
makeEnvironmentProviders
|
|
6
|
-
} from "@angular/core";
|
|
7
|
-
import { toSignal } from "@angular/core/rxjs-interop";
|
|
8
|
-
import {
|
|
9
|
-
createZuno
|
|
10
|
-
} from "@iadev93/zuno";
|
|
11
|
-
import { distinctUntilChanged, Observable } from "rxjs";
|
|
12
|
-
export * from "@iadev93/zuno";
|
|
13
|
-
var ZUNO_OPTIONS = new InjectionToken(
|
|
14
|
-
"ZUNO_OPTIONS"
|
|
15
|
-
);
|
|
16
|
-
var ZunoService = class {
|
|
17
|
-
constructor() {
|
|
18
|
-
const options = inject(ZUNO_OPTIONS, { optional: true }) || {};
|
|
19
|
-
this.zuno = createZuno(options);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Create or retrieve a Zuno store with Angular bindings.
|
|
23
|
-
*/
|
|
24
|
-
store(key, init, reducer, equals) {
|
|
25
|
-
const baseStore = this.zuno.store(key, init, reducer, equals);
|
|
26
|
-
const asObservable = () => new Observable((subscriber) => {
|
|
27
|
-
subscriber.next(baseStore.get());
|
|
28
|
-
const sub = baseStore.subscribe((state) => {
|
|
29
|
-
subscriber.next(state);
|
|
30
|
-
});
|
|
31
|
-
return () => sub();
|
|
32
|
-
}).pipe(
|
|
33
|
-
distinctUntilChanged(
|
|
34
|
-
(previous, current) => baseStore.equals(previous, current)
|
|
35
|
-
)
|
|
36
|
-
);
|
|
37
|
-
const asSignal = () => {
|
|
38
|
-
return toSignal(asObservable(), { initialValue: baseStore.get() });
|
|
39
|
-
};
|
|
40
|
-
return {
|
|
41
|
-
...baseStore,
|
|
42
|
-
asObservable,
|
|
43
|
-
asSignal
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
get(key, init) {
|
|
47
|
-
return this.zuno.get(key, init);
|
|
48
|
-
}
|
|
49
|
-
set(key, next, init) {
|
|
50
|
-
return this.zuno.set(key, next, init);
|
|
51
|
-
}
|
|
52
|
-
mutate(key, intent) {
|
|
53
|
-
return this.zuno.mutate(key, intent);
|
|
54
|
-
}
|
|
55
|
-
snapshot() {
|
|
56
|
-
return this.zuno.universe.snapshot();
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
function provideZuno(options = {}) {
|
|
60
|
-
return makeEnvironmentProviders([
|
|
61
|
-
{ provide: ZUNO_OPTIONS, useValue: options },
|
|
62
|
-
ZunoService
|
|
63
|
-
]);
|
|
64
|
-
}
|
|
65
|
-
export {
|
|
66
|
-
ZUNO_OPTIONS,
|
|
67
|
-
ZunoService,
|
|
68
|
-
provideZuno
|
|
69
|
-
};
|
|
70
|
-
//# sourceMappingURL=index.mjs.map
|
|
File without changes
|