-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add config object to connectable (#6267)
* feat: add config object to connectable * chore: update api_guardian * chore: typo BREAKING CHANGE: Our very new api, `connectable`, now takes a configuration object instead of just the `Subject` instance. This was necessary to make sure it covered all use cases for what we were trying to replace in the deprecated multicasting operators. Apologies for the late-in-the-game change, but we know it's not widely used yet (it's new in v7), and we want to get it right. Co-authored-by: Ben Lesh <ben@benlesh.com>
- Loading branch information
Showing
4 changed files
with
117 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** @prettier */ | ||
import { expect } from 'chai'; | ||
import { connectable, of, ReplaySubject } from 'rxjs'; | ||
import { TestScheduler } from 'rxjs/testing'; | ||
import { observableMatcher } from '../helpers/observableMatcher'; | ||
|
||
describe('connectable', () => { | ||
let testScheduler: TestScheduler; | ||
|
||
beforeEach(() => { | ||
testScheduler = new TestScheduler(observableMatcher); | ||
}); | ||
|
||
it('should mirror a simple source Observable', () => { | ||
testScheduler.run(({ cold, expectObservable, expectSubscriptions }) => { | ||
const source = cold('--1-2---3-4--5-|'); | ||
const sourceSubs = ' ^--------------!'; | ||
const expected = ' --1-2---3-4--5-|'; | ||
|
||
const obs = connectable(source); | ||
|
||
expectObservable(obs).toBe(expected); | ||
expectSubscriptions(source.subscriptions).toBe(sourceSubs); | ||
|
||
obs.connect(); | ||
}); | ||
}); | ||
|
||
it('should do nothing if connect is not called, despite subscriptions', () => { | ||
testScheduler.run(({ cold, expectObservable, expectSubscriptions }) => { | ||
const source = cold('--1-2---3-4--5-|'); | ||
const sourceSubs: string[] = []; | ||
const expected = ' -'; | ||
|
||
const obs = connectable(source); | ||
|
||
expectObservable(obs).toBe(expected); | ||
expectSubscriptions(source.subscriptions).toBe(sourceSubs); | ||
}); | ||
}); | ||
|
||
it('should support resetOnDisconnect = true', () => { | ||
const values: number[] = []; | ||
const source = of(1, 2, 3); | ||
const obs = connectable(source, { | ||
connector: () => new ReplaySubject(1), | ||
resetOnDisconnect: true, | ||
}); | ||
|
||
obs.subscribe((value) => values.push(value)); | ||
const connection = obs.connect(); | ||
expect(values).to.deep.equal([1, 2, 3]); | ||
|
||
connection.unsubscribe(); | ||
|
||
obs.subscribe((value) => values.push(value)); | ||
obs.connect(); | ||
expect(values).to.deep.equal([1, 2, 3, 1, 2, 3]); | ||
}); | ||
|
||
it('should support resetOnDisconnect = false', () => { | ||
const values: number[] = []; | ||
const source = of(1, 2, 3); | ||
const obs = connectable(source, { | ||
connector: () => new ReplaySubject(1), | ||
resetOnDisconnect: false, | ||
}); | ||
|
||
obs.subscribe((value) => values.push(value)); | ||
const connection = obs.connect(); | ||
expect(values).to.deep.equal([1, 2, 3]); | ||
|
||
connection.unsubscribe(); | ||
|
||
obs.subscribe((value) => values.push(value)); | ||
obs.connect(); | ||
expect(values).to.deep.equal([1, 2, 3, 3]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters