当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Observable.create方法代码示例

本文整理汇总了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
                });
            }
        );
    }
开发者ID:czcorpus,项目名称:kontext,代码行数:19,代码来源:form.ts

示例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));
  }
开发者ID:relution-io,项目名称:relution-cli,代码行数:26,代码来源:RelutionSDK.ts

示例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$
}
开发者ID:mariuslundgard,项目名称:cycle-http-server-driver,代码行数:24,代码来源:http-server-driver.ts

示例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));
开发者ID:chun4foryou,项目名称:develop,代码行数:11,代码来源:create.ts

示例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()
开发者ID:gatinul,项目名称:blog,代码行数:11,代码来源:search.ts

示例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()
开发者ID:gatinul,项目名称:blog,代码行数:23,代码来源:pageList.ts

示例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')
  }
开发者ID:gatinul,项目名称:blog,代码行数:31,代码来源:blogList.ts


注:本文中的@reactivex/rxjs.Observable.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。