1
1
import { Rx , hasRx , warn } from '../util'
2
2
3
3
/**
4
- * @name vue .prototype.$createObservableFunction
4
+ * @name Vue .prototype.$createObservableFunction
5
5
* @description Creates an observable from a given function name.
6
6
* @param {String } functionName Function name
7
7
* @param {Boolean } [passContext] Append the call context at the end of emit data?
@@ -23,7 +23,7 @@ export default function createObservableFunction (functionName, passContext) {
23
23
return
24
24
}
25
25
26
- if ( vm [ functionName ] !== undefined ) {
26
+ if ( vm [ functionName ] !== undefined ) {
27
27
warn (
28
28
'Potential bug: ' +
29
29
`Method ${ functionName } already defined on vm and has been overwritten by $createObservableFunction.` +
@@ -32,26 +32,25 @@ export default function createObservableFunction (functionName, passContext) {
32
32
)
33
33
}
34
34
35
- let creator = function ( observer ) {
36
-
35
+ const creator = function ( observer ) {
37
36
vm [ functionName ] = function ( ) {
38
- let args = Array . from ( arguments ) ;
39
- if ( passContext ) {
40
- args . push ( this ) ;
41
- observer . next ( args ) ;
42
- } else {
37
+ const args = Array . from ( arguments )
38
+ if ( passContext ) {
39
+ args . push ( this )
40
+ observer . next ( args )
41
+ } else {
43
42
if ( args . length <= 1 ) {
44
- observer . next ( args [ 0 ] ) ;
43
+ observer . next ( args [ 0 ] )
45
44
} else {
46
- observer . next ( args ) ;
45
+ observer . next ( args )
47
46
}
48
47
}
49
- } ;
50
- return function ( ) {
51
- delete vm [ functionName ] ;
52
- } ;
53
- } ;
48
+ }
49
+ return function ( ) {
50
+ delete vm [ functionName ]
51
+ }
52
+ }
54
53
55
- //Must be a hot stream otherwise function context may overwrite over and over again
56
- return Rx . Observable . create ( creator ) . share ( ) ;
54
+ // Must be a hot stream otherwise function context may overwrite over and over again
55
+ return Rx . Observable . create ( creator ) . share ( )
57
56
}
0 commit comments