Bacon.js observable.map with auto-catch
Bacon.js observable.map with auto-catch
当使用部分映射函数(并非每个可能的输入都是有效的)时,我最终做了一个小助手:
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));
}
});
}
有了这个帮助程序,我可以像property.map(myMapper)
一样使用strictMap(property, myMapper)
。这样的功能是否已经在培根.js某处,还是我以错误的方式做了什么?
与Observable.map相比,它什么都没抓到?
答案是否定的——培根中没有这样的功能.js到目前为止。
我认为到目前为止,还没有对异常捕获的需求,因为Javascript中的异常通常是软件错误,而不是应该作为正常操作的一部分来处理的东西。例如,JQuery 中的 AJAX 错误不会建模为异常。
无论如何,我建议你在Github上打开一个新问题。让我们看看是否有其他人认为这是我们需要的东西。如果我们想这样做,我认为我们应该以更通用的方式实现异常处理,即不与"map"耦合。
顺便说一句,你的实施看起来不错!
相关文章:
- Fighting with FRP
- 节点Js:How to catch a“;没有这样的文件或目录“;读取线模块出错
- issue with FB.Event.subscribe
- geolocation-marker.js conflict with markerclusterer.js
- Angular 2.0 with JavaScript or TypeScript?
- 为什么不推荐使用“with”?是否有更好或其他方法可以“下降”到对象的命名空间
- WebComponentsJS with IE10
- 指令的模板必须只有一个根元素:With restrict E&替换true
- timeago.js with datatable and PHP
- Ajax and Json with Rails
- errors with Javascript try catch
- how to split a string with ','
- Understanding Javascript scope with "var that = this&qu
- Architecture for CPU intensive tasks with NodeJS & Socke
- How to declare a Map containing certain properties with flow
- 如何使用(this)访问Angular 2 http rxjs catch函数中的对象属性
- Bacon.js observable.map with auto-catch
- Jquery Ui Auto suggestions with Json array
- auto tab with exception
- Javascript添加(push)数组与多个数据在auto with循环