-
Notifications
You must be signed in to change notification settings - Fork 190
Add Type declaration file #57
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
46f812b
typing file skeleton
HerringtonDarkholme cf715ba
add initial typing
HerringtonDarkholme 0d328e1
add type tests
HerringtonDarkholme f4d2c09
update package.json
HerringtonDarkholme 46e63c2
address code review and improve types
HerringtonDarkholme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
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[] | ||
observableMethods?: string[] | Record<string, string> | ||
} | ||
} | ||
|
||
export interface WatchObservable<T> { | ||
newValue: T | ||
oldValue: T | ||
} | ||
declare module "vue/types/vue" { | ||
interface Vue { | ||
$observables: Observables; | ||
$watchAsObservable(expr: string, options?: WatchOptions): Observable<WatchObservable<any>> | ||
$watchAsObservable<T>(fn: (this: this) => T, options?: WatchOptions): Observable<WatchObservable<T>> | ||
$eventToObservable(event: string): Observable<{name: string, msg: any}> | ||
$subscribeTo<T>( | ||
observable: Observable<T>, | ||
next: (t: T) => void, | ||
error?: (e: any) => void, | ||
complete?: () => void): void | ||
$fromDOMEvent(selector: string | null, event: string): Observable<Event> | ||
$createObservableMethod(methodName: string): Observable<any> | ||
} | ||
} | ||
|
||
export declare function install(V: typeof Vue): void |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
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({ | ||
mounted () { | ||
this.$subscribeTo(Rx.Observable.interval(1000), function (count) { | ||
console.log(count) | ||
}) | ||
} | ||
}) | ||
|
||
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') | ||
} | ||
} | ||
}) | ||
|
||
var vm = new Vue({ | ||
subscriptions () { | ||
return { | ||
// requires `share` operator | ||
formData: this.$createObservableMethod('submitHandler') | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "vue-rx", | ||
"main": "index.d.ts" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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