@@ -42,18 +42,74 @@ def append_backtrace(message_array, backtrace)
4242 backtrace [ 1 ..-1 ] . each { |line | message_array << line }
4343 end
4444
45+ def before_receive_props ( *args , &block )
46+ deprecation_warning "'before_receive_props' is deprecated. Use the 'before_new_params' macro instead."
47+ before_new_params ( *args , &block )
48+ end
49+
4550 def render ( container = nil , params = { } , &block )
4651 Tags . included ( self )
4752 if container
4853 container = container . type if container . is_a? Hyperstack ::Component ::Element
49- define_method :__hyperstack_component_render do
50- RenderingContext . render ( container , params ) { instance_eval ( &block ) if block }
54+ define_method ( :__hyperstack_component_render ) do
55+ __hyperstack_component_select_wrappers do
56+ RenderingContext . render ( container , params ) do
57+ instance_eval ( &block ) if block
58+ end
59+ end
5160 end
5261 else
53- define_method ( :__hyperstack_component_render ) { instance_eval ( &block ) }
62+ define_method ( :__hyperstack_component_render ) do
63+ __hyperstack_component_select_wrappers do
64+ instance_eval ( &block )
65+ end
66+ end
67+ end
68+ end
69+
70+ # def while_loading(*args, &block)
71+ # __hyperstack_component_after_render_hook do |element|
72+ # element.while_loading(*args) { |*aargs| instance_exec(*aargs, &block) }
73+ # end
74+ # end
75+
76+ def on ( *args , &block )
77+ __hyperstack_component_after_render_hook do |element |
78+ element . on ( *args ) { |*aargs | instance_exec ( *aargs , &block ) }
79+ end
80+ end
81+
82+ def rescues ( *klasses , &block )
83+ klasses = [ StandardError ] if klasses . empty?
84+ __hyperstack_component_rescue_hook do |found , *args |
85+ next [ found , *args ] if found || !klasses . detect { |klass | args [ 0 ] . is_a? klass }
86+ instance_exec ( *args , &block )
87+ [ true , *args ]
5488 end
5589 end
5690
91+ def before_render ( *args , &block )
92+ before_mount ( *args , &block )
93+ before_update ( *args , &block )
94+ end
95+
96+ def after_render ( *args , &block )
97+ after_mount ( *args , &block )
98+ after_update ( *args , &block )
99+ end
100+
101+ # [:while_loading, :on].each do |method|
102+ # define_method(method) do |*args, &block|
103+ # @@alias_id ||= 0
104+ # @@alias_id += 1
105+ # alias_name = "__hyperstack_attach_post_render_hook_#{@@alias_id}"
106+ # alias_method alias_name, :__hyperstack_attach_post_render_hook
107+ # define_method(:__hyperstack_attach_post_render_hook) do |element|
108+ # send(alias_name, element.while_loading(*args) { instance_eval(&block) })
109+ # end
110+ # end
111+ # end
112+
57113 # method missing will assume the method is a class name, and will treat this a render of
58114 # of the component, i.e. Foo::Bar.baz === Foo::Bar().baz
59115
@@ -147,8 +203,9 @@ def collect_other_params_as(name)
147203
148204 alias other_params collect_other_params_as
149205 alias others collect_other_params_as
206+ alias opts collect_other_params_as
150207
151- def triggers ( name , opts = { } )
208+ def fires ( name , opts = { } )
152209 aka = opts [ :alias ] || "#{ name } !"
153210 name = if name =~ /^<(.+)>$/
154211 name . gsub ( /^<(.+)>$/ , '\1' )
@@ -161,6 +218,8 @@ def triggers(name, opts = {})
161218 define_method ( aka ) { |*args | props [ name ] &.call ( *args ) }
162219 end
163220
221+ alias triggers fires
222+
164223 def define_state ( *states , &block )
165224 deprecation_warning "'define_state' is deprecated. Use the 'state' macro to declare states."
166225 default_initial_value = ( block && block . arity == 0 ) ? yield : nil
0 commit comments