UNPKG

3.56 kBMarkdownView Raw
1# Deprecated API Methods documentation
2
3All documentation on deprecated methods are moved
4from [main docs](http://kefirjs.github.io/kefir/) to this file.
5
6See also [2.x's version of this document](https://github.com/kefirjs/kefir/blob/v2/deprecated-api-docs.md) containing docs on methods that were removed in 3.0.
7
8
9### `obs.awaiting(otherObs)` [#145](https://github.com/kefirjs/kefir/issues/145)
10
11Returns a property that represents the awaiting status of two observables,
12i.e. answers the question «Has **obs** observable emitted a value since
13the last value from **otherObs** observable has been emitted?».
14
15
16```js
17var foo = Kefir.sequentially(100, [1, 2, 3]);
18var bar = Kefir.sequentially(100, [1, 2, 3]).delay(40);
19var result = foo.awaiting(bar);
20result.log();
21```
22
23```
24> [sequentially.awaiting] <value:current> false
25> [sequentially.awaiting] <value> true
26> [sequentially.awaiting] <value> false
27> [sequentially.awaiting] <value> true
28> [sequentially.awaiting] <value> false
29> [sequentially.awaiting] <value> true
30> [sequentially.awaiting] <value> false
31> [sequentially.awaiting] <end>
32```
33
34```
35foo: ----1----2----3X
36bar: ------1----2----3X
37
38result: f---t-f--t-f--t-fX
39```
40
41
42### `obs.valuesToErrors([handler])` [#149](https://github.com/kefirjs/kefir/issues/149)
43
44Converts values to errors. By default it converts all values to errors,
45but you can specify a custom **handler** function to change that. The **handler**
46function is called with one argument — a value, and must return an object
47with two properties `{convert: Boolean, error: AnyType}`, if **convert** is set
48to true, the specified **error** will be emitted, otherwise the original value
49will be emitted, and the **error** property will be ignored.
50
51```js
52var source = Kefir.sequentially(100, [0, -1, 2, -3]);
53var result = source.valuesToErrors(x => {
54 return {
55 convert: x < 0,
56 error: x * 2
57 };
58});
59result.log();
60```
61
62```
63> [sequentially.valuesToErrors] <value> 0
64> [sequentially.valuesToErrors] <error> -2
65> [sequentially.valuesToErrors] <value> 2
66> [sequentially.valuesToErrors] <error> -6
67> [sequentially.valuesToErrors] <end>
68```
69
70```
71source: ---•---•---•---•X
72 0 -1 2 -3
73result: ---•---e---•---eX
74 0 -2 2 -6
75```
76
77
78### `obs.errorsToValues([handler])` [#149](https://github.com/kefirjs/kefir/issues/149)
79
80Same as valuesToErrors but vice versa.
81
82```js
83var source = Kefir.sequentially(100, [0, -1, 2, -3]).valuesToErrors();
84var result = source.errorsToValues(x => {
85 return {
86 convert: x >= 0,
87 value: x * 2
88 };
89});
90result.log();
91```
92
93```
94> [sequentially.valuesToErrors.errorsToValues] <value> 0
95> [sequentially.valuesToErrors.errorsToValues] <error> -1
96> [sequentially.valuesToErrors.errorsToValues] <value> 4
97> [sequentially.valuesToErrors.errorsToValues] <error> -3
98> [sequentially.valuesToErrors.errorsToValues] <end>
99```
100
101```
102source: ---e---e---e---eX
103 0 -1 2 -3
104result: ---•---e---•---eX
105 0 -1 4 -3
106```
107
108
109### `obs.endOnError()` [#150](https://github.com/kefirjs/kefir/issues/150)
110
111Makes an observable to end on first error.
112
113```js
114var source = Kefir.sequentially(100, [0, -1, 2, -3])
115 .valuesToErrors(x => {
116 return {convert: x < 0, error: x};
117 });
118var result = source.endOnError()
119result.log();
120```
121
122```
123> [sequentially.valuesToErrors.endOnError] <value> 0
124> [sequentially.valuesToErrors.endOnError] <error> -1
125> [sequentially.valuesToErrors.endOnError] <end>
126```
127
128```
129source: ---•---e---•---eX
130 0 -1 2 -3
131result: ---•---eX
132 0 -1
133```