observable

LiveData List doesn't update when updating database

a 夏天 提交于 2019-12-12 10:05:58
问题 I'm currently refactoring legacy code to use Android Architecture Components and set up a room db and volley requests within a kind of repository pattern. So the presentation/domain layer asks the repository to get LiveData-Objects to observe or tell him to synchronize with the server, after which old db entries are deleted and all current ones refetched from the server. I've written tests for the synchronization part, so I'm sure, that the objects get fetched and inserted to the database

Emit and broadcast events throughout application in Angular

大兔子大兔子 提交于 2019-12-12 09:58:43
问题 Is there a way to emit event in angular2 that can be listened to in entire application? Like we had in AngularJS using $rootScope.broadcast and emit . Can this same thing be achieved in angular2? I read about @Output() and EventEmitter() and implemented it but it restricts only the parent to listen to the event emmitted by child. I read about BehaviorSubject being one of the ways to do this. Is that the right approach? Any other solution for this? 回答1: In Angular2 there is no global scope.

RXJS: Adding a function to Observable to execute when subscribed to (defer)

牧云@^-^@ 提交于 2019-12-12 09:56:59
问题 Adding a function to Observable to execute when subscribed to (defer) I have an Observable made from events. In this case, Bluetooth notifications. I want to run a function (startNotifictions) only when someone is subscribing to that Observable. This code did work, on previous versions. It is with Ionic3 framework. It added a new operator, that ran when subscribed. Now the transpiler has a problem with the types, complaining twice, that the .doOnSubscribe is not available on typedef

How to organize Angular data service

此生再无相见时 提交于 2019-12-12 09:28:18
问题 I have become slightly confused over Observables, Observers, Subjects, BehaviorSubjects, Services, injections, etc. I am trying to make a simple finance app. I have a transactions service that grabs the data from a REST server and then provides it to other services that can update it if they need to. I can get the list transactions component (which gets its data from getTransactions() )to update with the service, but I don't know how to get the edit component (which gets its data from "

How to properly chain rxjs 6 observables?

醉酒当歌 提交于 2019-12-12 08:57:53
问题 Any suggestions, how this can be rewritten in more promise-chaining style?: this.apiService.sendPutRequest('/api/users/activate', usrObj).pipe( map(() => { return this.apiService.sendGetRequest('/api/users/' + this.currentUserId).pipe( map(data => { return this.setActiveUser(data).pipe( map(() => { return this.apiService.sendGetRequest('api/tasks/user/' + this.currentUserId).pipe( map(tasks => { return this.taskService.setCurrentUserTasks(tasks); }) ); }) ); }) ); }) ); 回答1: You can use

Type 'Subscription' is not assignable to type 'Observable<SearchResult[]>' Angular 5 using HttpClient instead of Http

天涯浪子 提交于 2019-12-12 08:27:58
问题 I'm trying to use the new HttpClient class instead of the old Http. I want to map over the data I get from the subscribe method, but get the below error. Any suggestions on why I get this? Code: export class YoutubeSearchService { constructor( private http: HttpClient, @Inject(YOUTUBE_API_KEY) private apiKey: string, @Inject(YOUTUBE_API_URL) private apiUrl: string, ) { } search(query: string): Observable<SearchResult[]> { const params: string = [ `q=${query}`, `key=${this.apiKey}`, `part

Handle Network error with Retrofit observable

匆匆过客 提交于 2019-12-12 08:22:18
问题 When using Observables with Retrofit how do you handle Network failure? Given this code: Observable<GetJobResponse> observable = api.getApiService().getMyData(); observable .doOnNext(new Action1<GetJobResponse>() { @Override public void call(GetJobResponse getJobResponse) { //do stuff with my data } }) .doOnError(new Action1<Throwable>() { @Override public void call(Throwable throwable) { //do stuff with error message } }); The request just fails without network and onError is not called. It

Difference between new Observable(…) and Rx.Observable.create(…)?

*爱你&永不变心* 提交于 2019-12-12 08:18:11
问题 I'm updating our software substituting all promises (and other hairy junk) for observables. To make sure that I'm following best practices, I made a quick googlearch and noticed that in some cases, the suggested syntax is by instance whereas in other cases, the examples perform a call by factory. const byInstance = new Observable(_ => { ... }); const byFactory = Rx.Observable.create(_ => { ... }); I'm curious what's the actual difference. Are they precisely interchangeable? Is it an older

Communication between multiple components with a service by using Observable and Subject in Angular 2

你。 提交于 2019-12-12 04:45:38
问题 I am new to rxjs, so I would like to ask a question regarding Angular 2 , Observables and BehaviorSubject/Subject . So, what I want to achieve is : onclick of a button inside a ComponentA to notify other components for example ComponentB , ComponentC . What I did so far is to create a service : private isMenuOpenBS = new BehaviorSubject(false); toggleMenu(): void { this.isMenuOpenBS.next(!this.isMenuOpenBS.getValue()); } getMenuState(): Observable<boolean> { return this.isMenuOpenBS

How can I update my subscribe data?

会有一股神秘感。 提交于 2019-12-12 04:33:13
问题 I have a service that makes some http call to a rest api. On my component I have a subscribe to it. How can I update the data on the subscribe without having to make a new call to the service? 回答1: The question is not quite clear, but I think I can infer enough to hopefully offer an answer. Let's assume you have an observable of a User object that has an OrganizationId property on it, and you want an observable of the Organization object associated with that OrganizationId . You want it to