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

feat: switch to signal inputs #157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arturovt
Copy link
Contributor

@arturovt arturovt commented Jul 4, 2024

No description provided.

Copy link

stackblitz bot commented Jul 4, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@arturovt arturovt marked this pull request as ready for review July 7, 2024 11:11
@frezo00
Copy link

frezo00 commented Sep 9, 2024

@arturovt Isn't (one of) the purpose of signals to avoid using the ngOnChanges life-cycle hook?
Also, some predefined initial values for non-required inputs would be nice to add, especially for boolean values as the undefined seems as an invalid type.

@arturovt
Copy link
Contributor Author

arturovt commented Sep 9, 2024

I haven’t heard of avoiding ngOnChanges. If an effect running on a signal change may internally update some other signals, this will lead to a runtime error, or capture other signals being read.

@frezo00
Copy link

frezo00 commented Sep 9, 2024

Please, read Netanel's article about signal inputs: https://netbasal.com/revolutionizing-angular-introducing-the-new-signal-input-api-d0fc3c8777f2
There is a top highlight saying:

This update eliminates the need for the ngOnChanges lifecycle hook, as computed properties now automatically update with input changes.

Therefore, many of those protected properties, that are being initialized inside the ngOnChanges can be computed from the corresponding input signals.
With that reactive approach, we can reduce a lot of side effects and have less code written with the same functionalities.

@NetanelBasal
Copy link
Member

@frezo00 eliminates !== avoid

@frezo00
Copy link

frezo00 commented Sep 9, 2024

Sure, my mistake in the first comment, should have used another verb 😅
But generally, the current ngOnChanges logic could be replaced with the usage of the computed signals (mostly) and the effect in the constructor (for side effects).
For example, the this.props is an ideal candidate for a computed signal which is not added in 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