-
Notifications
You must be signed in to change notification settings - Fork 403
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(signals): provide @ngxs/signals
package with signals utilities
#2141
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 0c0c064. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 5 targetsSent with 💌 from NxCloud. |
BundleMon (Integration Projects)Unchanged files (2)
No change in files bundle size Final result: ✅ View report in BundleMon website ➡️ |
962a2ef
to
49c8baf
Compare
@ngxs/signals
package with signals utilities
There are 3 utilities: select, produceActions, and produceSelectors select:
produceActions/produceSelectors: Allow users to quickly adapt ngxs store to @ngrx/signals (signalStore). We can provide the following recipes in the documentation:
Usage:
|
49c8baf
to
2308a9e
Compare
// There's no reason to call the following function with an empty object as | ||
// `produceActions({})` or `produceSelectors({})`. We should prevent invalid | ||
// or incorrect use cases. | ||
export type RequireAtLeastOneProperty<T> = keyof T extends never ? never : T; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we're using type-fest, you can use NonEmptyObject
import { ActionDef, Store } from '@ngxs/store'; | ||
import { Observable } from 'rxjs'; | ||
|
||
import { RequireAtLeastOneProperty } from './types'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import type { NonEmptyObject } from 'type-fest';
import { Signal, inject } from '@angular/core'; | ||
import { Store, TypedSelector, ɵSelectorReturnType } from '@ngxs/store'; | ||
|
||
import { RequireAtLeastOneProperty } from './types'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import type { NonEmptyObject } from 'type-fest';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this is a really great, simple utility. Nicely done!
Just needs docs ❤️
2308a9e
to
d111778
Compare
questions:
|
I think we can leave this utility function out for the first release of this. WDYT? |
I think the utility function is super helpful, is inline with direction of replacing decorators with functions, and times nicely with the latest signal queries:
If we're looking to deprecate |
995e18f
to
5c7f03e
Compare
This makes me so happy!!! There has been a lot of discussions about the naming of this utility, and I have always wanted to have it as |
Just a subtle naming discussion point... |
And, if we have a |
Given my last 2 questions, it leads me to ask: |
I did start to discuss with Artur.
|
Maybe |
Since the function is generating dispatch functions rather than actions themselves a more appropriate name could be |
I like If so, then what would that mean for the |
dispatch should go in core, I think
dispatch should definitely go in core, not sure about producer, but makes sense to question it |
In terms of naming, we have a few options:
|
I suggested toSelectMap and toDispatchMap, bc of the rxjs-interop naming convention |
I think I prefer |
i'm fine with it too. so do we go with |
Sorry I only saw the discussion now. Definitely the content of this PR is awesome, thanks Arthur for all the work. I was wondering if we should align with the terminology we already have for the selector utilities. See https://www.ngxs.io/advanced/selector-utils I'm okay with the proposed naming also, I'm just wondering if we want to create more context for similar functionality |
Awesome PR! I think I like the
@markwhitfeld back in the RFC we discussed that it will be |
Great work @arturovt! Having said that, I would vote for the naming convention |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! So it looks like we have consensus on select
, createSelectMap
and createDispatchMap
.
We are just missing tests for createDispatchMap
in this PR.
The one other thing to be settled is the inclusion of the dispatch
utility, and if both the dispatch utilities should exist in the @ngxs/signals
package, or in the @ngxs/store
package.
Thoughts? @rhutchison @Carniatto @arturovt @joaqcid @dmitry-stepanenko @profanis
dispatch utility in separate PR #2143 I am not sure where createDispatchMap should land, but I'm leaning to say keep where it is bc of the use-case with ngrx/signals (signalStore) |
We can continue the discussion in a separate pull request related to the |
I believe it's ready to merge |
Merged. Can address any issues in subsequent PRs. |
I think we should include the |
No description provided.