-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add a form management feature to a signal store #45
Comments
Hello, that sounds very interesting, and we should dig deeper here. Some initial thoughts:
Last question: Who's going to implement it? :) |
Hello, thanks for your feedback.
I was thinking to a directive because it looked to be the simplest place to make the link between the formGroup and the store. Also, it required few changes in the template and no change in the component, but maybe the setter approach is simplest at the end. The logic in the directive to handle the form change / path it + calling store methods to patch the state should also works in the feature itself? A generated method
I looked for news about this but the roadmap and the approach is not clear to me. At the end the angular approach will not be related to ngrx signal store so the feature looks to be relevant to me for developers that will use ngrx signal store.
I didn't consider this way but you are right the DeepWritableSignal could change the game
I looked this project but there is nothing related to side effect management and also the declaration for each input implies more changes in the templates. I got a first implementation (poc) but with all the form + state management logic in the directive, not in the feature itself. |
I confirm that your idea of using a setter to pass the formGroup to a feature method works ;) ngOnInit(): void {
this.store.setMySearchFormGroup(this.mySearchForm, this.store);
} The reason is that the accessible store in the context of the feature method is the temp store, containing only methods already declared/generated before the call to the |
I do have an idea but I'm not sure if it is a good one :) I was thinking of initialzing the signalStore with a dummy |
Hi, the access error is more on methods required by the feature that are declared after rather than the formGroup object. I also create the PR if you want to have a look on the draft. |
When using complex forms in Angular, it could be convenient to handle the form management with a dedicated store feature.
Some commons scenarios where adding a withForm() feature to a signal store could be useful:
withSync()
feature to the form state could be saved in the localStorageTo connect the form to the store, a dedicated form directive should be used.
The approach could look like this:
In template, using the
appSignalStoreForm
directive :In the component, nothing required except the store:
In the store, declaring the
withForm
feature and the requiredcomputed
andmethod
:Let me know if you think this is feature could be relevant for the project.
The text was updated successfully, but these errors were encountered: