Make ObservableValue lazily calculate its value

This commit is contained in:
Joe Cheng
2012-06-21 20:55:51 -07:00
parent d5c49a80f9
commit acdaba2b0e
2 changed files with 7 additions and 3 deletions

View File

@@ -120,11 +120,15 @@ module React
@valueProc = valueProc
@dependencies = Hash.new
update_value
@initialized = false
end
def value
if !@initialized
@initialized = true
update_value
end
cur_ctx = React::Context.current!
@dependencies[cur_ctx.id] = cur_ctx
cur_ctx.on_invalidate do

View File

@@ -5,7 +5,7 @@ require 'digest/md5'
shinyapp = ShinyApp.new
input1 = React::ObservableValue.new {
(shinyapp.session.get('input1') || '') + (shinyapp.session.get('addnewline') ? "\n" : '')
shinyapp.session.get('input1') + (shinyapp.session.get('addnewline') ? "\n" : '')
}
shinyapp.define_output('md5_hash') do