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(customer-store-credit): create injection tokens with factory #3245

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
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { InjectionToken } from '@angular/core';
import { Observable } from 'rxjs';

import { createSingleInjectionToken } from '@daffodil/core';
import { DaffCustomerStoreCredit } from '@daffodil/customer-store-credit';

/**
* An injection token for the customer store credit driver.
*/
export const DaffCustomerStoreCreditDriver = new InjectionToken<DaffCustomerStoreCreditDriverInterface>('DaffCustomerStoreCreditDriver');
export const {
/**
* An injection token for the customer store credit driver.
*/
token: DaffCustomerStoreCreditDriver,
provider: daffProvideCustomerStoreCreditDriver,
} = createSingleInjectionToken<DaffCustomerStoreCreditDriverInterface>('DaffCustomerStoreCreditDriver');

/**
* The customer store credit driver is responsible for loading customers.
Expand Down
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_CUSTOMER_STORE_CREDIT_ERROR_MATCHER = new InjectionToken<typeof 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_CUSTOMER_STORE_CREDIT_ERROR_MATCHER,
provider: daffProvideCustomerStoreCreditErrorMatcher,
} = createSingleInjectionToken<typeof daffTransformErrorToStateError>(
'DAFF_CUSTOMER_STORE_CREDIT_ERROR_MATCHER',
{ factory: () => daffTransformErrorToStateError },
);
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { DAFF_CUSTOMER_STORE_CREDIT_ERROR_MATCHER } from './error-matcher.token';
export * from './error-matcher.token';
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
import {
InjectionToken,
Provider,
} from '@angular/core';
import { ActionReducer } from '@ngrx/store';

import { createMultiInjectionToken } from '@daffodil/core';

import { DaffCustomerStoreCreditReducersState } from '../reducers.interface';

/**
* A token to hold the injectable extra reducers.
*
* Prefer using {@link daffCustomerStoreCreditProvideExtraReducers}.
*/
export const DAFF_CUSTOMER_STORE_CREDIT_EXTRA_REDUCERS = new InjectionToken<ActionReducer<DaffCustomerStoreCreditReducersState>[]>(
export const {
/**
* A token to hold the injectable extra reducers.
*
* Prefer using {@link daffCustomerStoreCreditProvideExtraReducers}.
*/
token: DAFF_CUSTOMER_STORE_CREDIT_EXTRA_REDUCERS,

/**
* Provides additional reducers that run after the standard Daffodil customer reducers.
*
* ```ts
* providers: [
* ...daffCustomerStoreCreditProvideExtraReducers(
* myReducer1,
* myReducer2
* )
* ]
* ```
*/
provider: daffCustomerStoreCreditProvideExtraReducers,
} = createMultiInjectionToken<ActionReducer<DaffCustomerStoreCreditReducersState>>(
'DAFF_CUSTOMER_STORE_CREDIT_EXTRA_REDUCERS',
{
factory: () => [],
providedIn: 'any',
},
{ providedIn: 'any' },
);

/**
* Provides additional reducers that run after the standard Daffodil customer reducers.
*
* ```ts
* providers: [
* ...daffCustomerStoreCreditProvideExtraReducers(
* myReducer1,
* myReducer2
* )
* ]
* ```
*/
export function daffCustomerStoreCreditProvideExtraReducers(
...reducers: ActionReducer<DaffCustomerStoreCreditReducersState>[]
): Provider[] {
return reducers.map(reducer => ({
provide: DAFF_CUSTOMER_STORE_CREDIT_EXTRA_REDUCERS,
useValue: reducer,
multi: true,
}));
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import {
inject,
InjectionToken,
} from '@angular/core';
import { inject } from '@angular/core';
import {
ActionReducer,
combineReducers,
} from '@ngrx/store';

import { createSingleInjectionToken } from '@daffodil/core';
import { daffComposeReducers } from '@daffodil/core/state';
// these unused imports are a workaround
import { DaffCustomerStoreCredit } from '@daffodil/customer-store-credit';
Expand All @@ -15,13 +13,16 @@ import { DAFF_CUSTOMER_STORE_CREDIT_EXTRA_REDUCERS } from './extra.token';
import { DaffCustomerStoreCreditReducersState } from '../reducers.interface';
import { daffCustomerStoreCreditReducer } from '../store-credit/public_api';

/**
* An internal token to hold the Daffodil customer reducers.
* Includes the extra and standard reducers.
*
* @docs-private
*/
export const DAFF_CUSTOMER_STORE_CREDIT_REDUCERS = new InjectionToken<ActionReducer<DaffCustomerStoreCreditReducersState>>(
export const {
/**
* An internal token to hold the Daffodil customer reducers.
* Includes the extra and standard reducers.
*
* @docs-private
*/
token: DAFF_CUSTOMER_STORE_CREDIT_REDUCERS,
provider: daffProvideCustomerStoreCreditReducers,
} = createSingleInjectionToken<ActionReducer<DaffCustomerStoreCreditReducersState>>(
'DAFF_CUSTOMER_STORE_CREDIT_REDUCERS',
{
providedIn: 'any',
Expand Down
Loading