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

fn.bind(this) defeats the memoizing #2

Open
jcairney opened this issue Apr 29, 2019 · 1 comment
Open

fn.bind(this) defeats the memoizing #2

jcairney opened this issue Apr 29, 2019 · 1 comment

Comments

@jcairney
Copy link

Hi, thanks for sharing this pipe. It's very useful.

In my testing I've found that if you use .bind(this) as the fn input for the pipe, the function value is treated as a new function each time because .bind() is called creating a new wrapper function during each change detection cycle. As a result, the bound method is called on every change detection cycle, not just when inputs change. This defeats the memoizing of the pipe.

Although it's still a valid technique for fixing the 'this' of the fn function, I feel the README.md file should point out the pitfall of doing it that way when you've provided a better alternative. (the context parameter). Well done on the context parameter by the way, as I've seen articles by other prolific Angular devs where they have struggled to find an elegant solution.

@ArtemLanovyy
Copy link
Owner

@jcairney Thanks for Your investigation! 👍
You are right regarding bind method and new function as an output. I will update README regarding that pitfall.

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

No branches or pull requests

2 participants