Session constant in Polymer 1.0

I have two elements that are not directly related (no host child relationships). I want to share some information between them as two way data binding is not optimal. I was thinking about persistent session variables (in Meteor for example), is there something similar in Polymer 1.0? If not, can anyone please call me a viable solution.

Edit:

I just found out about iron signals , but the documentation states that it should be avoided, can someone explain why it should be avoided? I would also appreciate it if someone could write an example using this example.

Edit:

I discussed this with the Polymer team at the 2015 Polymer Summit. This was part of the big question of how to structure my application. They spoke at the summit about the mediator template. I recommend watching the talk from the top and visiting the code on Github .

+3


source to share


4 answers


For some coded examples using <iron-signals>

you can check out this Stack Overflow question and its answers .

This is not as difficult as it seems at first glance. Check out this documentation and this demo .



This is a simple two step process:

  • Fire the event iron-signal

    like this:

    this.fire('iron-signal', {name: 'hello', data: 'kitty'});

  • Listen to the event iron-signal

    with the same name (in this case hello

    ). Like this:

    <iron-signals on-iron-signal-hello="doSomething"></iron-signals>

+1


source


Recently I just looked at iron signals. It is useful for communication between loosely coupled distance components. It provides event bus functionality. I suppose the warning you see in the iron signals documentation ("Note: avoid using iron signals when you can use the controller (parent) to mediate instead.") Is to prevent overuse in simple cases where normal polymer binding properties will do the job. In the context of a comment included in the hardware signaling documentation, the parent ("controller") is the binding scope for the child transmitters.



Also, iron signals have nothing to do with session constant variables. There are two separate questions here.

+2


source


I just found this video (I linked to the exact minute and second where the concept is explained) that explains exactly the effect I want.The main difference between the answers posted by Mowzer is that you end your whole application in a template and accessing attributes through observers, which is a much simpler concept when you get it. I think the video is just clear, so I won't explain it here.

+2


source


Also, here is another related question and answer with examples of working codes. Only they refer to <iron-meta>

and <iron-local-storage>

.

+1


source







All Articles