Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(content): create injection tokens with factory #3265

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Loading