GithubHelp home page GithubHelp logo

Comments (11)

stefanpenner avatar stefanpenner commented on July 21, 2024

I am unsure if it is directly related, but I noticed.

https://github.com/firebase/emberFire/blob/master/src/data.js#L181 doesn't enqueue an actual error object, which likely is resulting in a poor error message.

This is due to crappy error logging in the router: https://github.com/emberjs/ember.js/blob/master/packages_es6/ember-routing/lib/system/router.js#L525
opened an issue: emberjs/ember.js#4691

But in general it is best practice to reject with error objects

from emberfire.

aputinski avatar aputinski commented on July 21, 2024

@jrhe I went to https://emberfire-test.firebaseio.com/posts.json in the browser and it looks like your Firebase doesn't have any data at the /posts location

@stefanpenner I'll update that so it throws an actual error.

from emberfire.

bnjamin avatar bnjamin commented on July 21, 2024

@aputinski Does that mean you have to bootstrap your firebase with some data? If not, how are you then supposed to handle empty collections?

from emberfire.

mbykovskyy avatar mbykovskyy commented on July 21, 2024

Luckily I haven't hit this problem yet because I'm accessing a non-existing child collection through a record that does exist in firebase and it works well. But I see a future use case where I will hit this problem. I went through the code to understand why it was working in my case and interestingly I noticed that if you access a non-existing collection (could be anything really) through a parent record like so this.modelFor('post').get('comments') emberFire gets the post and then emberData converts comments attribute to an Ember.Array which in turn converts an undefined to an empty array.

Usually it's a good practice to return empty objects as opposed to null or undefined, however, how would you detect that resource doesn't exist in that case? If one chooses to display an error message for example.

You can handle the rejection like so,

var route = this;

return new Ember.RSVP.Promise(function(resolve, error) {
  resolve(route.store.find('post'));
}).then(function(value) {
  return value;
}, function(reason) {
  return [];
});

from emberfire.

stefanpenner avatar stefanpenner commented on July 21, 2024

simplification of @mbykovskyy example

route.store.find('post').catch(function(reason) {
  // check if reason tells us it was just "not found"
  return [];
});

from emberfire.

mbykovskyy avatar mbykovskyy commented on July 21, 2024

Nice one @stefanpenner!

from emberfire.

aputinski avatar aputinski commented on July 21, 2024

@stefanpenner would there be any harm in returning an empty array in the adapter if no data was found instead of rejecting?

https://github.com/firebase/emberFire/blob/master/src/data.js#L257

from emberfire.

stefanpenner avatar stefanpenner commented on July 21, 2024

@aputinski I am unsure

from emberfire.

jrhe avatar jrhe commented on July 21, 2024

I knew that I had no data but I couldn't figure out how to create it
correctly through the GUI and I assumed that that it would have created the
collection if I tried to create a record.

On 11 April 2014 17:54, Stefan Penner [email protected] wrote:

@aputinski https://github.com/aputinski I am unsure

Reply to this email directly or view it on GitHubhttps://github.com//issues/39#issuecomment-40225338
.

from emberfire.

jrhe avatar jrhe commented on July 21, 2024

@aputinski Your fixes work well.

from emberfire.

idesignedme avatar idesignedme commented on July 21, 2024

will using {{link-to 'HOME' 'home'}} break an app? also is this discouraged?
should I be using {{#link-to}}HOME{{/link-to}} instead. I'm wondering if this is the reason my app seems to break

from emberfire.

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.