使用来自不同流的 属性 的值

Use value of property from a different stream

这是一些简化的代码。我按下一个按钮,它设置了一些配置。然后,当用户提交表单时,它需要读取配置的最新值。我正在努力成为所有 FRP 并避免设置普通变量。

var currentConfig = $('#authenticateCont #btnFormType')
        .asEventStream('click')
        .map(function (e) {
          ...
        });

$('#authenticateCont form')
        .asEventStream('submit')
         .combine(currentConfig, function(r, c) {
            return {
                response: r,
                config: c
            };
        })
        .onValue(function(e){
          ...
        });

除了当配置更改时它会导致按钮单击处理程序触发,就好像表单已提交一样,这会起作用。显然我不想要这个。

需要是表单提交的时候,从config中读取最新的值。我需要类似 'combineLeft' 的操作,它不存储最近的提交事件。

拜托....这么简单的事情怎么会这么棘手呢?按一个按钮,读取一个值!

I need something like a 'combineLeft' operation

是的,有这样的东西:属性<a href="https://github.com/baconjs/bacon.js#property-sampledby" rel="nofollow">.sampledBy</a>(stream)。每当您单击提交按钮时,它都会从配置 属性 中获取当前值:

var submit = $('#authenticateCont form').asEventStream('submit');
currentConfig.sampledBy(submit, function(c, e) {
    return {event: e, config: c};
})
.onValue(function(e) { … });