-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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(data): Introduce Standalone API for NgRx Data #3553
Conversation
✅ Deploy Preview for ngrx-io ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
constructor( | ||
private effectSources: EffectSources, | ||
entityCacheEffects: EntityCacheEffects, | ||
entityEffects: EntityEffects | ||
) { | ||
// We can't use `forFeature()` because, if we did, the developer could not | ||
// replace the entity-data `EntityEffects` with a custom alternative. | ||
// Replacing that class is an extensibility point we need. | ||
// | ||
// The FEATURE_EFFECTS token is not exposed, so can't use that technique. | ||
// Warning: this alternative approach relies on an undocumented API | ||
// to add effect directly rather than through `forFeature()`. | ||
// The danger is that EffectsModule.forFeature evolves and we no longer perform a crucial step. | ||
this.addEffects(entityCacheEffects); | ||
this.addEffects(entityEffects); | ||
} | ||
|
||
/** | ||
* Add another class instance that contains effects. | ||
* @param effectSourceInstance a class instance that implements effects. | ||
* Warning: undocumented @ngrx/effects API | ||
*/ | ||
addEffects(effectSourceInstance: any) { | ||
this.effectSources.addEffects(effectSourceInstance); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move this logic back to the EntityDataModule
to avoid breaking changes because addEffects
is a public method. For provideEntityData
, we can use ENVIRONMENT_INITIALIZER
as follows:
{
provide: ENVIRONMENT_INITIALIZER,
multi: true,
useValue() {
const effectSources = inject(EffectSources);
const entityCacheEffects = inject(EntityCacheEffects);
const entityEffects = inject(EntityEffects);
effectsSources.addEffects(entityCacheEffects);
effectsSources.addEffects(entityEffects);
},
}
export function provideEntityData( | ||
config: EntityDataModuleConfig | ||
): EnvironmentProviders { | ||
return { | ||
ɵproviders: [ | ||
{ | ||
provide: ENTITY_METADATA_TOKEN, | ||
multi: true, | ||
useValue: config.entityMetadata ? config.entityMetadata : [], | ||
}, | ||
{ | ||
provide: ENTITY_CACHE_META_REDUCERS, | ||
useValue: config.entityCacheMetaReducers | ||
? config.entityCacheMetaReducers | ||
: [], | ||
}, | ||
{ | ||
provide: ENTITY_COLLECTION_META_REDUCERS, | ||
useValue: config.entityCollectionMetaReducers | ||
? config.entityCollectionMetaReducers | ||
: [], | ||
}, | ||
{ | ||
provide: PLURAL_NAMES_TOKEN, | ||
multi: true, | ||
useValue: config.pluralNames ? config.pluralNames : {}, | ||
}, | ||
{ | ||
provide: ENVIRONMENT_INITIALIZER, | ||
multi: true, | ||
useFactory() { | ||
return () => inject(EntityModuleService); | ||
}, | ||
}, | ||
EntityModuleService, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make provideEntityData
work independently, we need to add providers from EntityDataModule
and providers from EntityDataModuleWithoutEffects
.
We also need to add the provideEntityDataWithoutEffects
function as a replacement for EntityDataModuleWithoutEffects.forRoot
.
Hi Team, I need help with type error modules/data/src/provide_entity_data.ts:80:7 - error TS7018: Object literal's property 'useValue' implicitly has an 'any[] | EntityMetadataMap' type. useValue: config.entityMetadata ? config.entityMetadata : [], |
Hey @santoshyadavdev, Build error (issue with -export function _provideEntityData(config: EntityDataModuleConfig) {
+export function _provideEntityData(config: EntityDataModuleConfig): Provider[] { |
aaaea66
to
3032bb0
Compare
@santoshyadavdev let us know if you need any more assistance on this. We'd like to land it for v15 |
I think I need to fix tests, will check today, And let you know if I need any help. |
bab668a
to
c884375
Compare
Hi team can I get some help on this test failure The error is : No provider for InjectionToken @ngrx/data Entity Cache Selector! |
39cd7c5
to
f825357
Compare
Hey @santoshyadavdev, Sorry, I accidentally pushed changes from the master to your branch 😅, and now I don't have permission to push the fix, because the PR was automatically closed. Can you please re-open the PR? Here are the changes that should fix it: 8f805ef |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Closes #3529
What is the new behavior?
Does this PR introduce a breaking change?
Other information