aurelia-async icon indicating copy to clipboard operation
aurelia-async copied to clipboard

Broken in latest Aurelia

Open niieani opened this issue 8 years ago • 11 comments

The error happens here:

AsyncExpression.prototype.connect(binding, scope) {
      var info = this.expression.connect(binding, scope);
      // info is undefined here!
      return {
        value: info.value ? info.value.__value : undefined,
        observer: new AsyncObserver(info.value, info.observer, this.ready)
      };
    };

niieani avatar Feb 10 '16 14:02 niieani

@niieani I started working on this. aurelia-async needed quite a bit of refactoring to bring it up to date with the latest version of aurelia-binding. I'm currently working on the tests. Should be ready in a few days.

jdanyow avatar Feb 11 '16 02:02 jdanyow

Awesome, thanks @jdanyow! I've tried doing the refactor myself (looking at the code of aurelia-binding to match), but without any success, there's no documentation and deciphering it all turned out to be pretty hard.

niieani avatar Feb 11 '16 12:02 niieani

@jdanyow Any updates? I'd really like to try out Aurelia and Falcor.

jmealo avatar May 01 '16 04:05 jmealo

@jmealo As a pretty good workaround, if you want to bind to Promises you can do something like this: https://gist.run/?id=bd1ee888a9311027156b29b7df6ac27e

Above code is inspired by @jods4's proposition from here.

Another alternative is my plugin aurelia-async-binding-function, however the API is still under consideration (I'll probably get rid of the @ prefix and make requiring the BindingFunction explicit).

niieani avatar Jun 01 '16 12:06 niieani

Bump. Can anyone outline what work needs to be done?

jmealo avatar Jul 22 '16 20:07 jmealo

We're still debating the best way to handle async binding. Recently a feature was added to aurelia called view engine hooks that make it very easy to implement "binding functions". Here's an example. In the example, app.html uses <require> to import some binding functions and use them to bind to promises/observables.

@niieani is working on another approach that would allow the view to pretend things aren't async.

jdanyow avatar Jul 23 '16 01:07 jdanyow

@jdanyow what about this approach: https://gist.run/?id=524b94cc960456499bbb306fe1491e4a

istrau2 avatar Aug 30 '17 21:08 istrau2

For those wondering, @istrau2's approach is to use a decorator to add getObserver to the getter of properties that are Promise. They can then be bound to like a regular value would.

That's very similar to the approach I suggested way back then, but it's done on the property declaration rather than in the binding expression (where I added a property access to add getObserver).

I think that's a pretty good approach, especially since it gives a nice place to configure stuff like default value when the Promise is pending or rejected. It also keeps the (or possibly more than one) consuming side simple.

jods4 avatar Aug 31 '17 23:08 jods4

Been struggling with async a bit in aurelia and came across this discussion.

So outside lifestyle hooks loaded from the router async is kind of a mess atm?

Seems the decision was to favor the .bind( promise & async ) or .bind( promse..value ) as here - but it seems theres still a lingering question as this package hasn't been updated.

For myself I greatly favor this gitrun bindableAsync decorator posted above but the solution is not compatible with any other computed features in aurelia - namely computedFrom

See this gist: https://gist.run/?id=5c3c86ff91f6c92441075cbb74f046dc

If the promise is dependent on something the user is selecting on the page - like a dropdown or a radio button theres no way to refresh the promise.

Looking through the aurelia-binding package it seems the proper solution would be to create a new PromiseObserver similar to ExpressionObserver so that bound expression promises are properly detected and interact with computedFrom for one.

But I could be completely off base too as I just started working with aurelia.

Has there been any forward progress in the async observables debate?

Back in the knockout days I was using the async observable extension pattern that was popular - sad that nothing has come around for modern libraries yet

charlessolar avatar Nov 30 '17 16:11 charlessolar

@volak You are completely "on base" actually. In fact, since I posted originally in this thread I have built a more sophisticated version of @asyncBindable with support for exactly what you mention (i.e. it works along with @computedFrom).

I am having a very busy day at work today but I will post it (on github as well as an npm module) either tonight or tomorrow.

istrau2 avatar Nov 30 '17 16:11 istrau2

@volak

Here: https://www.npmjs.com/package/aurelia-async-bindable-bluebird

Also, somewhat related. I have also published an aurelia redux integration that I use quite a bit too: https://www.npmjs.com/package/aurelia-redux-connect

istrau2 avatar Dec 01 '17 16:12 istrau2