本文整理匯總了TypeScript中@reactivex/rxjs.Observable.create方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable.create方法的具體用法?TypeScript Observable.create怎麽用?TypeScript Observable.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@reactivex/rxjs.Observable
的用法示例。
在下文中一共展示了Observable.create方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: handleFilterFileSelection
private handleFilterFileSelection(state:WordlistFormState, file:File, target:string):Rx.Observable<FilterEditorData> {
return Rx.Observable.create((observer:Rx.Observer<any>) => {
const fr = new FileReader();
fr.onload = (evt:any) => { // TODO TypeScript seems to have no type for this
observer.next(evt.target.result);
observer.complete();
};
fr.readAsText(file);
}).concatMap(
(data) => {
return Rx.Observable.of({
target: target,
data: data,
fileName: file.name
});
}
);
}
示例2: login
/**
* login on Relution
* @link [relution-sdk](https://github.com/relution-io/relution-sdk)
*/
login(serverModel: ServerModelRc, force?: boolean): Observable<{ user: Relution.security.User }> {
Relution.init({
serverUrl: serverModel.serverUrl,
application: 'studio'
});
if (!force) {
let currentUser: Relution.security.User = Relution.security.getCurrentUser();
if (currentUser) {
return Observable.create((observer: any) => {
observer.next({
user: currentUser
});
observer.complete();
});
}
}
return Observable.fromPromise(Relution.web.login({
userName: serverModel.userName,
password: serverModel.password
}, serverModel));
}
示例3: return
export function createHTTPContext$<Observable> (port: number, logger: HTTPLogger, transport: HTTPTransport) {
const httpContext$ = Observable.create((observer: Observer<HTTPContext>) => {
const server = transport.createServer(
(request: HTTPRequest, response: HTTPResponse) => {
logger.info(`${request.method} ${request.url}`)
const incoming: HTTPContext = {
request,
response
}
observer.next(incoming)
})
server.listen(port)
logger.info(`Listening at port ${port}`)
return () => {
server.close()
}
}).publish().refCount(1)
return httpContext$
}
示例4:
/**
* @author happygrammer
*/
import * as Rx from "@reactivex/rxjs";
const hello$ = Rx.Observable.create(function (observer) {
observer.next("a");
observer.next("b");
});
const subscribeHello = hello$.map(val => val + val).subscribe(val => console.log(val));
示例5: require
import api from '../../api/index';
var axios = require('axios');
var Rx = require('@reactivex/rxjs');
import * as $ from 'jquery';
const midCol:JQuery<HTMLElement> = $('.mid-col')
const init = Rx.Observable.create(observer => {
}).subscribe()
示例6: require
import api from '../../api/index';
var axios = require('axios');
var Rx = require('@reactivex/rxjs');
import * as $ from 'jquery';
const path:string = window.location.pathname;
const arr:Array<string> = path.split('/');
const fileName = arr[arr.length - 1];
const midCol:JQuery<HTMLElement> = $('.mid-col')
const init = Rx.Observable.create(observer => {
api.getPage({md:fileName}).then(res => {
observer.next(res)
observer.complete()
}).catch(err=>{
observer.error(err)
})
})
init.do(res=>{
midCol.append(res)
}).subscribe()
示例7: showList
const obj:GetBlogList = {
ctoken:'123456',
currentPage:currentPage
}
const $past = Rx.Observable.fromEvent(past, 'click')
const $future = Rx.Observable.fromEvent(future, 'click')
const $search = Rx.Observable.fromEvent(search, 'keyup')
const init = Rx.Observable.create(observer => {
api.getBlogList(obj).then(res => {
observer.next(res)
observer.complete()
}).catch(err=>{
observer.error(err)
})
})
const search$ = $search
.map((e) => $(e.target).val())
.map(esSearch)
const past$ = $past.do(()=>{
console.log(currentPage)
if(currentPage>1){
currentPage = currentPage -1;
showList(blogList[0], currentPage)
}else{
console.log('already first')
}