本文整理汇总了TypeScript中rxjs/operators.refCount函数的典型用法代码示例。如果您正苦于以下问题:TypeScript refCount函数的具体用法?TypeScript refCount怎么用?TypeScript refCount使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了refCount函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: convert
convert(entry: INamespace): Namespace {
const namespace = new Namespace(entry);
namespace.applications = this.applicationBindingService
.getBoundApplications(namespace.getId())
.pipe(
map(boundNamespaces => {
const namespaces = boundNamespaces['applications'];
return namespaces ? namespaces.length : 0;
}),
catchError(() => {
return of(0);
}),
publishReplay(1),
refCount()
);
const servicesUrl = `${
AppConfig.k8sApiServerUrl
}namespaces/${namespace.getId()}/services`;
namespace.services = this.http.get<any>(servicesUrl).pipe(
map(res => {
return res.items.length;
}),
catchError(() => {
return of(0);
}),
publishReplay(1),
refCount()
);
return namespace;
}
示例2: constructor
constructor(ref: DocumentReference) {
this.ref = ref;
this.index = new PackedIndex();
this.data().subscribe(data => this.index.setInstitution(data));
this.gradeDistribution = this.data().pipe(
switchMap(data => Axios.get(`${data.cloudFunctionsUrl}/api/grades`)),
map(
(response: { data: any }) =>
Object.freeze(response.data) as Distribution
),
publishReplay(1),
refCount()
);
this.courseRanking = combineLatest(
this.getGradeDistribution().pipe(
map(distribution => {
return Object.entries(distribution).reduce((obj, [course, data]) => {
return {
...obj,
[course]: 2 * Object.values(data).reduce((a, b) => a + b, 0)
};
}, {});
})
),
this.index.getSequences().pipe(
switchMap(sequences => {
return combineLatest(
sequences.map(sequence => this.index.getSparseSequence(sequence))
);
})
)
).pipe(
map(([courseRanking, sparseSequences]) => {
sparseSequences.forEach(sequence => {
// Promote the rank of each course in the sequence to the max.
const max =
sequence
.map(course => courseRanking[course] | 0)
.reduce((a, b) => Math.max(a, b)) + 1;
sequence.forEach(course => (courseRanking[course] = max));
});
return courseRanking;
}),
publishReplay(1),
refCount()
);
}
示例3: it
it('should be repeatable using a ReplaySubject', () => {
function subjectFactory() { return new ReplaySubject(1); }
const source = cold('-1-2-3----4-| ');
const sourceSubs = ['^ ! ',
' ^ ! ',
' ^ !'];
const multicasted = source.pipe(
multicast(subjectFactory),
refCount()
);
const subscribe1 = 's ';
const expected1 = '-1-2-3----4--1-2-3----4--1-2-3----4-|';
const subscribe2 = ' s ';
const expected2 = ' 23----4--1-2-3----4--1-2-3----4-|';
expectObservable(
hot(subscribe1).pipe(tap(() => {
expectObservable(multicasted.pipe(repeat(3))).toBe(expected1);
}))
).toBe(subscribe1);
expectObservable(
hot(subscribe2).pipe(tap(() => {
expectObservable(multicasted.pipe(repeat(3))).toBe(expected2);
}))
).toBe(subscribe2);
expectSubscriptions(source.subscriptions).toBe(sourceSubs);
});
示例4: getNavData
getNavData(): Observable<any> {
if (!this._navData) {
this._navData = this.httpClient.get(environment.serverUrl + 'application')
.pipe(publishReplay(), refCount());
}
return this._navData;
}
示例5: it
it('should unsub from the source when all other subscriptions are unsubbed', (done: MochaDone) => {
let unsubscribeCalled = false;
const connectable = new Observable<boolean>(observer => {
observer.next(true);
return () => {
unsubscribeCalled = true;
};
}).pipe(publish());
const refCounted = connectable.pipe(refCount());
const sub1 = refCounted.subscribe(() => {
//noop
});
const sub2 = refCounted.subscribe(() => {
//noop
});
const sub3 = refCounted.subscribe((x: any) => {
expect((connectable as any)._refCount).to.equal(1);
});
sub1.unsubscribe();
sub2.unsubscribe();
sub3.unsubscribe();
expect((connectable as any)._refCount).to.equal(0);
expect(unsubscribeCalled).to.be.true;
done();
});
示例6: getLogPerson
public getLogPerson(id: string): Observable<ActionLog[]> {
if (!this._logs) {
this._logs = this._http
.get('action-log/list?id=' + id + '&context=person')
.pipe(map(this.deserializeList), publishReplay(), refCount());
}
return this._logs;
}
示例7: cold
'(dis)connecting hot one', () => {
const source = cold('--1-2---3-4--5-|');
const sourceSubs = '^ !';
const expected = '--1-2---3-4--5-|';
const result = source.pipe(
publish(),
refCount()
);
expectObservable(result).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(sourceSubs);
});