我似乎不记得将proc作为react.rb中组件的参数传递,有人可以提醒我吗?
对不起,如果我的问题措辞不好,我有点累了。
当然结帐http://reactrb.org/docs/reusable-components.html(大约在页面的一半)或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>