本文整理匯總了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
};
}
示例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();
})
}
示例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;
}
示例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 || '');
});
}
示例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);
}
示例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]);
});
示例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 );
}
示例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);
}
示例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 + '* : ';
}
});
})
}
示例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;
});
}