本文整理匯總了TypeScript中rxjs.Subject.subscribe方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Subject.subscribe方法的具體用法?TypeScript Subject.subscribe怎麽用?TypeScript Subject.subscribe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rxjs.Subject
的用法示例。
在下文中一共展示了Subject.subscribe方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it("should translate Observable implementation not from RxJS into RxJS Observables", (done) => {
/* tslint:enable:max-line-length */
const sub1 = new Subject<number>();
const sub2 = new Subject<number>();
const myObs1 = {
subscribe(a : () => void, b : () => void, c : () => {}) {
sub1.subscribe(a, b, c);
return null;
},
};
const myObs2 = {
subscribe(a : () => void, b : () => void, c : () => {}) {
sub2.subscribe(a, b, c);
return null;
},
};
const rxObs1 = castToObservable(myObs1);
const rxObs2 = castToObservable(myObs2);
let itemFromObs1 = 0;
let itemFromObs2 = 0;
rxObs1.subscribe(
(num) => {
switch (itemFromObs1++) {
case 0:
expect(num).toBe(1);
break;
case 1:
expect(num).toBe(12);
break;
case 2:
expect(num).toBe(5);
break;
default:
throw new Error("Invalid item received");
}
},
(err : Error) => {
expect(err.message).toBe("ffob");
expect(itemFromObs1).toBe(3);
rxObs2.subscribe(
() => { itemFromObs2++; },
noop,
() => {
expect(itemFromObs2).toBe(0);
done();
}
);
}
);
sub1.next(1);
sub1.next(12);
sub1.next(5);
sub2.complete();
sub1.error(new Error("ffob"));
});
示例2: it
it('should create a request command with message-id', () => {
service.connect();
mockObs.subscribe(value => {
expect(value).toEqual({ 'message-id': '2', 'request-type': 'test' });
});
service.requestCommand(service.requestTask('test'));
});
示例3: Subscription
export const initWorker = (provisioning: Provisioning) => {
const subject = new Subject<WorkerPayload>();
const subscription = new Subscription();
const post = process.env.RMVI_TEST
? ({ type, payload }: { type: string; payload: any }) => {
global['RECEIVE_WORKER_MESSAGE']({ type, payload });
}
: typeof postMessage === 'function'
? ({ type, payload }: { type: string; payload: any }) => {
postMessage({ type, payload });
}
: () => {};
if (typeof Worker === 'function') {
onmessage = e => {
const { data } = e;
subject.next(data);
};
}
const publisher = provisioning.getPublisher();
subscription.add(
subject.subscribe(({ type, payload }) => {
switch (type) {
case WorkerReceiveEventType.DISPATCH:
publisher(payload.type, payload.payload);
provisioning.emitAsync(() =>
post({ type: WorkerPostEventType.DISPATCHED, payload }),
);
break;
case WorkerReceiveEventType.INITIALIZE:
provisioning.prepare(payload);
provisioning.subscribe((state, isInitial) => {
if (isInitial) {
post({
type: WorkerPostEventType.INITIALIZED,
payload: state.view,
});
} else {
post({ type: WorkerPostEventType.UPDATE, payload: state.view });
}
}, true);
break;
case WorkerReceiveEventType.EXIT:
publisher.unsubscribe();
provisioning.dispose();
subscription.unsubscribe();
break;
default:
return;
}
}),
);
return subject;
};
示例4: constructor
constructor(cookie: CookieDriver, signoutAction: Subject<void>) {
this._cookie = cookie;
const disposer = new Subscription();
this._disposer = disposer;
disposer.add(signoutAction.subscribe(() => {
this.removeToken();
}));
}
示例5: subject
subject() {
let subject$ = new Subject();
interval(300).pipe(
take(5)
).subscribe(subject$); // Now subject behaves as observable
// Every time the interval send values to the Subject, the Subject send this values to all his observers
subject$.subscribe(val => console.log(`First subject: ${val}`)); // 0, 1, 2, 3, 4
setTimeout(() => {
subject$.subscribe(val => console.log(`Second subject: ${val}`)) // 3, 4
}, 1000);
}
示例6: ngOnInit
public ngOnInit(): void {
this.addBlock$.subscribe(block => {
this.editor.runCommand(
insertImage({
src: "https://media.giphy.com/media/sIIhZliB2McAo/giphy.gif",
}),
)
})
this.editor.updateState(this.doc)
this.editor.stateChange.subscribe(this.save)
}
示例7: Observable
return new Observable(observer => {
subject.subscribe(observer).add(() => {
if (
!isUnsubscribed() &&
responseObserver &&
!responseObserver.complete &&
!responseObserver.observer.closed
) {
sendNotification(ABORT_REQUEST_METHOD, [id])
}
})
})
示例8: constructor
protected constructor(config: DynamicFormValueControlModelConfig<T>, layout?: DynamicFormControlLayout) {
super(config, layout);
this.additional = typeof config.additional === "object" && config.additional !== null ? config.additional : null;
this.hint = config.hint || null;
this.required = typeof config.required === "boolean" ? config.required : false;
this.tabIndex = config.tabIndex || null;
this.value = config.value !== null && config.value !== undefined ? config.value : null;
this.valueUpdates = new Subject<T>();
this.valueUpdates.subscribe((value: T) => this.value = value);
}
示例9: test
test('Handle bowlingLine with Delete', function() {
const testDeleter = { type: 'DELETE', payload: 7 };
function mockMakeBowlingLine(id, name) {
return {DOM: O.of(div()), Delete: O.of(testDeleter)};
}
const mockLineAction$ = new Subject();
mockLineAction$.subscribe(
x => expect(x).toEqual(testDeleter)
);
model(O.from([
{type: 'ADD ITEM', payload: 'Andrew'}
]), mockMakeBowlingLine, mockLineAction$);
});
示例10: openLogin
/**
* Opens a dialog to choose a file to upload.
* @param actionName Name of the action to show in the title
* @param title Title for the dialog
* @returns Information about the chosen file(s)
*/
openLogin(actionName: string, title: string): Observable<string> {
const logged = new Subject<string>();
logged.subscribe({
complete: this.close.bind(this)
});
const data: LoginDialogComponentData = {
title,
actionName,
logged
};
this.openLoginDialog(data, 'adf-login-dialog', '630px');
return logged;
}