Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RXWAIT observable$.cache is not a function #108

Closed
mkoczorowski opened this issue May 3, 2017 · 14 comments · Fixed by ui-router/core#366
Closed

RXWAIT observable$.cache is not a function #108

mkoczorowski opened this issue May 3, 2017 · 14 comments · Fixed by ui-router/core#366
Labels
Milestone

Comments

@mkoczorowski
Copy link

.cache is deprecated now. We should change this to .share() or publish().refCount(1)

@mkoczorowski
Copy link
Author

I can fix this, if Im able to do a pull

@plcart
Copy link

plcart commented May 9, 2017

Please consider this change as your next RC

@christopherthielen christopherthielen added this to the 1.0.0-beta.7 milestone May 10, 2017
@claudiuconstantin
Copy link

Any workaround for this?

@plcart
Copy link

plcart commented May 18, 2017

get the operator/cache.(js|d.ts|map) file from "rxjs": "5.0.0-beta.12" and add to your app or to node_modules/rxjs/operator/ & node_modules/rxjs/add/operator/

@christopherthielen
Copy link
Member

RXWAIT is not really working properly even with .cache(). I think the ui-router team needs need to take a step back and re-evaluate how to implement RXWAIT

@dam1ann
Copy link

dam1ann commented Oct 25, 2017

I used policy: { async: "RXWAIT" } in state resolving

Console shows:
stateService.js:41 Transition Rejection($id: 0 type: 6, message: The transition errored, detail: TypeError: observable$.cache is not a function)

How to resolve this problem? Its necessary to change node_modules folder?

@plcart
Copy link

plcart commented Oct 26, 2017

Create a file with this content
`import { Observable } from 'rxjs/Observable';
import { Scheduler } from 'rxjs/Scheduler';
import { ReplaySubject } from 'rxjs/ReplaySubject';
import { Observer } from 'rxjs/Observer';
import { Subscription } from 'rxjs/Subscription';

export function cache(
bufferSize: number = Number.POSITIVE_INFINITY,
windowTime: number = Number.POSITIVE_INFINITY,
scheduler?: Scheduler): Observable {
let subject: ReplaySubject;
let source = this;
let refs = 0;
let outerSub: Subscription;

const getSubject = () => {
	subject = new ReplaySubject<T>(bufferSize, windowTime, scheduler);
	return subject;
};

return new Observable<T>((observer: Observer<T>) => {
	if (!subject) {
		subject = getSubject();
		outerSub = source.subscribe(
			(value: T) => subject.next(value),
			(err: any) => {
				let s = subject;
				subject = null;
				s.error(err);
			},
			() => subject.complete()
		);
	}

	refs++;

	if (!subject) {
		subject = getSubject();
	}
	let innerSub = subject.subscribe(observer);

	return () => {
		refs--;
		if (innerSub) {
			innerSub.unsubscribe();
		}
		if (refs === 0) {
			outerSub.unsubscribe();
		}
	};
});

}

export interface CacheSignature {
(bufferSize?: number, windowTime?: number, scheduler?: Scheduler): Observable;
}`

at some main location in your app

`import { cache, CacheSignature } from '../services/cache';

Observable.prototype.cache = cache;

declare module 'rxjs/Observable' {
interface Observable {
cache: CacheSignature;
}
}`

@kuhnroyal
Copy link

This is somewhat of a blocker, I think .shareReplay() could potentially solve this problem.
It is available in rxjs 5.4.0+

ReactiveX/rxjs#2443
https://github.com/ReactiveX/rxjs/blob/892700dd4f5d5e5f9ae9276ede32208f4390c5e9/CHANGELOG.md#540-2017-05-09

@mkoczorowski
Copy link
Author

this issue is in beta.10 milestone.. but rc was released after bata.9 ?

@kuhnroyal
Copy link

kuhnroyal commented Mar 18, 2018

I tried to fix this in core but this is not possible, the rxjs typings/imports are needed to get this working.

I think the ResolvePolicy needs to become pluggable. Core should only provide WAIT and NOWAIT by default.
After this the whole RXWAIT can easily be implemented in the ng2/react module with the correct typings and plugged in.

At the moment I doubt anyone is using RXWAIT because it simply doesn't work with any recent version of angular and rxjs 5+.

So I propose RXWAIT gets dropped from core and implemented in ng2/react. Not sure how this can fit in the ng1 module.

@christopherthielen What do you think, is this possible?

Edit: I think the correct place to implement RXWAIT is actually @uirouter/rx.

@colmben
Copy link

colmben commented Mar 31, 2018

Am I missing something or is this not a pretty major showstopper for an Angular 2+ router? Observables are all over the place in Angular now. Is the suggested workaround just to "toPromise" everything?

@colmben
Copy link

colmben commented Mar 31, 2018

Also, its been around for nearly a year, can we take RXWAIT out of the docs?

@vincentdewisme
Copy link

Got the same error in my project:
TypeError: observable$.cache is not a function at waitForRx (resolvable.js:83)

Solved it by promisifying all my Observables...
So sad the other workaround creating the cache method on Observable did not work.

@Dgs-asohail4
Copy link

DEC 2018 still no workaround ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants