Skip to content

Conversation

@svenson95
Copy link
Contributor

@svenson95 svenson95 commented Mar 28, 2024

Here is a new proposal for a challenge. For me it's a interesting topic and after the pipe challenges, i delved a little bit deeper into the topic. So i found this article about It’s ok to use function calls in Angular templates and tried it out myself. In my opinion this is a nice extension to the @Pipe() challenges.

This is a first draft, so be encouraged to suppose changes or ideas for the challenge project. My initial idea is to prepare a function - to format a date - which is called in the template. The goal of the challenge would be refactor this function with a memo function.

I'm also thinking about whether I should somehow display in the UI how often the function or pipe is called - before and after. For example, by creating an element each time the function is called and putting it into an array. To visualize the improvement.

@tomalaforge
Copy link
Owner

Hey @svenson95, I can see you are back to a new challenge.

I'll look more in-depth tomorrow but warning, memo is useless now that computed is present. So I won't create a challenge on this utility function. The article of enea is great but deprecated

@svenson95
Copy link
Contributor Author

Okay, we could also mention that since v17 with computed this memo approach is unnecessary. But maybe for some people, who have to work with angular below v17, this can be useful to know.

@jdegand
Copy link
Contributor

jdegand commented Mar 29, 2024

This article and this article could be of interest.

Few thoughts if you want to rework the concept of the challenge:

  • You could shift to an Impure pipe challenge. See this article. Problem would be that there really isn't much to cover.
  • If you want to shift the focus to computed, a challenge could focus on conditionals inside computed functions. If you have a ternary with multiple signals, unexpected results can occur. Or even an effect vs computed challenge.

@tomalaforge
Copy link
Owner

I'm sorry @svenson95, but I don't see the benefits of this challenge. There is no real added value and people should focus on using Pipe instead of useMemo.
useMemo has side effects if used multiple times inside a template and you will not lose a lot of performance by just calling the function inside your template.
I would rather focus on creating challenges about signal, and all signal inputs, outputs, and so on.
Signal is very new and lots of people struggle with it.

I like the idea of @jdegand about the computed function with a ternary inside. Or maybe create a challenge where we need to use the untrack function.

What do you think?

@svenson95
Copy link
Contributor Author

No problem at all. That's why i first started only the article but not the challenge. I wasn't sure if that's a good challenge, it was just interesting for me. Challenges about signals sounds more interesting though, so i'll work on that. This PR can be closed, i will open up a new one.

@tomalaforge tomalaforge closed this Apr 2, 2024
@tomalaforge tomalaforge added the invalid solution is not working correctly label May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid solution is not working correctly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants