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

Signals enable me to implement my own ARC (Active Reference Counting) #53417

Closed
muhamedkarajic opened this issue Dec 7, 2023 · 5 comments
Closed

Comments

@muhamedkarajic
Copy link

muhamedkarajic commented Dec 7, 2023

Which @angular/* package(s) are relevant/related to the feature request?

No response

Description

Imagine that I have a global store like NgRx but where each key links to a Singal containing the state of the object. That store is global and multiple components can use the same object - you can imagine it like its firebase.

Now what I want is able to track how many components use the object, when the count go to 0 I want to wait a specific amount of time before GC-ing the signal, or I'll wait that the memory pressure of the hole app exceeds a specific limit cause of multiple reasons e.g. I have to destory the subscription between client and the server which is expensive while the user can need in the next few seconds the same object again.

I have already implemented the solution however I'm not able to implement it with Signals. I'm not capable to implement this with Signals cause you are not allowing me to overwrite the functions or letting me see the counter.

Proposed solution

Enable me to track how many times a singal is subscribed and unsubscribed - I know this is not the right terminology but I think the point which I want to do is clear.

Alternatives considered

None.

@muhamedkarajic muhamedkarajic changed the title Signals enable me to implement my own ACK Signals enable me to implement my own ARC (Active Reference Counting) Dec 7, 2023
@JeanMeche
Copy link
Member

Hi, I believe this is an issue you have already opened #51167 and was adressed in #50182.

@muhamedkarajic
Copy link
Author

Hi, I believe this is an issue you have already opened #51167 and was adressed in #50182.

You are right so if I understand correctly they just don't wanna allow this possibility cause its not what Singlas are in the Angular team oppinion deseigned for?

@pkozlowski-opensource
Copy link
Member

You are right so if I understand correctly they just don't wanna allow this possibility cause its not what Singlas are in the Angular team oppinion deseigned for?

Correct. Observing the act of subscribing / unsubscribing would make the signal read side-effectfull introducing the notion similar to "hot" vs. "cold" observables. This is not what signals are designed for. You might want to use a different reactive primitive for your use-cases.

@muhamedkarajic
Copy link
Author

You are right so if I understand correctly they just don't wanna allow this possibility cause its not what Singlas are in the Angular team oppinion deseigned for?

Correct. Observing the act of subscribing / unsubscribing would make the signal read side-effectfull introducing the notion similar to "hot" vs. "cold" observables. This is not what signals are designed for. You might want to use a different reactive primitive for your use-cases.

I was just trying to avoid it cause for me it means I have to have a Subject and then on top of that for each component I have to cast it into a signal, its at least 2N for memory or even MN. I guess I have then no choice.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jan 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants