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