patron-oop 1.43.0 → 1.44.1
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,15 @@
|
|
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
|
+
### [1.44.1](https://github.com/kosukhin/patron/compare/v1.44.0...v1.44.1) (2025-03-22)
|
6
|
+
|
7
|
+
## [1.44.0](https://github.com/kosukhin/patron/compare/v1.43.0...v1.44.0) (2025-03-22)
|
8
|
+
|
9
|
+
|
10
|
+
### Features
|
11
|
+
|
12
|
+
* **36-issue:** sourceOnce added ([b2c0178](https://github.com/kosukhin/patron/commit/b2c017881876ec059acd58b1c750b44a6f2f617f))
|
13
|
+
|
5
14
|
## [1.43.0](https://github.com/kosukhin/patron/compare/v1.42.1...v1.43.0) (2025-03-22)
|
6
15
|
|
7
16
|
|
package/package.json
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
import { expect, test, vi } from "vitest";
|
2
|
+
import { SourceOnce } from "./SourceOnce";
|
3
|
+
|
4
|
+
test("SourceOnce.notcalled.test", () => {
|
5
|
+
const source = new SourceOnce();
|
6
|
+
const guestNotCalled = vi.fn();
|
7
|
+
source.value(guestNotCalled);
|
8
|
+
expect(guestNotCalled).not.toHaveBeenCalled();
|
9
|
+
source.give(111);
|
10
|
+
source.value((v) => {
|
11
|
+
expect(v).toBe(111);
|
12
|
+
});
|
13
|
+
});
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { PatronPool } from "../Patron/PatronPool";
|
2
|
+
import { GuestType } from "../Guest/Guest";
|
3
|
+
import { value } from "../Guest/GuestAware";
|
4
|
+
import { SourceType } from "../Source/Source";
|
5
|
+
import { SourceEmpty } from "../Source/SourceEmpty";
|
6
|
+
|
7
|
+
/**
|
8
|
+
* @url https://kosukhin.github.io/patron.site/#/source/source-once
|
9
|
+
*/
|
10
|
+
export class SourceOnce<T> implements SourceType<T> {
|
11
|
+
private source = new SourceEmpty<T>();
|
12
|
+
private isFilled = false;
|
13
|
+
|
14
|
+
public constructor(initialValue?: T) {
|
15
|
+
if (initialValue !== undefined) {
|
16
|
+
this.isFilled = true;
|
17
|
+
this.source.give(initialValue);
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
public value(guest: GuestType<T>) {
|
22
|
+
value(this.source, guest);
|
23
|
+
return this;
|
24
|
+
}
|
25
|
+
|
26
|
+
public give(value: T): this {
|
27
|
+
if (!this.isFilled) {
|
28
|
+
this.isFilled = true;
|
29
|
+
this.source.give(value);
|
30
|
+
}
|
31
|
+
return this;
|
32
|
+
}
|
33
|
+
|
34
|
+
public pool(): PatronPool<T> {
|
35
|
+
return this.source.pool();
|
36
|
+
}
|
37
|
+
}
|