Where to keep the properties in below scenario?


#1

Case: I have two components which are upload dialog and progressbar. I have to share list of files to both components.

What I did is: I created a service and injected into both the components and used.

Problem: Once I finished all the process of upload and trying again to upload new files but the service properties are not reset even I destroyed all the components( upload dialog and progressbar ). I tried to destroy the service but it didn’t work out. I know that I shouldn’t use the service for this purpose but I don’t know the alternative.

So, I’m posting here to get the perfect solution.

Thanks in advance!


#2

If this isn’t state you need long lived, you might consider wrapping them with another component that holds the state instead of a service.

{{#x-foo as |list|}}
  {{x-bar files=list}}
  {{x-baz files=list}}
{{/x-foo}}

#3

I appreciate your help @jasonmit. But in my case, I should initialise the dialog component by script method(using util) and progress bar component initialisation part would be in application.hbs file. So, how could I implement this block form initialisation? If I cannot destroy the service object then, It would be great if I can get another solution to maintain those global variables in one place and that can be easily destroyable once the task completed.