now attributes and text are reactive

This commit is contained in:
Torsten 2023-02-07 18:56:28 +02:00
parent e93e4b0e38
commit 8a0461c98d
3 changed files with 15 additions and 5 deletions

View File

@ -38,13 +38,13 @@ module VueR
def trigger(key) def trigger(key)
puts "Trigger:#{key}" puts "Trigger:#{key}"
effects = get_subscribers_for(key) effects = get_subscribers_for(key)
effects.each {|effect| effect() } effects.each {|effect| effect.call() }
end end
def get_subscribers_for(key) def get_subscribers_for(key)
key = key.to_sym key = key.to_sym
unless @subscribers.has_key?(key) unless @subscribers.has_key?(key)
@subscribers[key] = [] @subscribers[key] = Set.new
end end
@subscribers[key] @subscribers[key]
end end

View File

@ -49,8 +49,16 @@ module VueR
end end
@application.watch_effect(proc) @application.watch_effect(proc)
end end
def mount_event(element , name) def mount_event(element , name)
puts "Event: #{name}" native_name = name.gsub("e_" , "")
ruby = element[name]
puts "Event: #{native_name}:#{ruby}"
element.on!(native_name) do
got = @application.eval(ruby)
puts "Clicked #{got}"
end
end end
end end
end end

View File

@ -3,11 +3,13 @@
= #@image.attributes = #@image.attributes
.flex.justify-center .flex.justify-center
%a.underline{ e_click: "hi" , r_class: 'bg'} %a.underline{ e_click: "bg_change" , r_class: 'bg'}
{{ bg }} {{ bg }}
:opal :opal
class Clicker < VueR::Application class Clicker < VueR::Application
def bg_change
self.bg = "bg-cyan-50"
end
end end
kanta = Clicker.new(bg: 'bg-cyan-200') kanta = Clicker.new(bg: 'bg-cyan-200')