Giter Site home page Giter Site logo

Comments (11)

ericclemmons avatar ericclemmons commented on August 14, 2024

Do you mean a Promise-free version (top to bottom), or you'd like the ability to do node-style callback resolution in the resolve block?

The internals are doing a Promise.all, so there would need to be some core equivalency here, whether with an outside dependency (async?) or similar...

from react-resolver.

goatslacker avatar goatslacker commented on August 14, 2024

Top to bottom would be nice but that's just a pipe dream. Just the ability to do callbacks or whatever in the resolve block is a good start.

Yeah you would need async.parallel

from react-resolver.

ericclemmons avatar ericclemmons commented on August 14, 2024

I can pretty easily add back in callback support in the resolve block based on the arity (is that the right word?) of the function.

Behind the scenes, it'll use a Promise to map it.

Is that ok for now?

I didn't know if Promises should be avoided in your estimation, or what?

from react-resolver.

goatslacker avatar goatslacker commented on August 14, 2024

No it's not necessary to avoid them. As long as resolver isn't swallowing errors promises are great.

from react-resolver.

ericclemmons avatar ericclemmons commented on August 14, 2024

I... guess we're fine then? I do know it's recommended to do Resolver.renderSomehow(...).catch(...), since it's promise-driven.

from react-resolver.

srph avatar srph commented on August 14, 2024

I like the idea as well. I'm starting to like generators recently.

from react-resolver.

goatslacker avatar goatslacker commented on August 14, 2024

Pseudo-code:

// where you resolve the promises:
return new Promise((resolve, reject) => {
  // create a node-style callback
  const callback = (err, value) => err ? reject(err) : resolve(value);

  // call the resolve prop
  const value = resolveProp(props, context, callback);

  // if a Promise is returned then attach to it.
  if (value && value.then && typeof value.then === 'function') {
    value.then(resolve).catch(reject)
  }
})

from react-resolver.

ericclemmons avatar ericclemmons commented on August 14, 2024

Ahhhh, that takes me back :)

if (value.length) {
return new Bluebird(function(resolve, reject) {
value.call(this, function(err, result) {
err ? reject(err) : resolve(result);
});
}.bind(this));
}

That was a simpler time!

Nice code, BTW. That solves it pretty well.

Now I'm curious. I guess I still use promises wrong??

https://github.com/petkaantonov/bluebird/wiki/Promise-anti-patterns#the-thensuccess-fail-anti-pattern

from react-resolver.

goatslacker avatar goatslacker commented on August 14, 2024

I think if you return the promise itself you'll be a-ok since it'll unwrap itself. I'm probably doing it wrong.

from react-resolver.

ericclemmons avatar ericclemmons commented on August 14, 2024

Oh no, I think you're right. In one of the other issues, I opted for .then(resolved, rejected), whereas I should've just used .then(resolved).catch(errored).

from react-resolver.

ericclemmons avatar ericclemmons commented on August 14, 2024

v2 is a complete-rewrap & will support decorators & a better mechanism with dealing with errors.

TBH, callbacks are soooo great for error states :) Closing to start fresh post-v2...

from react-resolver.

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.