本文整理匯總了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))
}