本文整理汇总了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;
}
示例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)
}
示例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);
}
示例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);
}
示例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;
});
}
示例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();
});
});
示例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);
}
示例8: constructor
constructor() {
this.subject = Subject.create();
}
示例9: function
impl: function(context,pipe) {
var subject = new Subject();
return Subject.create(x=>subject.next(x),pipe().$pipe(subject))
}