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

Global emissionRate for all NgxAutomaticRootFormComponent #184

Closed
alemputes opened this issue Aug 12, 2020 · 4 comments
Closed

Global emissionRate for all NgxAutomaticRootFormComponent #184

alemputes opened this issue Aug 12, 2020 · 4 comments
Labels
flag: can be closed? This issue or PR should probably be closed now type: RFC/discussion/question This issue is about RFC, discussion or a question

Comments

@alemputes
Copy link

Hi, is there anyway we can set the emissionRate for all components that extend NgxAutomaticRootFormComponent?

Right now I need to do this in all my components:
protected handleEmissionRate(): (obs$: Observable<MailSettingsNotificationsForm>) => Observable<MailSettingsNotificationsForm> { return NGX_SUB_FORM_HANDLE_VALUE_CHANGES_RATE_STRATEGIES.debounce(1000); }

@maxime1992 maxime1992 added the type: RFC/discussion/question This issue is about RFC, discussion or a question label Aug 12, 2020
@maxime1992
Copy link
Contributor

Hi @alemputes,

We've got a lot of them in our repo (+70) and what we've done is the following:

@Directive({})
export abstract class AutomaticRootFormComponent<ControlInterface, FormInterface = ControlInterface>
  extends NgxAutomaticRootFormComponent<ControlInterface, FormInterface>
  implements OnInit, OnChanges {
  public ngOnChanges(changes: SimpleChanges): void {}

  // by default on the app we debounce auto saves
  protected handleEmissionRate(): (obs$: Observable<FormInterface>) => Observable<FormInterface> {
    return NGX_SUB_FORM_HANDLE_VALUE_CHANGES_RATE_STRATEGIES.debounce(300);
  }
}

And then into our app instead of extending from NgxAutomaticRootFormComponent we do extend from AutomaticRootFormComponent. This let us have one class where we can define every custom params we want 😃

Would that be enough for you?

Maybe one day if we require to declare an NgxSubFormModule we'd in a forRoot method define a token for that value and set it by default to 0 and to override it you'd just have to override the token and provide your own value 👍

But for now we've been trying to keep that library as simple as possible and we don't have any module so that'd require a lot more changes than just the solution above.

@maxime1992 maxime1992 added the flag: can be closed? This issue or PR should probably be closed now label Aug 12, 2020
@alemputes
Copy link
Author

Yeah that directive should be enough, I actually need the one for NgxSubFrom as well so I made this one, is the OnInit and OnChanges really needed? Seems to work fine without them:

@Directive({})
// tslint:disable-next-line:directive-class-suffix
export abstract class NgxCustomSubFormComponent<ControlInterface, FormInterface = ControlInterface>
    extends NgxSubFormComponent<ControlInterface, FormInterface> {

  // by default on the app we debounce auto saves
  protected handleEmissionRate(): (obs$: Observable<FormInterface>) => Observable<FormInterface> {
    return NGX_SUB_FORM_HANDLE_VALUE_CHANGES_RATE_STRATEGIES.debounce(1000);
  }
}

A NgxSubFromModule would be great, maybe this could part of your "Major architecture changes coming" 👍

Thank a lot for you fast replays Max, keep up the good work, really loving ngx-sub-forms.

@maxime1992
Copy link
Contributor

OnInit and OnChanges really needed?

I guess not not sure why we've got that so yes feel free to remove that part 👍

A NgxSubFromModule would be great, maybe this could part of your "Major architecture changes coming"

I don't think that's going to end up there as the changes made internally + the ones visibles as part of the public interfaces is probably already enough haha.

Closing as you seem to be happy with the solution above 👍

@maxime1992
Copy link
Contributor

keep up the good work, really loving ngx-sub-forms

Thanks 🙏

Feel free to let us know how you're using the lib here and share your experience with others: #112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flag: can be closed? This issue or PR should probably be closed now type: RFC/discussion/question This issue is about RFC, discussion or a question
Projects
None yet
Development

No branches or pull requests

2 participants