Skip to content

Instantly share code, notes, and snippets.

/example.ts
Created Dec 6, 2017

Embed
What would you like to do?
import { Injectable } from '@angular/core';
import { Observable, Subject, ConnectableObservable } from 'rxjs/Rx';
import { WSocketService } from './wsocket';
import { List, Map } from 'immutable';
const WS_URL = "ws://0.0.0.0:9000/socket";
export class OneOfMyClasses {
constructor(
readonly a_country?: any,
readonly a_name?: any,
readonly a_surname?: any,
readonly a_sex?: any,
readonly a_discipline?: any
) {}
static fromJson(json: any): OneOfMyClasses {
return new OneOfMyClasses(
json["a_country"].value,
json["a_name"].value,
json["a_surname"].value,
json["a_sex"].value,
json["a_discipline"].value
);
}
}
@Injectable()
export class OneOfMyClassesService {
private observableMap: ConnectableObservable<Map<any, OneOfMyClasses>>;
private observableList: Observable<List<OneOfMyClasses>>;
private subject = new Subject<Map<any, OneOfMyClasses>>();
public messageFromWs: Subject<Message>;
constructor(wsService: WSocketService) {
this.messageFromWs = <Subject<Message>>wsService
.connect(WS_URL)
.map( response =>
List<any>(response["results"]["bindings"])
.map( item => OneOfMyClasses.fromJson(item) )
.toMap()
).subscribe(items => this.subject.next(items));
}
list(): Observable<List<OneOfMyClasses>> {
return this.observableList;
}
get(results: any): Observable<OneOfMyClasses> {
return this.observableMap.map( items => items.get(results) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.