This repository has been archived by the owner on Sep 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
peer.ts
72 lines (67 loc) · 2.4 KB
/
peer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { CxAsset, CxEntry, CxTracking, CxValues } from '@proc7ts/context-values';
import { Supply, SupplyPeer } from '@proc7ts/supply';
import { CxBuilder } from './builder';
/**
* Context peer providing assets preceding those from {@link CxBuilder.provide context builder}.
*
* @typeParam TContext - Context type the assets provided for.
*/
export interface CxPeer<TContext extends CxValues = CxValues> extends SupplyPeer {
/**
* The number of {@link CxAsset.Provided.rank asset ranks} this peer contains.
*/
readonly rankCount: number;
/**
* Context peer supply.
*
* Revokes all assets provided by this peer once cut off.
*/
readonly supply: Supply;
/**
* Iterates over particular entry assets in the same order they are provided.
*
* Each asset reported to the given `callback` function until the latter returns `false` or there are no more
* assets.
*
* @param target - Context entry definition target to iterate over assets of.
* @param cache - Target context cache.
* @param callback - Assets callback.
*/
eachAsset<TValue, TAsset>(
target: CxEntry.Target<TValue, TAsset, TContext>,
cache: CxBuilder.Cache,
callback: CxAsset.Callback<TAsset>,
): void;
/**
* Iterates over particular entry assets with the most recent assets iterated first. I.e. in reverse order to the
* order they are provided.
*
* Each asset reported to the given `callback` function until the latter returns `false` or there are no more
* assets.
*
* @param target - Context entry definition target to iterate over assets of.
* @param cache - Target context cache.
* @param callback - Assets callback.
*/
eachRecentAsset<TValue, TAsset>(
target: CxEntry.Target<TValue, TAsset, TContext>,
cache: CxBuilder.Cache,
callback: CxAsset.Callback<TAsset>,
): void;
/**
* Reads assets of particular entry value and start tracking of their additions.
*
* @param target - Context entry definition target to track assets for.
* @param cache - Target context cache.
* @param receiver - A receiver to report existing and added assets to.
* @param tracking - Tracking options.
*
* @returns Assets supply. Stops assets tracking once cut off.
*/
trackAssets<TValue, TAsset>(
target: CxEntry.Target<TValue, TAsset, TContext>,
cache: CxBuilder.Cache,
receiver: CxAsset.Receiver<TAsset>,
tracking?: CxTracking,
): Supply;
}