This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Observable } from "rxjs/Observable"; | |
import { spy } from "rxjs-spy"; | |
import "rxjs/add/observable/interval"; | |
import "rxjs/add/operator/map"; | |
import "rxjs/add/operator/mapTo"; | |
import "rxjs-spy/add/operator/tag"; | |
spy(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Observable } from 'rxjs/Observable'; | |
import { ajax } from 'rxjs/observable/dom/ajax'; | |
const getRepos = action$ => | |
action$.ofType('REPOS_REQUEST') | |
.map(action => action.payload.user) | |
.switchMap(user => ajax.getJSON(`https://api.notgithub.com/users/${user}/repos`)) | |
.map(repos => { type: 'REPOS_RESPONSE', payload: { repos } }) | |
.catch(error => Observable.of({ type: 'REPOS_ERROR' })) | |
.tag('getRepos'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Observable } from 'rxjs/Observable'; | |
import { ajax } from 'rxjs/observable/dom/ajax'; | |
const getRepos = action$ => | |
action$.ofType('REPOS_REQUEST') | |
.map(action => action.payload.user) | |
.switchMap(user => ajax | |
.getJSON(`https://api.notgithub.com/users/${user}/repos`) | |
.map(repos => { type: 'REPOS_RESPONSE', payload: { repos } }) | |
.catch(error => Observable.of({ type: 'REPOS_ERROR' })) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RxSpy.spy(); | |
RxSpy.log(/user-.+/); | |
RxSpy.log('users'); | |
const names = ['benlesh', 'kwonoj', 'staltz']; | |
const users = Rx.Observable.forkJoin(...names.map(name => | |
Rx.Observable | |
.ajax | |
.getJSON(`https://api.github.com/users/${name}`) | |
.tag(`user-${name}`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
changeDetection: ChangeDetectionStrategy.OnPush, | |
selector: "user-search", | |
template: ` | |
<form [formGroup]="form"> | |
<md-input-container> | |
<input formControlName="username" mdInput placeholder="Username"> | |
</md-input-container> | |
</form> | |
<md-list> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
changeDetection: ChangeDetectionStrategy.OnPush, | |
selector: "user-search-container", | |
template: ` | |
<user-search | |
[observer]="observer" | |
[users]="users | async"> | |
</user-search> | |
` | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable() | |
export class UserSearchService { | |
constructor(private _http: Http) {} | |
searchUsers(username: string): Observable<User[]> { | |
return username ? | |
this._http.get(`https://api.github.com/search/users?q=${username}`) | |
.map(response => response.json()) | |
.map(content => content.items) : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function publish<T>( | |
this: Observable<T>, | |
selector?: (source: Observable<T>) => Observable<T> | |
): Observable<T> | ConnectableObservable<T> { | |
return selector ? | |
multicast.call(this, () => new Subject<T>(), selector) : | |
multicast.call(this, new Subject<T>()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof selector === 'function') { | |
return this.lift(new MulticastOperator(subjectFactory, selector)); | |
} | |
const connectable: any = Object.create(this, connectableObservableDescriptor); | |
connectable.source = this; | |
connectable.subjectFactory = subjectFactory; | |
return <ConnectableObservable<T>> connectable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function defaultObservableIfEmpty<T>( | |
defaultObservable: Observable<T> | |
): (source: Observable<T>) => Observable<T> { | |
return source => source.publish(shared => shared.merge( | |
shared.isEmpty().mergeMap(empty => empty ? | |
defaultObservable : | |
Observable.empty<T>() | |
) | |
)); |
OlderNewer