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

[New Feature] Add new possible value for ngrxUpdateOn #119

Merged
merged 1 commit into from
Oct 21, 2018
Merged

[New Feature] Add new possible value for ngrxUpdateOn #119

merged 1 commit into from
Oct 21, 2018

Conversation

Mr-Eluzive
Copy link
Contributor

This PR address my proposal #118.

<!-- Example usage -->
<input [ngrxFormState]="formState$ | async" ngrxUpdateOn="never" />

@codecov-io
Copy link

codecov-io commented Oct 17, 2018

Codecov Report

Merging #119 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #119   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files         116    116           
  Lines        2180   2184    +4     
  Branches      408    408           
=====================================
+ Hits         2180   2184    +4
Impacted Files Coverage Δ
src/control/directive.ts 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 808677a...9d66add. Read the comment docs.

@MrWolfZ
Copy link
Owner

MrWolfZ commented Oct 17, 2018

Thank you for this PR.

I can see how this feature would be useful. However, I am not so sure about still dispatching the MarkAsDirtyAction when never is used. With change and blur the SetValueAction and MarkAsDirtyAction are always dispatched together (if the state is still pristine) because if there is no SetValueAction, then the form state is not really dirty, even if the HTML element is.

There is also the problem of when to dispatch the MarkAsDirtyAction with never. In your implementation you do it in the blur handler, but it could just as well be in the input handler.

Therefore, to prevent confusion I would like you to change the code to simply not dispatch either action if never is chosen. Please also update the documentation accordingly, i.e.

"It is possible to control when view value changes are pushed to the state with the ngrxUpdateOn attribute. The supported values are change (pushed immediately when the view value changes; default), blur (pushed when the form element loses focus), and never (the value is never pushed to the state; this is an advanced feature that is useful if you want full control over when and how the state is updated but it also requires greater understanding of how ngrx-forms performs state updates). Note that by changing this value to something different than change (and thereby changing the time at which value changes are pushed to the state) you are also changing the time at which validation and other state updates that depend on the value happen. If you change this value to never you will need to perform all state updates yourself (e.g. setting the value, marking as dirty etc.)."

@Mr-Eluzive
Copy link
Contributor Author

Mr-Eluzive commented Oct 18, 2018

Yeah you are right. I've already changed it and squashed into one commit (quickly from another computer via HTTPS so something with my username and avatar is wrong). Could you check if it's all right now, please?

Copy link
Owner

@MrWolfZ MrWolfZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please have a look at my comments. They are just small things, but they are important.

directive.ngrxUpdateOn = NGRX_UPDATE_ON_TYPE.NEVER;
});

it(`should not dispatch any even if the view value changed`, done => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The word action is missing here, i.e. should not dispatch any action even if the view value changed

@@ -64,7 +64,7 @@ A constant `NGRX_STATUS_CLASS_NAMES` is exported to allow accessing these class

#### Choosing when to sync the view to the state

It is possible to control when view values changes are pushed to the state with the `ngrxUpdateOn` attribute. The supported values are `change` (pushed immediately when the view value changes; default) and `blur` (pushed when the form element loses focus). Note that by changing this value to something different than `change` (and thereby changing the time at which value changes are pushed to the state) you are also changing the time at which validation and other state updates that depend on the value happen.
It is possible to control when view values changes are pushed to the state with the `ngrxUpdateOn` attribute. The supported values are `change` (pushed immediately when the view value changes; default), `blur` (pushed when the form element loses focus), and `never` (the value is never pushed to the state; this is an advanced feature that is useful if you want full control over when and how the state is updated but it also requires greater understanding of how ngrx-forms performs state updates). Note that by changing this value to something different than `change` (and thereby changing the time at which value changes are pushed to the state) you are also changing the time at which validation and other state updates that depend on the value happen. If you change this value to never you will need to perform all state updates yourself (e.g. setting the value, marking as dirty etc.).
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the documentation whenever I mention ngrx-forms, I make it bold. So to be consistent please change this to use **ngrx-forms**

src/control/directive.ts Show resolved Hide resolved
describe('ngrxUpdateOn "never"', () => {
beforeEach(() => {
directive.ngOnInit();
directive.ngrxFormControlState = { ...INITIAL_STATE, isTouched: true, isUntouched: false };
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary here since it leads to your additional check for the update on type not being executed. Just remove this line. The test should still work without it.

@Mr-Eluzive
Copy link
Contributor Author

Ok it looks like I've correct all your suggestions. Please check this again and let me know.

@MrWolfZ MrWolfZ merged commit ea0b284 into MrWolfZ:master Oct 21, 2018
@MrWolfZ
Copy link
Owner

MrWolfZ commented Oct 21, 2018

Sorry, for the delay. I am on vacation right now so there are bound to be some delays. However, I'll release a new version with this change right now.

Thank you again for this PR.

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.

3 participants