PolymerElements / app-storage

Data-pipes and specialized services
61 stars 47 forks source link

<app-localstorage-document> always initialize with the default value despite the value has been stored #127

Closed andrewspy closed 2 years ago

andrewspy commented 6 years ago

Description

<app-localstorage-document> always initialize with the default value despite the value has been stored.

I have posted a related problem in stackoverflow - Ignore changes on default value in app-localstorage-document when data is stored

Expected outcome

Initialize with stored value. (i.e. undefined > 'stored')

Actual outcome

Initialize with default value, then update to stored value. (i.e. undefined > 'default' > 'stored')

Live Demo

N/A

Steps to reproduce

Below are the snippet

<app-localstorage-document
    key="data"
    data="{{data}}">
</app-localstorage-document>
class MyView extends Polymer.Element{
  static get is() {return 'my-view';}
  static get properties() {
    return{
      data:{
        type: String,
        value: 'default',
        observer: 'dataChanged',
      },
    };
  }

  storeData() {
    this.data = 'stored';
  }

  dataChanged(data, oldData) {
    console.log('dataChanged:', data, oldData);

    // TODO: Skip default dataChanged when data is stored.
  }
}

Browsers Affected

N/A

phidias51 commented 6 years ago

This may be due to a change that was made a while ago so that app-storage-behavior#isNew() return s true, rather than false. I'm in the process of updating an application and paper-input fields that are bound to firebase document objects, are turning blank now. So that a record that used to have data in it, is now getting cleared of data. This is really annoying. Oddly enough, fields bound to a paper-textarea are fine.