Questions tagged [observable]

An observable is typically a programming construct that can be "watched" by other parts of the code, called the "observers". Different frameworks and programming languages have different implementations for observables, so this tag should typically be used in conjunction with others.

An observable is typically a programming construct that can be "watched" by other parts of the code, called the "observers". Different frameworks and programming languages have different implementations for observables, so this tag should typically be used in conjunction with others.

An observer may be any object that implements interface Observer. An observable object can have one or more observers. After an observable instance changes, an application calling the Observable's “notification” method causes all of its observers to be notified of the change by a call to their update method.

References

9527 questions
21
votes
1 answer

RxSwift How to use combineLatest?

I have defined: let currentHours:Variable = Variable(0.0) let currentRate:Variable = Variable(0.0) and I would like to make an Observable with combineLatest to sum these two value: Observable.combineLatest(currentHours, currentRate,…
chiarotto.alessandro
  • 1,491
  • 1
  • 13
  • 31
20
votes
2 answers

RxJS - subscribe only once but do not complete Observable

imagine situation when you have some Observable that contains data that changes in real time, example below... interface User { name: string; projectId: string; dataThatChangesALotInRealTime: Object; } userData: Observable This…
Raold
  • 1,383
  • 4
  • 20
  • 33
20
votes
3 answers

How to avoid RxJs subscribe callback hell?

I'm using Angular RxJs subscribe to make a HttpClient call and then make another call using the values from the first one. In this case, there's a call to get address object, and then i make a call using this object. Like…
James
  • 1,189
  • 2
  • 17
  • 32
20
votes
3 answers

How do I poll a service using RXJS Observables?

Given the following code, how to I alter it to make the get request to "api/foobar" repeat every 500 milliseconds? import {Observable} from "RxJS/Rx"; import {Injectable} from "@angular/core"; import {Http} from "@angular/http"; @Injectable()…
Jerry Huckins
  • 498
  • 3
  • 7
  • 22
20
votes
4 answers

unsubscribe is not a function on an observable

I'm making a drag and drop application and I have created an observable to the mouse position, that repositions my drag-object. mouseMove$: any; constructor(){ this.mouseMove$ = Observable.fromEvent(document, 'mousemove') .do((mouseevent:…
Nate May
  • 3,814
  • 7
  • 33
  • 86
20
votes
2 answers

angular2 rxjs observable forkjoin

Is it possible to continue forkjoin http.get requests even if one of the requests fails. I'm looking to a similar function of $q.allSettled in angular2. See example : http://jsfiddle.net/Zenuka/pHEf9/ angular.module('qAllSettled',…
kabus
  • 899
  • 1
  • 11
  • 20
20
votes
1 answer

How to get notified of a observer's unsubscribe action in a custom Observable in RxJava

I'm trying to wrap some listener-pattern based API to an Observable. My code roughly looks like following. def myObservable = Observable.create({ aSubscriber -> val listener = {event -> aSubscriber.onNext(event); } …
victorx
  • 3,267
  • 2
  • 25
  • 35
20
votes
1 answer

Event and Observable in FSharp

Is it equivalent/better to work with the Event module on Event type or with Observable on the publish property of an event Functionally it seems equivalent, and I guess the difference is 'semantic' : Are we inside the boundary where it makes…
nicolas
  • 9,549
  • 3
  • 39
  • 83
20
votes
3 answers

Alternative to Java's Observable class?

I'm coming to Java from the C# world where the Observer pattern is implemented as a first-class language construct with the event keyword. I see that Java's had the Observable class since the early days, but it clearly has implementation issues and…
HolySamosa
  • 9,011
  • 14
  • 69
  • 102
19
votes
4 answers

Type 'Observable' is not assignable to type '[]'

I am pretty new in Angular2/TypeScript so please excuse me if I am doing some stupid mistake. What I am trying to do is from Select drop down I am populating the data using service which is returning me a JSON array. Here is my…
tutorialfeed
  • 965
  • 3
  • 11
  • 24
19
votes
1 answer

How to map a response from http.get to a new instance of a typed object in Angular 2

I'm trying to get an understanding in how to map the result from a service call to an object using http.get and Observables in Angular 2. Take a look at this Plunk In the method getPersonWithGetProperty I'm expecting to return an Observable of type…
Magnus Wallström
  • 1,469
  • 4
  • 15
  • 23
19
votes
2 answers

How to parse xml in Angular 2

I'm using an API that uses XML instead of JSON. Any suggestions on how to convert the following XML to JSON or how to properly use the data in an ngFor directive? Also, would an observable be appropriate here?
Ken
  • 3,091
  • 12
  • 42
  • 69
19
votes
1 answer

How does rxjs observable perform compare to $watch in Angularjs 1.X?

I've heard from various ng-speakers how $watch is dangerous for performance of your application. I was wondering if anyone has compared performance of Rxjs' Observable against $watch in an AngularJS application. I know that Observables is going to…
pchitre
  • 191
  • 1
  • 4
18
votes
3 answers

are lastValueFrom and firstValueFrom equivalent in Angular HTTP?

In angular, we use HttpClient to make HTTP calls which return an observable, if we wanna use promises we can use lastValueFrom/firstValueFrom. Let's say we have: async getLast() { const get$ = this.http.get(url); const res1 = await…
Matias
  • 1,070
  • 2
  • 6
  • 14
18
votes
2 answers

How to listen to an ObservableObject

Ok, so SwiftUI and ObservableObject, on iOS 13. I have Model that implements ObservableObject: class Model: ObservableObject { @Published public var toggle: Bool = false init() { NSLog("Model init") objectWillChange.sink {…
Erhannis
  • 4,256
  • 4
  • 34
  • 48