opal react.rb 将 proc 作为参数传入以用作回调

opal react.rb passing in proc as a param for use as a callback

我似乎不记得在 react.rb 中将 proc 作为参数传递给组件,有人可以提醒我吗?

抱歉,如果我的问题措辞不当,我有点累了。

确定结帐http://reactrb.org/docs/reusable-components.html (about half way down the page) or http://reactrb.org/docs/component-api.html

这是一个工作示例

<div id="container"></div>
<script type="text/ruby">
class Alarm < React::Component::Base
  param :at, type: Time
  param :notify, type: Proc
  after_mount do
    @clock = every(1) do
      if Time.now > params.at
        params.notify
        @clock.stop
      end
      force_update!
    end
  end
  def render
    "#{Time.now}"
  end
end

Element['#container'].render do
  Alarm(
   at: Time.now+10.seconds, 
   notify: -> { alert ('beep beep beep') }
  )
end

</script>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script src="https://rawgit.com/reactive-ruby/inline-reactive-ruby/master/inline-reactive-ruby.js"></script>