GithubHelp home page GithubHelp logo

d.js's People

Contributors

adriengibrat avatar amiuhle avatar malko avatar mikaa123 avatar parth avatar wizardwerdna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

d.js's Issues

settle function

Hi,
when (https://github.com/cujojs/when) have a settle function that you can use to resolve or reject an array of promises.
It's similar to 'all' function, but does not call the 'error' callback if one of the promises is rejected, rather call the 'then' callback with an array of objects with 'state' (fulfilled/rejected) and the value/reason.
It is very useful, and would be nice addition to D.js.

Here is a trivial implementation (copy-pasted from 'all', I didn't have the time to make it nicer):

defer.settle = function(){ /*jshint loopfunc:true*/
        var A=arguments;
        if( A[length] === 1 && ( A[0] instanceof Array) ){
            if( A[0][length] ){
                return defer.settle.apply(defer,A[0]);
            }else{
                var D=defer();D[resolve](A[0]);
                return D[promise];
            }
        }
        var args=[]
            , d=defer()
            , promises=slice(A)
            , c=promises[length]
        ;
        if( ! c ){
            d[resolve](args);
        }else{
            for( var i=0,l=c;i<l;i++){
                (function(i){
                    var p = defer.promisify(promises[i]);
                    p[then](
                        function(v){
                            if( i in args ){ return; }
                            args[i] = { state: 'fulfilled', value: v };
                            (--c) || d[resolve](args);
                        }
                        ,function(e){
                            if( i in args ){ return; }
                            args[i] = { state: 'rejected', reason: e };
                            (--c) || d[reject](e);
                        }
                    );
                })(i);
            }
        }
        return d[promise];
    };

return value of promise callbacks not persisted, preventing chaining

When processing pendings, the return values of the callbacks are not persisted. This means that while the payload passed into the callback can be mutated, it cannot be entirely replaced (for example to wrap it in a decorator).

For example, the following will work as expected:

deferred = D();
deferred.promise.success(function(payload) {
  payload.newProperty = true;
  return payload;
});
deferred.resolve({});
deferred.promise.valueOf(); # { newProperty: true }

The following behaves unexpectedly (to me):

deferred = D();
deferred.promise.success(function(payload) {
  payload = { newProperty: true };
  return payload;
});
deferred.resolve({});
deferred.promise.valueOf(); # {}

This limitation prevents someone from wrapping the value, if it is an object, and also prevents other cases where someone may want to return an entirely different value.

I don't see anything about this behavior one way or another in the Promises/A+ spec, and this is already how native promises work. Is there any reason you wouldn't want to support this, perhaps configurable?

D.js is an invalid AMD module name

The AMD module definition states that

Module identifiers may not have file-name extensions like ".js".

Exporting "D.js" as the module id prevents AMD loaders from loading this dependency properly:

D.js/lib/D.js

Line 434 in 5217f4c

define('D.js', [], function(){ return defer; });

D.promisify & D.all broken

Hello,

There is an undefined reference to a d variable in D.promisify (l:164), this breaks the D.promisify and D.all methods :

@@ -161,7 +161,7 @@
    //-- if given value is not a promise return a fulfilled promise resolved to given value
    defer.promisify = function(promise){
        if(promise && isFunc(promise[then])){ return promise;}
-       return d.resolved(promise);
+       return defer.resolved(promise);
    };

And bonus question: I don't get the point of the closure (function(i){ ... })(i) in D.all, is there a reason?

Node requirement >=0.8

Hi,

On npm node requirement is >=0.8, it would be nice if this requirement is announced in README.md or if it's not a real requirement to lower it to >=0.6 (since default node version is 0.6.x on debian and ubuntu)

Keep up the good work!

Thanks ;)

Callback context

Hello

though not part of the promises/A+ spec I think it would be a nice addition to be able to specify the execution context of the callbacks.

For example with a bind method which store the context :

  var defer = D().bind(this);

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.