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

test(store): ensure state writes are allowed with fire & forget #2241

Merged
merged 1 commit into from
Dec 24, 2024

Conversation

arturovt
Copy link
Member

No description provided.

Copy link

nx-cloud bot commented Oct 25, 2024

View your CI Pipeline Execution ↗ for commit e3d1ce6.

Command Status Duration Result
nx run-many --target=test --all --configuration... ✅ Succeeded 2m 13s View ↗
nx run-many --target=lint --all --exclude=creat... ✅ Succeeded 5s View ↗
nx lint-types store ✅ Succeeded <1s View ↗
nx run-many --target=build --all ✅ Succeeded 1m 28s View ↗

☁️ Nx Cloud last updated this comment at 2024-12-24 17:57:02 UTC

Copy link

pkg-pr-new bot commented Oct 25, 2024

Open in Stackblitz

@ngxs/devtools-plugin

npm i https://pkg.pr.new/@ngxs/devtools-plugin@2241

@ngxs/form-plugin

npm i https://pkg.pr.new/@ngxs/form-plugin@2241

@ngxs/hmr-plugin

npm i https://pkg.pr.new/@ngxs/hmr-plugin@2241

@ngxs/router-plugin

npm i https://pkg.pr.new/@ngxs/router-plugin@2241

@ngxs/storage-plugin

npm i https://pkg.pr.new/@ngxs/storage-plugin@2241

@ngxs/store

npm i https://pkg.pr.new/@ngxs/store@2241

@ngxs/websocket-plugin

npm i https://pkg.pr.new/@ngxs/websocket-plugin@2241

commit: e3d1ce6

Copy link

bundlemon bot commented Oct 25, 2024

BundleMon

Unchanged files (6)
Status Path Size Limits
fesm2022/ngxs-store.mjs
104.68KB 105KB / +0.5%
fesm2022/ngxs-store-internals.mjs
11.54KB 13KB / +0.5%
fesm2022/ngxs-store-internals-testing.mjs
6.8KB 7KB / +0.5%
fesm2022/ngxs-store-operators.mjs
6.22KB 7KB / +0.5%
fesm2022/ngxs-store-plugins.mjs
2.38KB 3KB / +0.5%
fesm2022/ngxs-store-experimental.mjs
574B 2KB / +0.5%

No change in files bundle size

Unchanged groups (1)
Status Path Size Limits
@ngxs/store(fesm2022)[gzip]
./fesm2022/*.mjs
31.88KB +1%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

Copy link

bundlemon bot commented Oct 25, 2024

BundleMon (NGXS Plugins)

Unchanged files (9)
Status Path Size Limits
Plugins(fesm2022)[gzip]
storage-plugin/fesm2022/ngxs-storage-plugin.m
js
3.98KB +0.5%
Plugins(fesm2022)[gzip]
router-plugin/fesm2022/ngxs-router-plugin.mjs
3.02KB +0.5%
Plugins(fesm2022)[gzip]
hmr-plugin/fesm2022/ngxs-hmr-plugin.mjs
2.61KB +0.5%
Plugins(fesm2022)[gzip]
websocket-plugin/fesm2022/ngxs-websocket-plug
in.mjs
2.57KB +0.5%
Plugins(fesm2022)[gzip]
form-plugin/fesm2022/ngxs-form-plugin.mjs
2.46KB +0.5%
Plugins(fesm2022)[gzip]
devtools-plugin/fesm2022/ngxs-devtools-plugin
.mjs
2.15KB +0.5%
Plugins(fesm2022)[gzip]
logger-plugin/fesm2022/ngxs-logger-plugin.mjs
2.01KB +0.5%
Plugins(fesm2022)[gzip]
storage-plugin/fesm2022/ngxs-storage-plugin-i
nternals.mjs
861B +0.5%
Plugins(fesm2022)[gzip]
router-plugin/fesm2022/ngxs-router-plugin-int
ernals.mjs
396B +0.5%

No change in files bundle size

Unchanged groups (1)
Status Path Size Limits
All Plugins(fesm2022)[gzip]
./-plugin/fesm2022/.mjs
20.01KB +0.5%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

Copy link

bundlemon bot commented Oct 25, 2024

BundleMon (Integration Projects)

Files added (1)
Status Path Size Limits
Main bundles(Gzip)
hello-world-ng19/dist-integration/browser/mai
n-(hash).js
+66.35KB +1%
Files removed (3)
Status Path Size Limits
Main bundles(Gzip)
hello-world-ng18/dist-integration/browser/mai
n-(hash).js
-70.1KB +1%
Main bundles(Gzip)
hello-world-ng17/dist-integration/main.(hash)
.js
-68.24KB +1%
Main bundles(Gzip)
hello-world-ng16/dist-integration/main.(hash)
.js
-67.3KB +1%

Total files change -139.3KB -67.74%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

Copy link

codeclimate bot commented Oct 25, 2024

Code Climate has analyzed commit b256490 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 95.4% (0.0% change).

View more on Code Climate.

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 believe that the expected behaviour should be as follows...
(this is assuming that cancelUncompleted: true is present)

  • If the fire and forget action is left to run without a new action coming in, then it should be allowed to do as many writes to the context that it needs to (ie. the StateContext remains writeable)
  • but as soon as a second action comes in then the previous StateContext should become noop'ed so that it is no longer writeable.

Please add test cases to demonstrate both of these expected behaviours.

@arturovt
Copy link
Member Author

I'm afraid that might be difficult to implement. With your second approach, we would need to manually subscribe to the canceled observable:

const canceled = dispatched$.pipe(ofActionDispatched(action));

canceled.subscribe(() => {
  stateContext.setState = noop;
  stateContext.patchState = noop;
});

That is actually possible, but we need to unsubscribe from the canceled observable. However, the exact point at which we need to unsubscribe is unknown - perhaps when the action handler completes?

With the fire-and-forget approach, we never know if the action is still executing any functionality or when that functionality completes.

@markwhitfeld
Copy link
Member

markwhitfeld commented Oct 29, 2024 via email

@arturovt
Copy link
Member Author

arturovt commented Oct 30, 2024

My thoughts that fire-and-forget actions should not be cancellable. Instead, it should be the user’s responsibility to manage their cancellation by returning an observable, rather than subscribing to an observable and 'forgetting' it. I’d prefer not to capture previous state contexts because, if the fire-and-forget action never resolves, we wouldn't know when to release a reference to the previous state context.

@arturovt arturovt merged commit fbc4fdb into master Dec 24, 2024
3 checks passed
@arturovt arturovt deleted the test/fire-forget branch December 24, 2024 17:51
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