本文整理汇总了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')
}