@@ -8,71 +8,106 @@ import type { derived } from 'vs/base/common/observableImpl/derived';
8
8
import { getLogger } from 'vs/base/common/observableImpl/logging' ;
9
9
10
10
export interface IObservable < T , TChange = unknown > {
11
- readonly TChange : TChange ;
12
-
13
11
/**
14
- * Reads the current value.
12
+ * Returns the current value.
15
13
*
16
- * Must not be called from {@link IObserver.handleChange}.
14
+ * Calls {@link IObserver.handleChange} if the observable notices that the value changed.
15
+ * Must not be called from {@link IObserver.handleChange}!
17
16
*/
18
17
get ( ) : T ;
19
18
19
+ /**
20
+ * Forces the observable to check for and report changes.
21
+ *
22
+ * Has the same effect as calling {@link IObservable.get}, but does not force the observable
23
+ * to actually construct the value, e.g. if change deltas are used.
24
+ * Calls {@link IObserver.handleChange} if the observable notices that the value changed.
25
+ * Must not be called from {@link IObserver.handleChange}!
26
+ */
20
27
reportChanges ( ) : void ;
21
28
29
+ /**
30
+ * Adds the observer to the set of subscribed observers.
31
+ * This method is idempotent.
32
+ */
22
33
addObserver ( observer : IObserver ) : void ;
34
+
35
+ /**
36
+ * Removes the observer from the set of subscribed observers.
37
+ * This method is idempotent.
38
+ */
23
39
removeObserver ( observer : IObserver ) : void ;
24
40
25
41
/**
26
- * Subscribes the reader to this observable and returns the current value of this observable.
42
+ * Reads the current value and subscribes to this observable.
43
+ *
44
+ * Just calls {@link IReader.readObservable} if a reader is given, otherwise {@link IObservable.get}
45
+ * (see {@link ConvenientObservable.read}).
27
46
*/
28
47
read ( reader : IReader | undefined ) : T ;
29
48
49
+ /**
50
+ * Creates a derived observable that depends on this observable.
51
+ * Use the reader to read other observables
52
+ * (see {@link ConvenientObservable.map}).
53
+ */
30
54
map < TNew > ( fn : ( value : T , reader : IReader ) => TNew ) : IObservable < TNew > ;
31
55
56
+ /**
57
+ * A human-readable name for debugging purposes.
58
+ */
32
59
readonly debugName : string ;
33
60
34
- /*get isPossiblyStale(): boolean;
35
-
36
- get isUpdating(): boolean;*/
61
+ /**
62
+ * This property captures the type of the change object. Do not use it at runtime!
63
+ */
64
+ readonly TChange : TChange ;
37
65
}
38
66
39
67
export interface IReader {
40
68
/**
41
69
* Reads the value of an observable and subscribes to it.
42
- *
43
- * Is called by {@link IObservable.read}.
44
70
*/
45
71
readObservable < T > ( observable : IObservable < T , any > ) : T ;
46
72
}
47
73
74
+ /**
75
+ * Represents an observer that can be subscribed to an observable.
76
+ *
77
+ * If an observer is subscribed to an observable and that observable didn't signal
78
+ * a change through one of the observer methods, the observer can assume that the
79
+ * observable didn't change.
80
+ * If an observable reported a possible change, {@link IObservable.reportChanges} forces
81
+ * the observable to report an actual change if there was one.
82
+ */
48
83
export interface IObserver {
49
84
/**
50
- * Indicates that calling {@link IObservable.get} might return a different value and the observable is in updating mode.
51
- * Must not be called when the given observable has already been reported to be in updating mode.
85
+ * Signals that the given observable might have changed and a transaction potentially modifying that observable started.
86
+ * Before the given observable can call this method again, is must call {@link IObserver.endUpdate}.
87
+ *
88
+ * The method {@link IObservable.reportChanges} can be used to force the observable to report the changes.
52
89
*/
53
90
beginUpdate < T > ( observable : IObservable < T > ) : void ;
54
91
55
92
/**
56
- * Is called by a subscribed observable when it leaves updating mode and it doesn't expect changes anymore,
57
- * i.e. when a transaction for that observable is over.
58
- *
59
- * Call {@link IObservable.reportChanges} to learn about possible changes (if they weren't reported yet).
93
+ * Signals that the transaction that potentially modified the given observable ended.
60
94
*/
61
95
endUpdate < T > ( observable : IObservable < T > ) : void ;
62
96
97
+ /**
98
+ * Signals that the given observable might have changed.
99
+ * The method {@link IObservable.reportChanges} can be used to force the observable to report the changes.
100
+ *
101
+ * Implementations must not call into other observables, as they might not have received this event yet!
102
+ * The change should be processed lazily or in {@link IObserver.endUpdate}.
103
+ */
63
104
handlePossibleChange < T > ( observable : IObservable < T > ) : void ;
64
105
65
106
/**
66
- * Is called by a subscribed observable immediately after it notices a change.
67
- *
68
- * When {@link IObservable.get} is called two times and no change was reported before the second call returns,
69
- * there has been no change in between the two calls for that observable.
70
- *
71
- * If the update counter is zero for a subscribed observable and calling {@link IObservable.get} didn't trigger a change,
72
- * subsequent calls to {@link IObservable.get} don't trigger a change either until the update counter is increased again.
107
+ * Signals that the given observable changed.
73
108
*
74
- * Implementations must not call into other observables!
75
- * The change should be processed when all observed observables settled .
109
+ * Implementations must not call into other observables, as they might not have received this event yet !
110
+ * The change should be processed lazily or in { @link IObserver.endUpdate} .
76
111
*/
77
112
handleChange < T , TChange > ( observable : IObservable < T , TChange > , change : TChange ) : void ;
78
113
}
@@ -83,13 +118,10 @@ export interface ISettable<T, TChange = void> {
83
118
84
119
export interface ITransaction {
85
120
/**
86
- * Calls ` Observer.beginUpdate` immediately
87
- * and ` Observer.endUpdate` when the transaction is complete .
121
+ * Calls { @link Observer.beginUpdate} immediately
122
+ * and { @link Observer.endUpdate} when the transaction ends .
88
123
*/
89
- updateObserver (
90
- observer : IObserver ,
91
- observable : IObservable < any , any >
92
- ) : void ;
124
+ updateObserver ( observer : IObserver , observable : IObservable < any , any > ) : void ;
93
125
}
94
126
95
127
let _derived : typeof derived ;
0 commit comments