Skip to content

Commit

Permalink
feat(cdk): remove UNIQUE_SELECTION_DISPATCHER_PROVIDER from cdk
Browse files Browse the repository at this point in the history
  • Loading branch information
pimenovoleg committed May 11, 2018
1 parent 54d3134 commit 9726e89
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 40 deletions.
1 change: 0 additions & 1 deletion src/cdk/collections/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ export * from './selection';
export {
UniqueSelectionDispatcher,
UniqueSelectionDispatcherListener,
UNIQUE_SELECTION_DISPATCHER_PROVIDER,
} from './unique-selection-dispatcher';
46 changes: 23 additions & 23 deletions src/cdk/collections/unique-selection-dispatcher.spec.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import { UniqueSelectionDispatcher } from './unique-selection-dispatcher';
import {UniqueSelectionDispatcher} from './unique-selection-dispatcher';


describe('Unique selection dispatcher', () => {
let dispatcher: UniqueSelectionDispatcher;
let dispatcher: UniqueSelectionDispatcher;

beforeEach(() => dispatcher = new UniqueSelectionDispatcher());
beforeEach(() => dispatcher = new UniqueSelectionDispatcher());

it('should notify registered listeners', () => {
const spy = jasmine.createSpy('listen handler');
it('should notify registered listeners', () => {
const spy = jasmine.createSpy('listen handler');

dispatcher.listen(spy);
dispatcher.notify('id', 'name');
dispatcher.listen(spy);
dispatcher.notify('id', 'name');

expect(spy).toHaveBeenCalledWith('id', 'name');
});
expect(spy).toHaveBeenCalledWith('id', 'name');
});

it('should not notify unregistered listeners', () => {
const spy = jasmine.createSpy('listen handler');
const unregister = dispatcher.listen(spy);
it('should not notify unregistered listeners', () => {
const spy = jasmine.createSpy('listen handler');
const unregister = dispatcher.listen(spy);

unregister();
dispatcher.notify('id', 'name');
unregister();
dispatcher.notify('id', 'name');

expect(spy).not.toHaveBeenCalled();
});
expect(spy).not.toHaveBeenCalled();
});

it('should remove all listeners when destroyed', () => {
const spy = jasmine.createSpy('listen handler');
dispatcher.listen(spy);
it('should remove all listeners when destroyed', () => {
const spy = jasmine.createSpy('listen handler');
dispatcher.listen(spy);

dispatcher.ngOnDestroy();
dispatcher.notify('id', 'name');
dispatcher.ngOnDestroy();
dispatcher.notify('id', 'name');

expect(spy).not.toHaveBeenCalled();
});
expect(spy).not.toHaveBeenCalled();
});
});
14 changes: 0 additions & 14 deletions src/cdk/collections/unique-selection-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,3 @@ export class UniqueSelectionDispatcher implements OnDestroy {
this._listeners = [];
}
}

/** @docs-private */
export function UNIQUE_SELECTION_DISPATCHER_PROVIDER_FACTORY(
parentDispatcher: UniqueSelectionDispatcher) {
return parentDispatcher || new UniqueSelectionDispatcher();
}

/** @docs-private */
export const UNIQUE_SELECTION_DISPATCHER_PROVIDER = {
// If there is already a dispatcher available, use that. Otherwise, provide a new one.
provide: UniqueSelectionDispatcher,
deps: [[new Optional(), new SkipSelf(), UniqueSelectionDispatcher]],
useFactory: UNIQUE_SELECTION_DISPATCHER_PROVIDER_FACTORY
};
2 changes: 0 additions & 2 deletions src/lib/radio/radio.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';

import {A11yModule} from '@ptsecurity/cdk/a11y';
import {UNIQUE_SELECTION_DISPATCHER_PROVIDER} from '@ptsecurity/cdk/collections';
import {McCommonModule} from '@ptsecurity/mosaic/core';

import {McRadioButton, McRadioGroup} from './radio.component';
Expand All @@ -11,7 +10,6 @@ import {McRadioButton, McRadioGroup} from './radio.component';
@NgModule({
imports: [ CommonModule, A11yModule, McCommonModule ],
exports: [ McRadioGroup, McRadioButton, McCommonModule ],
providers: [UNIQUE_SELECTION_DISPATCHER_PROVIDER],
declarations: [ McRadioGroup, McRadioButton ]
})
export class McRadioModule {}

0 comments on commit 9726e89

Please sign in to comment.