Skip to content

Constant Model ID Results in Duplicate Local Storage Values #152

@ohnnyj

Description

@ohnnyj

I've read in other comments to another issue that this library wasn't necessary intended to work with single models which might be why I am seeing this issue.

I have a model with a static / constant id, 'settings'.

Each time I make a change to the attributes of my settings object I do a model.save. Each save appends a new 'settings' value to the current local storage value.

example:

first save creates two local storage entries:

settings -> settings
settings-settings -> json object

next save:

settings -> settings,settings
settings-settings -> json object

next save:

settings -> settings,settings,settings
settings-settings -> json object

etc.

I've changed the save method to look at the value before setting which seemed to work but not sure if this will break something else:

  save: function() {
    var records = this.records.join(',');
    var value = this.localStorage().getItem(this.name);
    if(!value || records.indexOf(value) === -1) {
      this.localStorage().setItem(this.name, records);
    }
  },

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions