Frage

When working with partial mapping function (not every possible input is valid), I ended up making a small helper:

function strictMap(property, f) {
  return property.withHandler(function (ev) {
    try {
      var x = ev.fmap(f);
      // force
      if (x.hasValue()) {
        x.value();
      }
      return this.push(x);
    } catch (err) {
      return this.push(new Bacon.Error(err));
    }
  });
}

With this helper I can use strictMap(property, myMapper) in the same fashion as property.map(myMapper). Is such functionality already in Bacon.js somewhere, or am I doing something in a wrong way?

Compare to Observable.map which doesn't catch anything?

War es hilfreich?

Lösung

The answer is no - there's no such functionality in Bacon.js as of now.

So far there hasn't been demand for exception-catching, I think, because exceptions in Javascript are generally software bugs and not something that should be handled as a part of the normal operation. For instance, AJAX errors in JQuery are not modeled as exceptions.

In any case, I suggest you open a new Issue on Github. Let's see if there are others who feel this is something we need. If we wanted to do this, I think we should implement exception-handling in a more generic way, i.e. not coupled with "map".

You implementation, btw, looks good!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top