better undestanding of vue, walking dom
This commit is contained in:
parent
feb6815d38
commit
ef4a22709a
@ -1 +1,2 @@
|
|||||||
require "vue_r/application"
|
require "vue_r/application"
|
||||||
|
require "vue_r/mounter"
|
||||||
|
@ -5,7 +5,6 @@ module VueR
|
|||||||
hash.each do |k,v|
|
hash.each do |k,v|
|
||||||
wrap_attr(k,v)
|
wrap_attr(k,v)
|
||||||
end
|
end
|
||||||
wrap_methods
|
|
||||||
@effect = nil
|
@effect = nil
|
||||||
@subscribers = {}
|
@subscribers = {}
|
||||||
end
|
end
|
||||||
@ -42,6 +41,7 @@ module VueR
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_subscribers_for(key)
|
def get_subscribers_for(key)
|
||||||
|
key = key.to_sym
|
||||||
unless @subscribers.has_key?(key)
|
unless @subscribers.has_key?(key)
|
||||||
@subscribers[key] = []
|
@subscribers[key] = []
|
||||||
end
|
end
|
||||||
@ -49,25 +49,17 @@ module VueR
|
|||||||
end
|
end
|
||||||
|
|
||||||
def mount(on_class)
|
def mount(on_class)
|
||||||
puts $document[on_class].inner_html
|
@mounter = Mounter.new(on_class , self)
|
||||||
|
@mounter.mount
|
||||||
end
|
end
|
||||||
|
|
||||||
def wrap_methods
|
def watch_effect( update_proc )
|
||||||
methods = self.class.methods(false).collect{|name| self.class.method(name)}
|
effect = Proc.new do
|
||||||
methods.select!{|method| method.arity > 0 }
|
@effect = effect
|
||||||
methods.each{|method| wrap_method(method.name)}
|
update_proc.call
|
||||||
end
|
|
||||||
|
|
||||||
def wrap_method(method_name)
|
|
||||||
clazz = self.class
|
|
||||||
clazz.alias "#{method_name}_original".to_sym , method_name
|
|
||||||
clazz.remove_method method_name
|
|
||||||
clazz.define_method method_name do
|
|
||||||
@effect = self.class.method(method_name)
|
|
||||||
self.class.method("#{method_name}_original".to_sym).call
|
|
||||||
@effect = nil
|
@effect = nil
|
||||||
end
|
end
|
||||||
clazz.method(method_name).call
|
effect.call
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
31
app/assets/javascript/vue_r/mounter.rb
Normal file
31
app/assets/javascript/vue_r/mounter.rb
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
module VueR
|
||||||
|
class Mounter
|
||||||
|
|
||||||
|
def initialize( id , app )
|
||||||
|
@root = $document[id]
|
||||||
|
@application = app
|
||||||
|
end
|
||||||
|
|
||||||
|
def mount
|
||||||
|
mount_Element(@root)
|
||||||
|
end
|
||||||
|
|
||||||
|
def mount_Text elem
|
||||||
|
puts "Text: #{elem.text}"
|
||||||
|
puts "DYN text" if elem.text.include? "{{"
|
||||||
|
end
|
||||||
|
|
||||||
|
def mount_Element(elem)
|
||||||
|
elem.attributes.each do |name , value|
|
||||||
|
puts "Name: #{name}"
|
||||||
|
puts "Value: #{value}"
|
||||||
|
puts "DYN" if name.start_with?("r_")
|
||||||
|
puts "EVENT" if name.start_with?("e_")
|
||||||
|
end
|
||||||
|
elem.children.each do |elem|
|
||||||
|
base_name = elem.class.to_s.split("::").last
|
||||||
|
send "mount_#{base_name}" , elem
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -2,9 +2,9 @@
|
|||||||
.flex.flex-col
|
.flex.flex-col
|
||||||
= @image.attributes
|
= @image.attributes
|
||||||
|
|
||||||
%a.underline{ '@click' => "hi"}
|
%a.underline{ e_click: "hi"}
|
||||||
Back
|
{{Back}}
|
||||||
|
%div{ r_class: 21 }
|
||||||
:opal
|
:opal
|
||||||
class Clicker < VueR::Application
|
class Clicker < VueR::Application
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user