当前位置: 首页>>代码示例>>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;未经允许,请勿转载。