{"id":19641752,"url":"https://github.com/layzeedk/rxjs-subscription-count","last_synced_at":"2025-04-28T12:31:36.278Z","repository":{"id":55842884,"uuid":"143483442","full_name":"LayZeeDK/rxjs-subscription-count","owner":"LayZeeDK","description":"subscriptionCount operator for RxJS - Count subscriptions to observables. Useful for testing.","archived":false,"fork":false,"pushed_at":"2022-03-02T23:01:07.000Z","size":190,"stargazers_count":6,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2024-10-30T11:20:16.882Z","etag":null,"topics":["rxjs","rxjs-subscriptions","rxjs6"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LayZeeDK.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"LayZeeDK"}},"created_at":"2018-08-03T23:58:06.000Z","updated_at":"2024-08-28T06:58:35.000Z","dependencies_parsed_at":"2022-08-15T07:50:15.403Z","dependency_job_id":null,"html_url":"https://github.com/LayZeeDK/rxjs-subscription-count","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LayZeeDK%2Frxjs-subscription-count","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LayZeeDK%2Frxjs-subscription-count/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LayZeeDK%2Frxjs-subscription-count/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LayZeeDK%2Frxjs-subscription-count/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LayZeeDK","download_url":"https://codeload.github.com/LayZeeDK/rxjs-subscription-count/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224115712,"owners_count":17258238,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rxjs","rxjs-subscriptions","rxjs6"],"created_at":"2024-11-11T14:10:17.883Z","updated_at":"2024-11-11T14:10:18.487Z","avatar_url":"https://github.com/LayZeeDK.png","language":"TypeScript","funding_links":["https://github.com/sponsors/LayZeeDK"],"categories":[],"sub_categories":[],"readme":"# `subscriptionCount` operator for RxJS\n## rxjs-subscription-count\nCount subscriptions to observables. Useful for testing `Observable` flattening strategies.\n\n## Installation\nInstall using NPM CLI\n```\nnpm install --save rxjs-subscription-count\n```\n\nor using Yarn CLI\n```\nyarn add rxjs-subscription-count\n```\n\n## Use cases\nTest that the subscriptions are switched (`switchMap` or `switchAll`) correctly\nto prevent memory leaks and race conditions.\n\n## Usage\n```typescript\nimport { BehaviorSubject, empty } from 'rxjs';\nimport { subscriptionCount } from 'rxjs-subscription-count';\n\nconst counter: BehaviorSubject\u003cnumber\u003e = new BehaviorSubject(0);\nconst source: Observable\u003cnever\u003e = empty().pipe(\n  subscriptionCount(counter),\n);\n```\n\n## `switchMap` test case\n```typescript\nimport {\n  BehaviorSubject,\n  interval,\n  Observable,\n  range,\n  Subscription,\n} from 'rxjs';\nimport { switchMap } from 'rxjs/operators';\n\nimport { subscriptionCount } from './subscription-count';\n\ndescribe('switchMap', () =\u003e {\n  it('keeps a single subscription', () =\u003e {\n    const threeValues: Observable\u003cnumber\u003e = range(1, 3);\n    const subscriptionCounter: BehaviorSubject\u003cnumber\u003e = new BehaviorSubject(0);\n    const infiniteValues: Observable\u003cnumber\u003e = interval(0).pipe(\n      subscriptionCount(subscriptionCounter),\n    );\n\n    const subscription: Subscription = threeValues.pipe(\n      switchMap(() =\u003e infiniteValues),\n    ).subscribe();\n\n    expect(subscriptionCounter.value).toBe(1);\n    subscription.unsubscribe();\n  });\n});\n```\n\n## `mergeMap` test case\n```typescript\nimport {\n  BehaviorSubject,\n  interval,\n  Observable,\n  range,\n  Subscription,\n} from 'rxjs';\nimport { mergeMap } from 'rxjs/operators';\n\nimport { subscriptionCount } from './subscription-count';\n\ndescribe('mergeMap', () =\u003e {\n  it('results in a subscription per emitted value', () =\u003e {\n    const threeValues: Observable\u003cnumber\u003e = range(1, 3);\n    const subscriptionCounter: BehaviorSubject\u003cnumber\u003e = new BehaviorSubject(0);\n    const infiniteValues: Observable\u003cnumber\u003e = interval(0).pipe(\n      subscriptionCount(subscriptionCounter),\n    );\n\n    const subscription: Subscription = threeValues.pipe(\n      mergeMap(() =\u003e infiniteValues),\n    ).subscribe();\n\n    expect(subscriptionCounter.value).toBe(3);\n    subscription.unsubscribe();\n  });\n});\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flayzeedk%2Frxjs-subscription-count","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flayzeedk%2Frxjs-subscription-count","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flayzeedk%2Frxjs-subscription-count/lists"}