Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit 19d932c

Browse files
committed
Implement all the lifecyle hooks
1 parent 27ddbc6 commit 19d932c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/react/component.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ def self.included(base)
1010
class_attribute :init_state, :validator
1111
define_callback :before_mount
1212
define_callback :after_mount
13+
define_callback :before_receive_props
14+
define_callback :before_update
15+
define_callback :after_update
16+
define_callback :before_unmount
1317
end
1418
base.extend(ClassMethods)
1519
end
@@ -43,23 +47,23 @@ def component_did_mount
4347
end
4448

4549
def component_will_receive_props(next_props)
46-
50+
self.run_callback(:before_receive_props, next_props)
4751
end
4852

4953
def should_component_update?(next_props, next_state)
50-
54+
self.respond_to?(:needs_update?) ? self.needs_update? : true
5155
end
5256

5357
def component_will_update(next_props, next_state)
54-
58+
self.run_callback(:before_update, next_props, next_state)
5559
end
5660

5761
def component_did_update(prev_props, prev_state)
58-
62+
self.run_callback(:after_update, prev_props, prev_state)
5963
end
6064

6165
def component_will_unmount
62-
66+
self.run_callback(:before_unmount)
6367
end
6468

6569
def method_missing(name, *args, &block)

0 commit comments

Comments
 (0)