Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persistent session variable in Polymer 1.0

I have two elements that are not directly connected (no host child relationship). I want to share some information between them as two-way data binding is not optimal. I thought about persistent session variables (like that exist in Meteor), is there is something like that in Polymer 1.0? If not, can somebody refer me to a viable solution.

Edit:

I just found out about iron-signals but the documentation states that it should be avoided, can somebody explain why it should be avoided? I would also appreciate it if somebody wrote an example of how to use it through an example.

Edit:

I discussed this question with the Polymer team in the Polymer Summit 2015. It was a part of a larger question, how to structure my app. They spoke in the summit about the mediator pattern. I recommend watching the talk from the summit and visiting the code in Github.

like image 582
Salah Saleh Avatar asked May 27 '26 13:05

Salah Saleh


2 Answers

I just looked at iron-signals myself recently. It is useful for communication between loosely coupled distance components. It provides an "event bus" type functionality. I believe the warning you see in the iron-signals documentation ("Note: avoid using iron-signals whenever you can use a controller (parent element) to mediate communication instead.") is to prevent over-use in simple cases where ordinary Polymer property binding would do the job. In the context of the comment included in the iron-signals documentation, the parent element (the "controller") is the binding scope for the communicating child elements.

Also, iron-signals, has nothing to do with persistent session variables. Two separate issue there.

like image 152
jptknta Avatar answered May 30 '26 11:05

jptknta


I just found this video (I linked to the exact minute and second where the concept is explained) which explains exactly the effect that I want. The Key difference between the answers posted by Mowzer is that you wrap the whole of your application in a template and access the attributes through observers which is a much easier concept once you get it. I think the video is straight forward to understand, so I will not go to much explanations here.

like image 41
Salah Saleh Avatar answered May 30 '26 10:05

Salah Saleh