jdanyow / aurelia-async

A plugin for the Aurelia platform providing asynchronous binding support
MIT License
27 stars 4 forks source link

Broken in latest Aurelia #4

Open niieani opened 8 years ago

niieani commented 8 years ago

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)
      };
    };
jdanyow commented 8 years ago

@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.

niieani commented 8 years ago

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.

jmealo commented 8 years ago

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

niieani commented 8 years ago

@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).

jmealo commented 7 years ago

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

jdanyow commented 7 years ago

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.

istrau2 commented 6 years ago

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

jods4 commented 6 years ago

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.

charlessolar commented 6 years ago

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

istrau2 commented 6 years ago

@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 commented 6 years ago

@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