mirror of
https://github.com/rstudio/shiny.git
synced 2026-01-09 15:08:04 -05:00
Make ObservableValue lazily calculate its value
This commit is contained in:
8
react.rb
8
react.rb
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user