observable

Observable pattern in Remote EJB

孤人 提交于 2019-12-13 07:29:51
问题 I have 2 applications. One 'main' and a second one with a Remote EJB. The first application calls the Remote EJB in the second one. Now I want to implement the Observable pattern. But it doesn't seem to work cross-application. So I want my Observable inside the second application, and my Observers in the first. When I try it, it doesn't seem to work. It only works if I make the Observable and Observers in the same application. I got another solution, but I think it's dirty. I could use a MDB

Need a way to subscribe to an observable that Angular service holds and also display it in view

こ雲淡風輕ζ 提交于 2019-12-13 06:35:09
问题 I am writing an angular + nodejs application where server listens to twitter stream and front-end angular application using socket.io gets data from server. Everything works till this point, but I am unable to find a way to subscribe to my angular service which using socket.io gets the data. How can I subscribe to the data that my service has and also how can I bind it to my view, so that the data shows up. Here is my service code in Angular that gets data from server: import {Injectable}

angular2 avoid updating reference variable also

一世执手 提交于 2019-12-13 06:11:41
问题 why angular2 is updating all the references of a variable? Problem Statement: I have a service which returns observable on calling getData method @Injectable() export class BuildingService { constructor(private http: Http){ } buildings$: Observable<Building[]>; getData() : Observable<Building[]>{ if (this.buildings$) { this.buildings$ = this.http.get('http://localhost:8080/buildings') .map(this.extractData) .publishReplay(1) .refCount(); } return this.buildings$; } private extractData(res:

RXSwift: Modifying URLRequest if request fails in `retryWhen`

强颜欢笑 提交于 2019-12-13 03:37:20
问题 I need to modify the headers of the request when the request fails but the request doesn't change when I modify the request in retryWhen Here is my implementation: func makeRequest(serviceRequest: URLRequest) { let maxRetry = 2 var localRequest = serviceRequest request(request: localRequest).retryWhen { errors in return errors.enumerated().flatMap { (arg) -> Observable<Int64> in localRequest.setValue("someValue", forHTTPHeaderField: "someKey") let (index, error) = arg return index <= maxRetry

RxJS - Create Observable from an EventEmitter's multiple events

余生颓废 提交于 2019-12-13 03:35:46
问题 I have a node.js EventEmitter which raises the following events: error , message . Is there a straight forward way I can create an RxJS Observable from it? i.e next() called on message and error() called on error . 回答1: You can create it like this: const obs$ = Observable.create(observer => { emitter.on('message', val => observer.next(val)); emitter.on('error', err => observer.error(err)); }); As an alternative, you can do this by constructinng and chaining observables like this, but it's

Sort nested observable

社会主义新天地 提交于 2019-12-13 00:46:45
问题 I have here a JSON file which looks like this: [ { "question": "What is your age range?", "options": ["10-20","20-30","30-40","40-50"] }, { "question": "How did you find us?", "options": ["Friend recommendation","Google","Other"] }, { "question": "Are you interested in etcetc?", "options": ["No","Yes","Meh"] } ] In my project I've got a model with the same structure which looks like this: export interface Test { question: string; options: string[]; } in my service file, I read the file like

How to call multiple API and subscribe in angular 6?

本小妞迷上赌 提交于 2019-12-12 20:44:07
问题 In my app, to call all the POST request I have used a service . When I get a specific code (E.x : 401) from the server, I call an API to fetch new token. Till the another token is received, if there's any other API call from, I store all those requests in an array. It may be n requests. For now assume there are 3 API call while the call for newToken API is in progress. Once I get a new token I have to pass that in all the subsequent API's. Now I have to execute all the pending API requests

Closure identity in swift: unregister observing closure

余生长醉 提交于 2019-12-12 19:19:52
问题 When rethinking my everyday programming patterns to be more swifty , there is one, that I really struggle with: observing changes . After a lot of thinking and research I have yet to find a satisfying solution . That is one, that is easy to use, leverages the full potential of swift's strong type system, is compatible with value types and allows for static dispatch. Maybe the latter one is not possible and that's the reason why my search is unsuccessful so far. If so, I would like to know why

Java Interface Observable

喜夏-厌秋 提交于 2019-12-12 18:36:25
问题 I have the following: A Java class: ClassA implements Observer A Java Interface: Inter (extends Observable, not possible) A Java class: ClassB implements Inter extends Observable A Java class: ClassC implements Inter extends Observable Now the code for ClassA is somewhat like this. ClassA{ Inter anyClass = new ClassB(); //or it could be Inter anyClass = new ClassC(); //Inter.addObserver(this); //not possible since Interface cannot extend Observable } Now if a particular event happens in

Convert click event into Observable Mouse Event (Angular 2/4)

旧街凉风 提交于 2019-12-12 18:11:52
问题 I'm trying to make Drag and Drop functionality on my own without use any opensource modules. When I use single element and create Observables in the controller like: const mouseup = Observable.fromEvent(item, 'mouseup'); const mousemove = Observable.fromEvent(document, 'mousemove'); const mousedown = Observable.fromEvent(item, 'mousedown'); Drag works fine. But when I bind event in template with (click) and pass $event to controller like: (click)="click($event)" I can't convert event into