silentium-components 0.0.48 → 0.0.49

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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.0.49](https://github.com/silentium-lab/silentium-components/compare/v0.0.48...v0.0.49) (2025-09-07)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **main:** part component ([92ea425](https://github.com/silentium-lab/silentium-components/commit/92ea425c760603fd26ae887b124b96f4b74fdb7d))
11
+
5
12
  ### [0.0.48](https://github.com/silentium-lab/silentium-components/compare/v0.0.47...v0.0.48) (2025-09-06)
6
13
 
7
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "silentium-components",
3
- "version": "0.0.48",
3
+ "version": "0.0.49",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/silentium-components.js",
@@ -0,0 +1,19 @@
1
+ import { From, Late, SharedSource } from "silentium";
2
+ import { Part } from "../behaviors/Part";
3
+ import { expect, test, vi } from "vitest";
4
+
5
+ test("Part.test", () => {
6
+ const recordSrc = new SharedSource(
7
+ new Late({
8
+ name: "Peter",
9
+ surname: "Parker",
10
+ }),
11
+ );
12
+ const nameSrc = new Part<string>(recordSrc, "name");
13
+ const g = vi.fn();
14
+ recordSrc.value(new From(g));
15
+ expect(g).toHaveBeenLastCalledWith({ name: "Peter", surname: "Parker" });
16
+
17
+ nameSrc.give("Shmiter");
18
+ expect(g).toHaveBeenLastCalledWith({ name: "Shmiter", surname: "Parker" });
19
+ });
@@ -0,0 +1,64 @@
1
+ import {
2
+ All,
3
+ From,
4
+ InformationType,
5
+ MaybeInformationType,
6
+ MbInfo,
7
+ OwnerType,
8
+ SourceType,
9
+ TheInformation,
10
+ } from "silentium";
11
+ import { Sync } from "../behaviors/Sync";
12
+
13
+ /**
14
+ * Return source of record path
15
+ * https://silentium-lab.github.io/silentium-components/#/behaviors/path
16
+ */
17
+ export class Part<
18
+ R,
19
+ T extends Record<string, unknown> | Array<unknown> = any,
20
+ K extends string = any,
21
+ >
22
+ extends TheInformation<R>
23
+ implements OwnerType<R>
24
+ {
25
+ private baseSync: Sync<T>;
26
+ private keySync: Sync<string>;
27
+ private keySrc: InformationType<string>;
28
+
29
+ public constructor(
30
+ private baseSrc: SourceType<T>,
31
+ private key: MaybeInformationType<K>,
32
+ ) {
33
+ super(baseSrc);
34
+ this.keySrc = new MbInfo(key);
35
+ this.baseSync = new Sync(baseSrc);
36
+ this.keySync = new Sync(this.keySrc);
37
+ }
38
+
39
+ public value(o: OwnerType<R>): this {
40
+ const allSrc = new All(this.baseSrc, this.keySrc).value(
41
+ new From(([base, key]) => {
42
+ const keyChunks = key.split(".");
43
+ let value: unknown = base;
44
+ keyChunks.forEach((keyChunk) => {
45
+ value = (value as Record<string, unknown>)[keyChunk];
46
+ });
47
+
48
+ if (value !== undefined && value !== base) {
49
+ o.give(value as R);
50
+ }
51
+ }),
52
+ );
53
+ this.addDep(allSrc);
54
+ return this;
55
+ }
56
+
57
+ public give(value: R): this {
58
+ this.baseSrc.give({
59
+ ...this.baseSync.valueSync(),
60
+ [this.keySync.valueSync()]: value,
61
+ });
62
+ return this;
63
+ }
64
+ }