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

fix(store): call ngxsOnChanges whenever state changes (even through plugins) #1926

Merged
merged 4 commits into from
Nov 1, 2022

Conversation

arturovt
Copy link
Member

@arturovt arturovt commented Oct 19, 2022

Issue: #1567

@bundlemon
Copy link

bundlemon bot commented Oct 19, 2022

BundleMon

Files updated (2)
Status Path Size Limits
fesm5/ngxs-store.js
133.02KB (-86B -0.06%) 145KB / +0.5%
fesm2015/ngxs-store.js
113.88KB (-271B -0.23%) 125KB / +0.5%
Unchanged files (4)
Status Path Size Limits
fesm5/ngxs-store-operators.js
10.07KB 15KB / +0.5%
fesm2015/ngxs-store-operators.js
9.94KB 15KB / +0.5%
fesm5/ngxs-store-internals.js
6.58KB 20KB / +0.5%
fesm2015/ngxs-store-internals.js
5.65KB 20KB / +0.5%

Total files change -357B -0.12%

Groups updated (6)
Status Path Size Limits
@ngxs/store(umd.min)[gzip]
./bundles/*.umd.min.js
13.5KB (+53B +0.38%) +1%
@ngxs/store(umd)[gzip]
./bundles/*.umd.js
39.38KB (+46B +0.11%) +1%
@ngxs/store(fesm5)[gzip]
./fesm5/*.js
28.78KB (+39B +0.13%) +1%
@ngxs/store(fesm2015)[gzip]
./fesm2015/*.js
26.35KB (-13B -0.05%) +1%
@ngxs/store(esm5)[gzip]
./esm5/**/*.js
174.27KB (-212B -0.12%) +1%
@ngxs/store(esm2015)[gzip]
./esm2015/**/*.js
167.68KB (-271B -0.16%) +1%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@bundlemon
Copy link

bundlemon bot commented Oct 19, 2022

BundleMon (NGXS Plugins)

Unchanged files (28)
Status Path Size Limits
Plugins(umd)[gzip]
storage-plugin/bundles/ngxs-storage-plugin.um
d.js
7.47KB +1%
Plugins(umd)[gzip]
hmr-plugin/bundles/ngxs-hmr-plugin.umd.js
6.96KB +1%
Plugins(umd)[gzip]
websocket-plugin/bundles/ngxs-websocket-plugi
n.umd.js
6.87KB +1%
Plugins(umd)[gzip]
router-plugin/bundles/ngxs-router-plugin.umd.
js
6.5KB +1%
Plugins(umd)[gzip]
form-plugin/bundles/ngxs-form-plugin.umd.js
6.44KB +1%
Plugins(umd)[gzip]
devtools-plugin/bundles/ngxs-devtools-plugin.
umd.js
6.16KB +1%
Plugins(umd)[gzip]
logger-plugin/bundles/ngxs-logger-plugin.umd.
js
5.77KB +1%
Plugins(fesm5)[gzip]
storage-plugin/fesm5/ngxs-storage-plugin.js
4.17KB +1%
Plugins(fesm2015)[gzip]
storage-plugin/fesm2015/ngxs-storage-plugin.j
s
3.87KB +1%
Plugins(fesm5)[gzip]
hmr-plugin/fesm5/ngxs-hmr-plugin.js
3.62KB +1%
Plugins(fesm5)[gzip]
websocket-plugin/fesm5/ngxs-websocket-plugin.
js
3.53KB +1%
Plugins(fesm2015)[gzip]
hmr-plugin/fesm2015/ngxs-hmr-plugin.js
3.25KB +1%
Plugins(fesm5)[gzip]
router-plugin/fesm5/ngxs-router-plugin.js
3.15KB +1%
Plugins(fesm2015)[gzip]
websocket-plugin/fesm2015/ngxs-websocket-plug
in.js
3.15KB +1%
Plugins(umd.min)[gzip]
hmr-plugin/bundles/ngxs-hmr-plugin.umd.min.js
3.1KB +1%
Plugins(fesm5)[gzip]
form-plugin/fesm5/ngxs-form-plugin.js
3.07KB +1%
Plugins(fesm2015)[gzip]
router-plugin/fesm2015/ngxs-router-plugin.js
2.89KB +1%
Plugins(fesm5)[gzip]
devtools-plugin/fesm5/ngxs-devtools-plugin.js
2.83KB +1%
Plugins(fesm2015)[gzip]
form-plugin/fesm2015/ngxs-form-plugin.js
2.74KB +1%
Plugins(fesm2015)[gzip]
devtools-plugin/fesm2015/ngxs-devtools-plugin
.js
2.65KB +1%
Plugins(fesm5)[gzip]
logger-plugin/fesm5/ngxs-logger-plugin.js
2.48KB +1%
Plugins(umd.min)[gzip]
router-plugin/bundles/ngxs-router-plugin.umd.
min.js
2.48KB +1%
Plugins(umd.min)[gzip]
form-plugin/bundles/ngxs-form-plugin.umd.min.
js
2.43KB +1%
Plugins(fesm2015)[gzip]
logger-plugin/fesm2015/ngxs-logger-plugin.js
2.37KB +1%
Plugins(umd.min)[gzip]
storage-plugin/bundles/ngxs-storage-plugin.um
d.min.js
2.36KB +1%
Plugins(umd.min)[gzip]
websocket-plugin/bundles/ngxs-websocket-plugi
n.umd.min.js
2.18KB +1%
Plugins(umd.min)[gzip]
logger-plugin/bundles/ngxs-logger-plugin.umd.
min.js
1.95KB +1%
Plugins(umd.min)[gzip]
devtools-plugin/bundles/ngxs-devtools-plugin.
umd.min.js
1.86KB +1%

