suppose I want to have a data provider element for my user, like
<user-data-provider user-data="{{data}}"></user-data-provider>
which sends an ajax request and gets the logged in user.
Suppose I want to access my user data in different pages, and I add this tag to wherever I need, but the problem is, every time the browser sees this tag, makes an ajax again and I have to wait until data is fetched!
I know I can make a variable in my main page and pass it along child pages, but that seems like overkill to me !
how can I persist user data across different pages and part of my app?
thank you in advance
2 Answers
Answers 1
There are different ways to do this.
- You can use use a monostate pattern
- You can have one instance of your
user-data-provider
element in your root element or index.html and use iron-signals to transmit the data to all other elements that want to consume it - You can use iron-meta to have global state
- Use an external state management framework (i.e. redux). There is a polymer wrapper for it: polymer-redux
I would recommend using an external state mangement framework such as redux.
Some of the solutions are shown here:
Answers 2
I used pouchdb for my data store, and used polymer's predefined elements to work with it
now every time that I need data, I just use that component
0 comments:
Post a Comment