Skip to content

Commit

Permalink
feat(content): create injection tokens with factory (#3265)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 authored Oct 14, 2024
1 parent 0f3bb0b commit 5ac537a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
8 changes: 6 additions & 2 deletions libs/content/driver/src/interfaces/service.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import {
DaffContentBlock,
DaffContentBlockCollection,
} from '@daffodil/content';

export const DaffContentDriver = new InjectionToken<DaffContentServiceInterface>('DaffContentDriver');
import { createSingletonInjectionToken } from '@daffodil/core';

/**
* Query content objects accessible by the logged-in user.
Expand All @@ -19,3 +18,8 @@ export interface DaffContentServiceInterface<
*/
getBlocks(...blockIds: T['id'][]): Observable<DaffContentBlockCollection<T>>;
}

export const {
token: DaffContentDriver,
provider: provideDaffContentDriver,
} = createSingletonInjectionToken<DaffContentServiceInterface>('DaffContentDriver');
22 changes: 12 additions & 10 deletions libs/content/state/src/injection-tokens/error-matcher.token.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { InjectionToken } from '@angular/core';

import { createSingleInjectionToken } from '@daffodil/core';
import { daffTransformErrorToStateError } from '@daffodil/core/state';

/**
* Transforms `DaffError`s into `DaffStateError`s before they are serialized into state.
* Can be used to further refine Daffodil errors into more specific app errors.
*/
export const DAFF_CONTENT_ERROR_MATCHER = new InjectionToken<typeof daffTransformErrorToStateError>(
'DAFF_CONTENT_ERROR_MATCHER',
{ factory: () => daffTransformErrorToStateError },
);
export const {
/**
* Transforms `DaffError`s into `DaffStateError`s before they are serialized into state.
* Can be used to further refine Daffodil errors into more specific app errors.
*/
token: DAFF_CONTENT_ERROR_MATCHER,
/**
* Provider for {@link DAFF_CONTENT_ERROR_MATCHER}.
*/
provider: provideDaffContentErrorMatcher,
} = createSingleInjectionToken<typeof daffTransformErrorToStateError>('DAFF_CONTENT_ERROR_MATCHER');

0 comments on commit 5ac537a

Please sign in to comment.