-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvertOperator.js
35 lines (33 loc) · 961 Bytes
/
convertOperator.js
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
// @ts-check
import { Observable } from "rxjs"
/**
* Because the DSL currently does not have support to specify the format
* of the operator, this exists solely for the purpose of evaluating the
* first argument.
*
* @template T
* @param {(...args: any[]) => Observable<T>} operator
*/
export default function convertOperator (operator) {
return (...args) => {
if (typeof args[0] === 'function')
args[0] = args[0]()
return operator(...args)
}
}
/**
* Because the DSL currently does not have support to specify the format
* of the operator, this exists solely for the purpose of evaluating the
* first argument.
*
* @template T
* @param {T} operators
* @returns {T}
*/
export function convertOperators (operators) {
// @ts-ignore I promise this is correct.
return Object.keys(operators).reduce((acc, key) => {
acc[key] = convertOperator(operators[key])
return acc
}, {})
}