No change in files bundle size

Unchanged groups (6)
Status Path Size Limits
All Plugins(esm5)[gzip]
./-plugin/esm5/**/.js
118.45KB +1%
All Plugins(esm2015)[gzip]
./-plugin/esm2015/**/.js
113.2KB +1%
All Plugins(umd)[gzip]
./-plugin/bundles/.umd.js
46.17KB +1%
All Plugins(fesm5)[gzip]
./-plugin/fesm5/.js
22.85KB +1%
All Plugins(fesm2015)[gzip]
./-plugin/fesm2015/.js
20.92KB +1%
All Plugins(umd.min)[gzip]
./-plugin/bundles/.umd.min.js
16.36KB +1%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@bundlemon
Copy link

bundlemon bot commented Oct 19, 2022

BundleMon (Integration Projects)

Files updated (3)
Status Path Size Limits
Main bundles(Gzip)
hello-world-ng13-ivy/dist-integration/main.(h
ash).js
69.49KB (+43B +0.06%) +1%
Main bundles(Gzip)
hello-world-ng11-ivy/dist-integration/main.(h
ash).js
70.83KB (+38B +0.05%) +1%
Main bundles(Gzip)
hello-world-ng12-ivy/dist-integration/main.(h
ash).js
67.54KB (+20B +0.03%) +1%
Unchanged files (1)
Status Path Size Limits
Main bundles(Gzip)
hello-world-ng14-ivy/dist-integration/main.(h
ash).js
65.12KB +1%

Total files change +97B +0.03%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

Copy link
Member

@markwhitfeld markwhitfeld left a comment

Choose a reason for hiding this comment

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

I like this approach. It is much cleaner, and keeps this logic quite isolated to one place.
A subtle side effect of this change would be that previously the ngxsOnChanges would have been called before the state is actually set on the root BehaviorSubject, and now it is called in response to the change in the root behavior subject.
I think that this is ok, and perhaps more logical if the user was to ever get a snapshot of the state from within this function.

I also see that due to the fact that this is literally the very first subscription that connects to a state as it is initialised it will in the majority of cases still honour the contract of being the first thing that is called. After this change, the only situation where another selector for that state would be called before this function is if the state is lazy loaded as part of a feature and a selector is set up before the state is loaded and initialised. While this is a subtle side effect of the change I don't think that it has enough impact to merit concern. One should really not be using the ngxsOnChanges hook for major logic and especially not logic that would change the same feature state.

@arturovt arturovt added this to the v3.7.6 milestone Oct 26, 2022
@codeclimate
Copy link

codeclimate bot commented Oct 26, 2022

Code Climate has analyzed commit 5503495 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 96.7% (0.0% change).

View more on Code Climate.

@arturovt arturovt marked this pull request as ready for review October 26, 2022 18:32
Copy link
Member

@markwhitfeld markwhitfeld left a comment

Choose a reason for hiding this comment

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

Excellent work!!!

@markwhitfeld markwhitfeld merged commit f9549a3 into master Nov 1, 2022
@markwhitfeld markwhitfeld deleted the fix/1567 branch November 1, 2022 19:56
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Nov 29, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@ngxs/form-plugin](https://github.com/ngxs/store) | dependencies | patch | [`3.7.5` -> `3.7.6`](https://renovatebot.com/diffs/npm/@ngxs%2fform-plugin/3.7.5/3.7.6) |
| [@ngxs/storage-plugin](https://github.com/ngxs/store) | dependencies | patch | [`3.7.5` -> `3.7.6`](https://renovatebot.com/diffs/npm/@ngxs%2fstorage-plugin/3.7.5/3.7.6) |
| [@ngxs/store](https://github.com/ngxs/store) | dependencies | patch | [`3.7.5` -> `3.7.6`](https://renovatebot.com/diffs/npm/@ngxs%2fstore/3.7.5/3.7.6) |

---

### Release Notes

<details>
<summary>ngxs/store</summary>

### [`v3.7.6`](https://github.com/ngxs/store/blob/HEAD/CHANGELOG.md#&#8203;376-2022-11-23)

[Compare Source](ngxs/store@v3.7.5...v3.7.6)

-   Performance: Run change detection once for all `Actions` subscribers once the stream emits [#&#8203;1939](ngxs/store#1939)
-   Fix: Use `isObservable` to test whether actions return an observable [#&#8203;1925](ngxs/store#1925)
-   Fix: Call `ngxsOnChanges` whenever state changes (even through plugins) [#&#8203;1926](ngxs/store#1926)
-   Fix: Do not delegate errors to `ErrorHandler` if users catch them manually [#&#8203;1927](ngxs/store#1927)
-   Fix: Complete `Actions` stream once root view is removed [#&#8203;1933](ngxs/store#1933)
-   Fix: Storage Plugin - Do not skip deserialization for keys with dot notation [#&#8203;1924](ngxs/store#1924)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC40MC4wIiwidXBkYXRlZEluVmVyIjoiMzQuNDAuMiJ9-->

Co-authored-by: cabr2-bot <[email protected]>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1659
Reviewed-by: Epsilon_02 <[email protected]>
Co-authored-by: Calciumdibromid Bot <[email protected]>
Co-committed-by: Calciumdibromid Bot <[email protected]>
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.

2 participants