A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

Hot answers tagged

8

Your service looks perfectly fine to me. As far as the Clock component goes, I can only recommend one thing. When getClock().subscribe(...) is executed, a reference to the subscription is being returned back. Ideally, the reference should be kept as long as the component is alive. On component destruction, the subscription should be released by invoking ...


4

I'd suggest that the switchMap operator be replaced with mergeMap. Only a single array of files (or an error) is going to be emitted from the bound callback, so it will never be necessary to switch; a merge is all that's required. And the Observable.zip call could be simplified. You could use a map operator to pair the file name and the stats. Observable....


3

First off I noticed a problem in how the quiz chooses the numbers: It can easily happen that two (or more) numbers are the same. Especially when picking number between 1..5. In that case it can be confusing to the user, which of the two equal numbers should he click. The main problems with the code resides in tight coupling between UI logic and business ...


3

The purpose of the request made in ngOnInit seemed unclear to me. I presume if any pagination info is not provided, then the result contains the default pagination values such as page, total, limit or does it return all items? Just in case, it is good practice to provide explicit default values such as page: 0, limit: 20etc. After setting the default ...


3

Are there any down sides to using RxJS on the backend The way I see it, you get 2 benefits from RxJS Reactivity Streaming operations Observables are effectively a form of event management. They run, listen to things, and execute code when something happens. They're a good way to respond when something happens in the app. However, when used in routing, ...


3

I'm not very good at js & I can't really suggest ways to clean things up, but you've got this odd mix of OOP & FP, callbacks & promises, and arrow notation & function(). This code style is overall inconsistent. A good first step would be to try to achieve some consistency in style. Now, it may be that the inconsistency stems from using ...


3

Overall, I think this is very decent code, some observations: JSHint Use JsHint ;) You have a number of missing semicolons, and an unnecessary semicolon return url = new Buffer(url, 'base64').toString('ascii'); <- I dont think you wanted to assign to buffer? You are not using the function fileName(url, season, episode){ anywhere Odd stuff You use the ...


3

This is a really good question -- starred it! I am not very experienced with RxJs, but I believe your code around BehaviorSubject and Observable is as concise as possible. BehaviourSubject itself is "subscribable" (just like an Observable) but it's a really bad practice to expose it directly to the consumer, i.e. your separation of users$ and usersSource is ...


2

Two years have passed but your wrap is really a good start for wrapping indexedDb with rxjs. Take(1) now lives in rxjs/operators import and must be used with a pipe but besides this needed an upgrade. Your approach with rxjs seems like the right choice when handling indexedDb without external libraries. Thumbs up!


2

I know I have mentioned this in previous reviews - it would be wise to cache DOM references. For example, I see multiple places in your code where the element with id attribute contentInner is fetched. I would declare it outside the functions that use it (or better yet, wrap all functions in an IIFE to limit the scope), assign the value in the ready() ...


2

First of all, you are using some kind of C# code style in your typescript. I suggest the ng lint command-line to conform with typescript/angular code style. Moreover prefixing interfaces with I is not a typescript convention (https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines). I think the difficult part of your code with rxjs is how to know ...


1

Per se returning a promise from an Angular Service is not bad, however there are numerous things in Angular world that are heavily based on Observables: usually you will likely change the change detection to ChangeDetectionStrategy.OnPush in your components and this will most likely be easier with Angular's async pipe not a problem, because async also ...


1

Do I have any memory leaks? No Why is it if I stick debounceTime(1) inside the lineItem valueChanges then this stops working where the calculation is out by the last change? Beacuse debounceTime(1) delays the response by 1ms inside the lineItem and this.linesChange.emit(value['lines']); is already run with old total The implementation below will ...


1

Looks good. Yeah, sometimes APIs are hard to work with. Instead of the loop clientsData.forEach, you might want to reduce the client data down to an object, where the keys are the client id (ie. index on the id). Then, map through your orders, and use this object to add in the client name. This will be O(N) vs. O(N^2) I'd also probably use a different ...


1

Each subscribe(...) invocation results in creating and returning a new Subscription unless special measures are taken (like .publish(), .share()...) Subscribing to observables Remember, observables are lazy. If you don’t subscribe nothing is going to happen. It’s good to know that when you subscribe to an observer, each call of subscribe() will ...


1

It is really hard to solve the problem since the question is not providing all the necessary details. Assuming you have a factory for your Http observable (call it createHttpObservable()) you may do something like this: const observable = createHttpObservable() // Share the stream of events across all the subscribers. .publishReplay(1) .refCount() ...


1

On Observables My personal preference is to have as few Subscription objects and subscribe() invocations as possible. If I don't have mistakes in the refactored code, you can achieve a single subscribe() which does the same things as your code. I also got rid of sub2. this.offerSubscription = this.service .isPending$ .flatMap(data => { ...


1

First of all, I recommend you to ensure your code is correct (see my comment on your question). Here are a few suggestions about improving your code. Please do not use non-informative names like w, ww, sep, kArg, cW, CK, and even the "well-known" i, j, k, m, n. They are absolutely horrible. They make decent code be an unreadable puzzle. They hide the ...


1

public createAccount(registrationRequest: CreateUserRequestModel): Observable<SomeType> { return this.apiService.post('api/register/account', registrationRequest) .flatMap(() => this.authenticationService.authenticate(registrationRequest.emailAddress, registrationRequest.password)) .map(response => <SomeType>response.json()) ....


1

Specify types explicitly whenever it's possible (including void for methods and FindIpZoneDataService for datafetchservice instead of any). Use const instead of let -- it will help detecting unintended assignments. Try not to move things around when it's not necessary. E.g. the following section is pushing one array's items into another. let res: Array<...


Only top voted, non community-wiki answers of a minimum length are eligible