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


TypeScript Subject.subscribe方法代碼示例

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


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

示例1: function

export default function(options: CanvasOptions) {
  const write  = new Subject<DragDeltaLog>();
  const clear  = new Subject<any>();
  const scale  = new BehaviorSubject<any>(true);
  const toggle = new Subject<any>();

  const canvas  = options.canvasElement as HTMLCanvasElement;
  const context = canvas.getContext("2d");
  if (context === null) {
    throw new TypeError('unreachable: canvas should be not `null`');
  }

  write.subscribe(writeCanvasTo(context, options.color));
  clear.subscribe(clearCanvasTo(context));

  scale
    .map(() => window.innerWidth)
    .subscribe(attributeAssignOf(canvas, 'width'));
  scale
    .map(() => window.innerHeight)
    .subscribe(attributeAssignOf(canvas, 'height'));

  toggle
    .scan((acc) => !acc, false)
    .map((bool) => bool ? 'false' : 'true')
    .subscribe(attributeAssignOf(canvas, 'aria-hidden'));

  return {
    cvWrite  : write,
    cvClear  : clear,
    cvToggle : toggle,
    cvScale  : scale
  };

}
開發者ID:1000ch,項目名稱:Talkie,代碼行數:35,代碼來源:canvas.ts

示例2: action

export const subjectDebounce = <T>(subject: Subject<T>, dueTime: number, action : (T) => void): void => {

    let sub = subject.debounceTime(dueTime).distinctUntilChanged().subscribe(p => action(p));
    let sub1 = subject.subscribe(null, null, () => {
        sub.unsubscribe();
        sub1.unsubscribe();
    })
}
開發者ID:baio,項目名稱:link-shortener,代碼行數:8,代碼來源:subject-debounce.ts

示例3: Message

 useFactory: (messageService, model) => {
     let subject = new Subject<SharedState>();
     subject.subscribe(m => messageService.reportMessage(
             new Message(MODES[m.mode] + (m.id != undefined
                 ? ` ${model.getProduct(m.id).name}` : "")))
         );
     return subject;       
 }
開發者ID:hieutran106,項目名稱:pro-angular-2ed,代碼行數:8,代碼來源:core.module.ts

示例4: _initSession

 private _initSession() {
   let user = this._deserialize(localStorage.getItem('currentUser'));
   this.currentUser = new BehaviorSubject<Response>(user);
   // persist the user to the local storage
   this.currentUser.subscribe((user) => {
     localStorage.setItem('currentUser', this._serialize(user));
     localStorage.setItem('token', user.token.hash || '');
   });
 }
開發者ID:AdrianPasalega,項目名稱:mean-blueprints-ecommerce,代碼行數:9,代碼來源:auth.service.ts

示例5: global

  protected _model:StoogeModel;       // reference to the global (Singleton) store

 /**
  * Construct a new Flux-style component
  *
  * @return Nothing
  */
  constructor()
  {
    this._model = new StoogeModel();      // even when constructed normally, there will be only one actual instance of the global store

    let subject: Subject<any>      = new Subject<any>();
    let subscription: Subscription = subject.subscribe( (data:Object) => this.__onModelUpdate(data) ); 

    this._model.subscribe(subject);
  }
開發者ID:theAlgorithmist,項目名稱:A2ComponentRouter,代碼行數:16,代碼來源:flux.component.ts

示例6: it

  it('should allow me to use Subject for testing', () => {
    const subject = new Subject<number>();

    const log: number[] = [];
    subject.subscribe(x => {
      log.push(x);
    });

    subject.next(111);
    subject.next(222);
    subject.next(333);

    expect(log).toEqual([111, 222, 333]);
  });
開發者ID:loki2302,項目名稱:html5-experiment,代碼行數:14,代碼來源:rxjs.spec.ts

示例7: subscribe

	// I subscribe to the PopStateEvents for the RetroLocation.
	// --
	// CAUTION: These events will be emitted when the location is changed either manually
	// by the user or programmatically by the RetroLocation service.
	public subscribe(
		onNext: SubscribeHandlers.OnNext, 
		onThrow?: SubscribeHandlers.OnThrow | null,
		onComplete?: SubscribeHandlers.OnComplete | null
		) : Subscription {
		
		var subscription = this.popStateEvents.subscribe({
			next: onNext,
			error: onThrow,
			complete: onComplete
		});

		return( subscription );

	}
開發者ID:bennadel,項目名稱:JavaScript-Demos,代碼行數:19,代碼來源:retro-location.ts

示例8: constructor

    constructor(config: DynamicFormValueControlModelConfig<T>, cls?: ClsConfig) {

        super(config, cls);

        this.asyncValidators = config.asyncValidators || null;
        this.errorMessages = config.errorMessages || null;
        this.hint = config.hint || null;
        this.required = isBoolean(config.required) ? config.required : false;
        this.tabIndex = config.tabIndex || null;
        this.validators = config.validators || null;
        this._value = config.value || null;

        this.valueUpdates = new Subject<T>();
        this.valueUpdates.subscribe((value: T) => this.value = value);
    }
開發者ID:CodeFork,項目名稱:ng2-dynamic-forms,代碼行數:15,代碼來源:dynamic-form-value-control.model.ts

示例9: constructor

 constructor() {
     this.started = new Subject();
     this.output = new Subject();
     
     this.started.subscribe(() => {
         let lineBuffer = '> *' + this.host.alias + '* : ';
         this.process.stdout.on('data', (d) => {
             let data = d.toString();
             lineBuffer += data;
             if (data.indexOf(';') > -1) {
                 this.output.next(lineBuffer);
                 lineBuffer = '> *' + this.host.alias + '* : ';
             }
         });
     })
 }
開發者ID:criticalbh,項目名稱:jmx-slackbot,代碼行數:16,代碼來源:JmxProcess.ts

示例10: 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


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