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(data): Introduce Standalone API for NgRx Data #3553

Closed
wants to merge 0 commits into from

Conversation

santoshyadavdev
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Closes #3529

What is the new behavior?

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@netlify
Copy link

netlify bot commented Aug 29, 2022

Deploy Preview for ngrx-io ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit f825357
🔍 Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/6362e51eddc14e00091cb4e3
😎 Deploy Preview https://deploy-preview-3553--ngrx-io.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Comment on lines 8 to 32
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);
}
Copy link
Member

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);
  },
}

Comment on lines 22 to 56
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,
Copy link
Member

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.

@santoshyadavdev santoshyadavdev marked this pull request as draft September 8, 2022 21:01
@santoshyadavdev
Copy link
Contributor Author

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 : [],

@timdeschryver @markostanimirovic

@markostanimirovic
Copy link
Member

Hey @santoshyadavdev,

Build error (issue with noImplicitAny) can be fixed by adding a return type to the _provideEntityData function:

-export function _provideEntityData(config: EntityDataModuleConfig) {
+export function _provideEntityData(config: EntityDataModuleConfig): Provider[] {

@brandonroberts
Copy link
Member

@santoshyadavdev let us know if you need any more assistance on this. We'd like to land it for v15

@santoshyadavdev
Copy link
Contributor Author

I think I need to fix tests, will check today, And let you know if I need any help.

@santoshyadavdev santoshyadavdev marked this pull request as ready for review November 1, 2022 22:26
@santoshyadavdev
Copy link
Contributor Author

Hi team can I get some help on this test failure

The error is : No provider for InjectionToken @ngrx/data Entity Cache Selector!

@santoshyadavdev
Copy link
Contributor Author

@markostanimirovic
Copy link
Member

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

brandonroberts pushed a commit that referenced this pull request Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Data: Introduce Standalone API for NgRx Data
3 participants