kurko / ember-sync

MIT License
282 stars 28 forks source link

Setup per instructions, no online syncing happening #26

Closed csprocket777 closed 9 years ago

csprocket777 commented 9 years ago

While I had to use a different github repo to install this, I managed to get it installed and setup.

However when I create a record and save it, nothing is being transmitted to the server.

Here is my online-store.js initializer:

import DS from "ember-data";
import ENV from "recruiter/config/environment";

var CustomOnlineAdapter = DS.RESTAdapter.extend({
    host: ENV.apiHost
});

var OnlineStore = DS.Store.extend({
    adapterFor: function(type){
        return this.container.lookup('adapter:_custom_store');
    }
});

export function initialize(container, application ) {
    container.register('store:online', OnlineStore);
    container.register('adapter:_custom_store', CustomOnlineAdapter);

    application.inject('route',     'onlineStore', 'store:online');
    application.inject('controller','onlineStore', 'store:online');
}

export default {
  name: 'onlineStore',
  initialize: initialize
};

Here is my application route:

import Ember from 'ember';

export default Ember.Route.extend({
    init: function(){
        this._super();
        this.emberSync.set('offlineStore', this.store);
        this.emberSync.set('onlineStore', this.onlineStore);
        this.emberSync.synchronizeOnline();
    },

    model: function(){
        return this.emberSync.find('event');
    },

    setupController: function(controller, model){
    }
});

Now, in the application controller, doing:

this.emberSync.createRecord('event', { title: 'foo' }).save();

Only stores it locally, nothing is transmitted online.

I'm using your localstorage ember-cli addon for the local storage piece. And I'm using the built-in Ember-Data RESTAdapter for the online adapter.

kurko commented 9 years ago

Part of the discussion is at #22. It seems to be that some models associations are async and it's not working with that.

csprocket777 commented 9 years ago

I just updated the bower file for the library to using the latest ember-data (beta.14) and nearly all the tests are failing.

kurko commented 9 years ago

I just pushed to master using beta.14-1 and all tests are passing. Can you provide more details? On Sat, Jan 24, 2015 at 6:12 PM Chuck notifications@github.com wrote:

I just updated the bower file for the library to using the latest ember-data (beta.14) and nearly all the tests are failing.

— Reply to this email directly or view it on GitHub https://github.com/kurko/ember-sync/issues/26#issuecomment-71335180.

csprocket777 commented 9 years ago

Ok. sorry, I just updated with your latest and the tests now pass. I also installed the latest version into my app and it compiles now but I'm back to no online syncing. Going to try re-applying what you gisted yesterday.

csprocket777 commented 9 years ago

I applied the async fix but am now stuck again at only the first record persisting to the server and nothing else. Here's what I'm seeing in the console after turning on debug: screen shot 2015-01-24 at 2 55 01 pm

csprocket777 commented 9 years ago

So a promise fails in the "rollbackExistingRecord" function at this line: "this.onlineStore.unloadAll(recordType);".

The store won't unload a record while it's in the "root.loaded.created.inFlight" state. The job queue doesn't progress from there.

csprocket777 commented 9 years ago

:forehead smack: I should ensure my REST server is returning the proper response before filing bug reports. My apologies.

kurko commented 9 years ago

lol

It's fine bro :D