-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Type declaration file #57
Changes from 4 commits
46f812b
cf715ba
0d328e1
f4d2c09
46e63c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Vue = require('vue') | ||
import { WatchOptions } from 'vue' | ||
import { Observable } from 'rxjs/Observable' | ||
|
||
export type Observables = Record<string, Observable<any>> | ||
declare module 'vue/types/options' { | ||
interface ComponentOptions<V extends Vue> { | ||
subscriptions?: Observables | ((this: V) => Observables) | ||
domStreams?: string[] | ||
} | ||
} | ||
|
||
declare module "vue/types/vue" { | ||
interface Vue { | ||
$observables: Observables; | ||
$watchAsObservable(exprOrFn: string | Function, options?: WatchOptions): Observable<any> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can improve this type by using type parameter like $watchAsObservable<T>(fn: (this: this) => T, options?: WatchOptions): Observable<T> There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, returned Observable has a value that is formed of https://github.com/vuejs/vue-rx#watchasobservableexporfn-options |
||
$eventToObservable(event: string): Observable<any> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the returned type is |
||
$subscribeTo<T>( | ||
observable: Observable<T>, | ||
next: (t: T) => void, | ||
error: (e: any) => void, | ||
complete: () => void): void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't https://github.com/vuejs/vue-rx#subscribetoobservable-next-error-complete |
||
$fromDOMEvent(selector: string, event: string): Observable<any> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we can let the return type be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, https://github.com/vuejs/vue-rx/blob/master/src/methods/fromDOMEvent.js#L17 selector only applies to native dom element. |
||
$createObservableMethod(methodName: string): Observable<any> | ||
} | ||
} | ||
|
||
export declare function install(V: typeof Vue): void |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import Vue = require('vue') | ||
import * as VueRX from '../index' | ||
import * as Rx from 'rxjs/Rx' | ||
|
||
Vue.use(VueRX, Rx) | ||
|
||
var vm = new Vue({ | ||
el: '#app', | ||
subscriptions: { | ||
msg: Rx.Observable.interval(100) | ||
} | ||
}) | ||
|
||
vm.$observables.msg.subscribe(msg => console.log(msg)) | ||
|
||
Vue.component('foo', { | ||
subscriptions: function () { | ||
return { | ||
msg: Rx.Observable.interval(100) | ||
} | ||
} | ||
}) | ||
|
||
new Vue({ | ||
domStreams: ['plus$'] | ||
}) | ||
|
||
var vm = new Vue({ | ||
data: { | ||
a: 1 | ||
}, | ||
subscriptions () { | ||
// declaratively map to another property with Rx operators | ||
return { | ||
aPlusOne: this.$watchAsObservable('a') | ||
.pluck('newValue') | ||
.map((a: number) => a + 1) | ||
} | ||
} | ||
}) | ||
|
||
// or produce side effects... | ||
vm.$watchAsObservable('a') | ||
.subscribe( | ||
({ newValue, oldValue }) => console.log('stream value', newValue, oldValue), | ||
err => console.error(err), | ||
() => console.log('complete') | ||
) | ||
|
||
|
||
var vm = new Vue({ | ||
created () { | ||
this.$eventToObservable('customEvent') | ||
.subscribe((event) => console.log(event.name,event.msg)) | ||
} | ||
}) | ||
|
||
var vm = new Vue({ | ||
subscriptions () { | ||
return { | ||
inputValue: this.$fromDOMEvent('input', 'keyup').pluck('target', 'value') | ||
} | ||
} | ||
}) | ||
|
||
var vm = new Vue({ | ||
subscriptions () { | ||
return { | ||
// requires `share` operator | ||
formData: this.$createObservableMethod('submitHandler') | ||
} | ||
} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es5", | ||
"lib": [ | ||
"es5", | ||
"dom", | ||
"es2015.promise", | ||
"es2015.core" | ||
], | ||
"strict": true, | ||
"noEmit": true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es5", | ||
"lib": [ | ||
"es5", | ||
"dom", | ||
"es2015.promise" | ||
], | ||
"strict": true, | ||
"noEmit": true | ||
}, | ||
"include": [ | ||
"*.d.ts" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "vue-rx", | ||
"main": "index.d.ts" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also have
observableMethods
in component options 😉https://github.com/vuejs/vue-rx#createobservablemethodmethodname