Skip to content

puzzled about local storage adapter behaviour #86

@st-h

Description

@st-h

I have created a few test cases to find out how the local storage adapter works:
I also tried creating a twiddle, but failed with a Namespace error in ember-graph, so here are the classes:

adapters/persistent-token.js:

export default EG.LocalStorageAdapter.extend({

});

models/persistent-token.js:

export default EG.Model.extend({
  token: EG.attr({ type: 'string' })
});

If I call in an action in route/application.js:

this.get('store').pushPayload({persistentToken: [{id: 'testPush', token: 'test1'}]})

and then:

this.get('store').find('persistentToken', 'testPush').then(function(token) {
        if (!token) {
          console.log('no token');
          return;
        }
        console.log('token: ' +  token + ' id: ' + token.get('id') + ' val: ' + token.get('token'));
      }, function(error) {
        console.error('failed to find token: ' + JSON.stringify(error))
      })

The token is retrieved as expected

token: <testapp@model:persistent-token::ember758> id: testPush val: test1

If I reload the page and call the above function to retrieve the token again, I receive the following error:

failed to find token: {"status":404,"typeKey":"persistentToken","id":"testPush"}

I do not see any entry in chrome's local storage resource. And the data is lost after a reload of the page

Trying to use the save method to persist the token:

      var version = this.get('store').createRecord('persistentToken', {
        id: 'testSave',
        token: 'test2'
      });
      version.save();

and retrieving it with a similar function:

      this.get('store').find('persistentToken', 'testSave').then(function(token) {
        if (!token) {
          console.log('no token');
          return;
        }
        console.log('token: ' +  token + ' id: ' + token.get('id') + ' val: ' + token.get('token'));
      }, function(error) {
        console.error('failed to find token: ' + JSON.stringify(error))
      })

The token is not found. Output is:

failed to find token: {"status":404,"typeKey":"persistentToken","id":"testSave"}

However, an entry to the local storage resource has been added. A find all shows that the id has been automatically assigned, even though one had been provided:

this.get('store').find('persistentToken').then(function(token) {
        if (!token) {
          console.log('no token');
          return;
        }
        token.forEach(function(t) {
          console.log('token: ' +  t + ' id: ' + t.get('id') + ' val: ' + t.get('token'));
        })
      }, function(error) {
        console.error('failed to find token: ' + JSON.stringify(error))
      })

leads to output:

token: <testapp@model:persistent-token::ember774> id: 1143a7b2-9334-4480-8ab0-01ee8d1d798d val: test2

If the page is reloaded, the token still is there. However, it is difficult to remember an automatically assigned id between reloads and I think this mainly defeats the purpose.

Am I doing anything wrong, or are these bugs?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions