Giter Club home page Giter Club logo

Comments (3)

tanepiper avatar tanepiper commented on July 30, 2024
DS.create('post', { author: 'Sally', title: 'Angular gotchas' })
.then(function (post) {
    post; // { id: 65, author: 'Sally', title: 'Angular gotchas' }
});

DS.create('post', { author: 'Sally' })
.then(null, function (err) {
    err; // 'Title is required'
});

What was the design decision around these function signatures?

Why for example is there a separate error callback, rather than an error promise? Or why is the error not returned as the first parameter of the then callback? i.e. .then(...).error(...) or .then(function(error, post)`

from js-data-angular.

jmdobry avatar jmdobry commented on July 30, 2024

@tanepiper angular-data just uses angular's $q service for promises, so they'll function exactly as you would expect $q promises to work. The following are functionally equivalent:

DS.create('post', { author: 'Sally', title: 'Angular gotchas' })
.then(function (post) {
  // called on success
}, function (err) {
  // called on error
})
.finally(function () {
  // always called
});

and

DS.create('post', { author: 'Sally', title: 'Angular gotchas' })
.then(function (post) {
  // called on success
})
.catch(function (err) {
  // called on error
})
.finally(function () {
  // always called
});

The error will never be passed as the first argument to the first callback that was passed to .then(...). It wasn't a design decision on my part–that's just how $q promises work.

Perhaps my example is a bit confusing because I pass null as the first argument to .then(...) (because I knew the first callback wouldn't be called anyway). The examples in this comment are probably clearer.

from js-data-angular.

tanepiper avatar tanepiper commented on July 30, 2024

@jmdobry Ahh I didn't realise that. I've always used the second way though so never seen the first way used. Makes sense now and I'm glad to see they are just promises so fits with my code structuring.

from js-data-angular.

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.