當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。