Skip to content

Commit

Permalink
feat: add disabled lifecycle groups
Browse files Browse the repository at this point in the history
Signed-off-by: Rifa Achrinza <[email protected]>
  • Loading branch information
achrinza committed Sep 10, 2021
1 parent da92836 commit cb29cbe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/core/src/__tests__/unit/lifecycle-registry.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ describe('LifeCycleRegistry', () => {
expect(events).to.eql(['1-start', '2-start']);
});

it('skips notification of disabled groups', async () => {
givenObserver('1', 'a');
givenObserver('2', 'b');
registry.setDisabledGroups(['a']);
await registry.start();
expect(events).to.eql(['2-start']);
});

it('starts/stops all registered observers with param injections', async () => {
givenObserverWithParamInjection('1');
givenObserverWithParamInjection('2');
Expand Down Expand Up @@ -170,6 +178,10 @@ describe('LifeCycleRegistry', () => {
setParallel(parallel?: boolean) {
this.options.parallel = parallel;
}

setDisabledGroups(groups?: string[]) {
this.options.disabledGroups = groups;
}
}

async function givenLifeCycleRegistry() {
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/lifecycle-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export type LifeCycleObserverOptions = {
* observers are notified in the reverse order during `stop`.
*/
orderedGroups: string[];
/**
* Override and disable lifecycle observer groups. This setting applies to
* both ordered groups (i.e. those defined in `orderedGroups`) and unordered
* groups.
*/
disabledGroups?: string[];
/**
* Notify observers of the same group in parallel, default to `true`
*/
Expand Down Expand Up @@ -211,6 +217,10 @@ export class LifeCycleObserverRegistry implements LifeCycleObserver {
groups = [...groups].reverse();
}
for (const group of groups) {
if (this.options.disabledGroups?.includes(group.group)) {
debug('Notification skipped (Group is disabled): %s', group.group);
continue;
}
const observersForGroup: LifeCycleObserver[] = [];
const bindingsInGroup = reverse
? group.bindings.reverse()
Expand Down

0 comments on commit cb29cbe

Please sign in to comment.