Created
September 5, 2016 11:58
-
-
Save catmando/225636b1512938a80f152a8ad2298993 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Few days ago i’ve started to learning and understanding Reactrb from scratch. Well, at now days React is a popular JavaScript library for building user interfaces. With a big pleasure let me introduce you Reactrb — an Opal Ruby wrapper of React.js library. | |
I recommended this wrapper for all Ruby On Rails funs, because when you get some experience (just little bit) to work with it — you just gorgeous this. First step in my way was understanding how to work param/params in Components and inside it’s. | |
Here is the my first lesson: | |
When you pass some params to Reactrb component from Controller or View, don’t forget about using it inside Component as method calls. | |
You must read the attributes by method calls. | |
Here is fast example. Though View we pass to Reactrb Component parameter user: | |
class MyClass < React::Component::Base | |
param :user, type: User | |
def render | |
div | |
a(className: 'client-link') do | |
'change me ' | |
end.on(:click) { | |
# Firstly i was trying like this: | |
# params.user[:active_status] # And the deal was in that every time when the Component was re-rendered by ReactRB — data was old. And where is React? :) | |
# And only when i'm using method calls to read attributes — everything is working. | |
params.user.active_status | |
# when you call trough the methods and before that specify the Model Name in param - like in this class in top, you tell ReactRB: Ok, give me now update to this param after every re-render. | |
end | |
end | |
end | |
Main deal of upper example was in telling the type of param that coming to Class, and calling param like method of this param. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment