Giter Site home page Giter Site logo

Comments (9)

kurko avatar kurko commented on May 18, 2024

I think your code is wrong.

export default Ember.Route.extend({
  model: function () {
    return this.emberSync.find('user', '2oj9m');
  },

  actions: {
    save: function () {
      // do something cool
      this.get('content').emberSync.save();
    }
  }
});

You need to read Ember.js' guide about what this.get('content') is. I'm closing this, if you have other problems, let us know.

from ember-sync.

codepreneur avatar codepreneur commented on May 18, 2024

If after loading application I do this in the console:

var route = Ember.Namespace.NAMESPACES_BY_ID[''].__container__.lookup('route:index');

I get:

Class {routeName: "index", _names: Array[0], context: Class, currentModel: Class, controller: Class…}

then, when I type this:

var user = route.emberSync.createRecord('user', {name:'kurko'})

I get this:

Class {id: "8tp85", store: Class, container: Container, _changesToSync: Object, _deferredTriggers: Array[0]…}

and then when I type this:

user.emberSync.save()

I get this:

Class {__ember1412872464239: null, __nextSuper: undefined, __ember_meta__: Object, constructor: function, _super: function…}

Then I go to my firebase dashboard and I see that nothing has been added...

However, this: route.emberSync.find('user', '2oj9m') works fine and returns a promise

https://github.com/codepreneur/embersync-localforage-example

from ember-sync.

csprocket777 avatar csprocket777 commented on May 18, 2024

@codepreneur did you find a solution to this? I'm running into a similar issue myself.

from ember-sync.

kurko avatar kurko commented on May 18, 2024

@codepreneur @csprocket777 I really don't have a way to debug this, but I'll be helping you with whatever I can. Can you perhaps put some debugger; here and there and see what's going on?

Basically, if your Firebase adapter is similar to RESTAdapter/LSAdapter or any Ember compatible adapter, it'll be called according to that interface and it should work. If it works for RESTAdapter and not for Firebase, there's a possibility that your Firebase adapter is broken somehow because nothing is done on EmberSync side, except calling these adapters.

I've been using with ember-json-api (online) and ember-local-storage-adapter (offline) and it works fine.

from ember-sync.

csprocket777 avatar csprocket777 commented on May 18, 2024

For the record, here are my versions:

Ember: 1.9.1
Ember-Data: 1.0.0-beta.14
Handlebars: 2.0.0
jQuery: 2.1.3

I'm using the default REST adapter and the LocalStorage Ember-CLI add-on (kurko)

So I've been diving into the code to see if I can pin point where my issue is.

So far I've narrowed it down to a failing promise in ember-sync.js,
at this line: https://github.com/kurko/ember-sync/blob/master/dist/ember-sync.js#L448

The console error states:

undefined is not a function

Which is caused by a failure to generate relations, from the function "_this.generateRelationForRecord(type, relation);" here:
https://github.com/kurko/ember-sync/blob/master/dist/ember-sync.js#L655

(sorry for the rambling nature, I'm tracing my way through the code)

HERE'S THE CULPRIT
At: https://github.com/kurko/ember-sync/blob/master/dist/ember-sync.js#L678
There is a "record.serialize" call, except that in my case, the record is a promise that hasn't been resolved. This is where it fails for me.

I see there is a comment on line 638 to "implement for when .get(relation) returns a Promise". That time might be now. 😉

In fact, removing the relationships from my model allows the online sync to occur. I'm wondering if there was a change in ember-data to ensure that ALL relationships returned promises by default (maybe they always did and I'm thinking wrong).

Further clarification, I have my "belongsTo" relationship set to async. Removing the async attribute allows the online sync to work as well. It boils down to the need to handle async relationships.

from ember-sync.

kurko avatar kurko commented on May 18, 2024

@csprocket777 you rock, sir!

Do you think you can code a PR to implement this? I'll do it myself but I can't guarantee when.

from ember-sync.

csprocket777 avatar csprocket777 commented on May 18, 2024

Ugh, I'm not sure how to approach implementing a solution. I'm not sure where to implement a promise to solve for this without breaking the whole thing. I'll play around and see if I can solve for this.

(I know this is alpha and I'm breaking the "don't use it in production yet" rule, but I'm doing it anyways because this solves a huge issue for me right now, and I'm under the gun)

from ember-sync.

kurko avatar kurko commented on May 18, 2024

@csprocket777 under the gun? 😱 🔫

You can hit me up at #emberjs channel on Freenode if you need. If you can at least write a failing spec in a PR, I'll try to make a patch tonight.

from ember-sync.

kurko avatar kurko commented on May 18, 2024

@csprocket777 from our conversation on IRC, here's a gist with what I think should be done: https://gist.github.com/kurko/7ca3b17fa6b7590b93a1

from ember-sync.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.