genkgo / ember-localforage-adapter

Offline usage for Ember Data, based on localstorage adapter, but now uses Mozilla's localforage as data source
Other
133 stars 26 forks source link

Got serializer.pushPayload is not a function while trying to pushPayload #38

Closed sakozz closed 5 years ago

sakozz commented 9 years ago

Hi guys, I come to a case where i need to fetch data in online-mode, store on device and then use in offline-mode. I used normal ajax call, received JSON data and tried to push to store as follows.

var _this = this; 
Ember.$.ajax(apiEndpoint, 'GET').then(function(result) {
    result.forEach(function (item) {
         _this.store.pushPayload('user', item);
    });      
})

This ends up with error message "Uncaught TypeError: serializer.pushPayload is not a function" . Am i missing something or anyway i can use this ad-on for this case? Thanks for Help in advance.

frederikbosch commented 9 years ago

No, you are right. It is not a bug, rather a missing feature. But I experimented with this today. Have a look at the pushPayload method inside the rest adapter. Copy it to your serializer in app/serializers/application.js, you will probably receive an error from modelNameFromPayloadKey because that method does not (yet) exists in the localforage adapter. Replace it, and then you should be fine. If you succeed, you could create a PR so we all can use it. I also might invest some time in the issue.

frederikbosch commented 9 years ago

@sunil-shrestha Forgot to mention an important detail. I believe that pushPayload does not store data in the adapter. It only pushes records in the store. Please check for yourself to be sure.

In order to push data into localforage, you can call adapterFor('user') on the store and then with the adapter call the persistData method in the localforage adapter

sakozz commented 9 years ago

Thanks, i guess, i am looking for something like persistData method. I will try this and let you know.