Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

data persistence across elements

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

like image 657
Developerium Avatar asked Aug 30 '16 05:08

Developerium


People also ask

What is the meaning of data persistence?

Persistence is "the continuance of an effect after its cause is removed". In the context of storing data in a computer system, this means that the data survives after the process with which it was created has ended.

What are the types of persistence?

There are two types of persistence: object persistence and process persistence, whereby persistent objects and processes continue to exist even after their parent processes are killed or shut down. Process persistence is achieved by storing core system processes in non-volatile, persistent storage.

What is persistent data model?

In computing, a persistent data structure or not ephemeral data structure is a data structure that always preserves the previous version of itself when it is modified.

What is meant by data persistence in flutter?

:] In order to avoid frustrating users, your app needs to save data that survives an app restart. Saving app data to some type of storage that survives app restarts is called data persistence. In this Flutter tutorial, you'll: Build an Alchemy-themed shopping app that persists data on different levels.


1 Answers

There are different ways to do this.

  1. You can use use a monostate pattern
  2. 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
  3. You can use iron-meta to have global state
  4. 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:

Polymer 1.0 Global Variables

like image 65
Ümit Avatar answered Sep 27 '22 20:09

Ümit