當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Subject.create方法代碼示例

本文整理匯總了TypeScript中rxjs/Subject.Subject.create方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Subject.create方法的具體用法?TypeScript Subject.create怎麽用?TypeScript Subject.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rxjs/Subject.Subject的用法示例。


在下文中一共展示了Subject.create方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getTalks

 getTalks(): Observable<TalkModel> {
     const subject: Subject<TalkModel> = Subject.create();
     if(!this.talks) {
         this.get('assets/talks.json').subscribe((talks: Array<TalkModel>) => {
             this.talks = talks;
             talks.forEach((talk: TalkModel) => subject.next(talk));
             subject.complete();
         });
     } else {
         setTimeout(() => {
             this.talks.forEach((talk: TalkModel) => subject.next(talk));
             subject.complete();
         });
     }
     return subject;
 }
開發者ID:manland,項目名稱:angular2-bien-ou-pas-bien,代碼行數:16,代碼來源:Server.ts

示例2: constructor

 constructor (private store: Store<any>) {
   const ws = new WebSocket(`wss://api.wka.se/mediat/`);
   const observable = Observable.create(
     (obs: Observer<MessageEvent>) => {
       ws.onmessage = obs.next.bind(obs);
       ws.onerror = obs.error.bind(obs);
       ws.onclose = obs.complete.bind(obs);
       return ws.close.bind(ws);
     }
   );
   const observer = {
     next: (data: Object) => {
       if (ws.readyState === WebSocket.OPEN) {
         ws.send(JSON.stringify(data));
       }
     },
   };
   this.socket = Subject.create(observer, observable);
   this.receive().subscribe(store)
 }
開發者ID:penmark,項目名稱:mediat-frontend,代碼行數:20,代碼來源:socket.service.ts

示例3: create

    private create(url): Subject<MessageEvent> {
        let ws = new WebSocket(url);

        let observable = Observable.create((obs: Observer<MessageEvent>) => {
            ws.onmessage = obs.next.bind(obs);
            ws.onerror = obs.error.bind(obs);
            ws.onclose = obs.complete.bind(obs);

            return ws.close.bind(ws);
        });

        let observer = {
            next: (data: Object) => {
                if (ws.readyState === WebSocket.OPEN) {
                    ws.send(JSON.stringify(data));
                }
            },
        };

        return Subject.create(observer, observable);
    }
開發者ID:dahang,項目名稱:angular2-websocket-webrtc-RP,代碼行數:21,代碼來源:websocket.service.ts

示例4: constructor

    constructor() {
        this._ws = new WebSocket(`ws://echo.websocket.org`);

        // lets set up an observable so we can subscribe to events from the server
        let observable = Observable.create((obs: Observer<any>) => {
            this._ws.onmessage = obs.next.bind(obs)
            
            return this._ws.close.bind(this._ws);
        });

        let observer = {
            next: (data: Object) => {
                console.log('do nothing')
            },
        };
        
        this.stream = Subject.create(observer, observable.share());
        
        setTimeout(function() {
            this._ws.send(JSON.stringify('some value'))
        }.bind(this), 1000);
    }
開發者ID:matthewdaniel,項目名稱:angular2-ie10-bug,代碼行數:22,代碼來源:Test.ts

示例5: constructor

	constructor() {

		this.selectedCard = Subject.create();
		this.selectedCard.subscribe((layout: ISelectedCard) => {
			this.morning.setSelected(false);
			this.day.setSelected(false);
			this.evening.setSelected(false);
			this.night.setSelected(false);

			this.hideForecastsExcept(layout.cardName);

			layout.card.animate({
				translate: { x: 0, y: 0 },
				duration: 300,
				curve: AnimationCurve.linear,
			});

			this.handleCardForecastPosistion(layout);
			this.moveWeatherIcon(layout);

			this.previousCard = layout;
		});
	}
開發者ID:eeandrew,項目名稱:nativescript-weather,代碼行數:23,代碼來源:positioning.service.ts

示例6: describe

describe('AuthGuard', () => {
  beforeEachProviders(() => [
    AuthGuard,
    provide(AuthenticationService, {useClass: MockAuthService}),
    provide(Router, {useClass: MockRouter})
  ]);

  let guard: AuthGuard;
  let authService: AuthenticationService;
  let authObs = Subject.create();

  beforeEach(inject([AuthenticationService], (_authService) => {
    authService = _authService;
    spyOn(authService, 'authenticationStream').and.returnValue(authObs);

  }));

  beforeEach(inject([AuthGuard, AuthenticationService], (_guard) => {
    guard = _guard;
  }));

  it('should return true if authenticated', () => {
    authObs.next(true);

    let result = guard.canActivate();

    expect(result).toBeTruthy();
  });

  it('should return false if not authenticated', () => {
    authObs.next(false);

    let result = guard.canActivate();

    expect(result).toBeFalsy();
  });
});
開發者ID:bryant-pham,項目名稱:brograder,代碼行數:37,代碼來源:auth.guard.spec.ts

示例7: createWebSocket

 private createWebSocket(basePath: string, name: string, pName: string): Subject<MessageEvent | Heartbeat> {
   let url = `${basePath}/${name}`;
   if (pName.length > 0) {
     url += `?name=${pName}`;
   }
   const socket = new WebSocket(url);
   const observable = Observable.create(
     (observer: Observer<MessageEvent>) => {
       socket.onmessage = observer.next.bind(observer);
       socket.onerror = observer.error.bind(observer);
       socket.onclose = observer.complete.bind(observer);
       return socket.close.bind(socket);
     }
   );
   const observer = {
     next: (data: Object) => {
       if (socket.readyState === WebSocket.OPEN) {
         socket.send(JSON.stringify(data));
       }
     }
   };
   this._socket = socket;
   return Subject.create(observer, observable);
 }
開發者ID:cinovo,項目名稱:cloudconductor-server,代碼行數:24,代碼來源:websocket.service.ts

示例8: constructor

 constructor() {
   this.subject = Subject.create();
 }
開發者ID:tygern,項目名稱:hudson,代碼行數:3,代碼來源:fixtures.component.spec.ts

示例9: function

	impl: function(context,pipe) {
		var subject = new Subject();
		return Subject.create(x=>subject.next(x),pipe().$pipe(subject))
	}
開發者ID:ArtwareSoft,項目名稱:jbart5-ng,代碼行數:4,代碼來源:jb-rx.ts


注:本文中的rxjs/Subject.Subject.create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。