zewa666 / aurelia-async-binding

Aurelia async bindingbehavior to consume Observables and Promises
MIT License
18 stars 3 forks source link

Using expressions, converters ... #4

Open doktordirk opened 6 years ago

doktordirk commented 6 years ago

Seems that personsStats != 0 & async: { property: value} or personsStats & async: { property: value} != 0 or personsStats | isNotZero & async: { property: value} or personsStats & async: { property: value} | isNotZero aren't possible.

one way to allow evaluation of the async bound value would be:

personsStats & async: { property: value, converter: isNotZero}

thoughts? other options (well, i could filter the stream, but i need that for several values separately. hence too much code repetition to be a good idea)?

edit: ah, asyncIsNotZero works: eg

import { filter} from 'rxjs/operators';

export class asyncIsNotZeroValueConverter {
  toView(stream, option) {
    return stream.pipe(
      filter(data=> data[option] !== 0)
    );
  }
}
<div repeat.for="attribute of attributes" if.bind="stats | asyncIsNotZero:attribute.name & async: { property: attribute.name}">

something more generic would be nice still

zewa666 commented 6 years ago

Yeah like an async adapter for valueconverters. Essentially it could be as proposed with converter, but this breaks chaining and looks rather clunky right? Ideally we could use personStats | toAsync: isNotZero : otheropts & async: { ... }. In worst case the VC would have to be passed in as a string.

Another alternative would be to register async variants of VCs globally via code with ab alias, like in your sample asyncIsNotZero.