hyper-react icon indicating copy to clipboard operation
hyper-react copied to clipboard

params should always attempt to run "to_xxx" on in coming objects if type doesn't match

Open barriehadfield opened this issue 9 years ago • 1 comments

You will get this warning but the functionality will work as expected. See this example from the tutorial:

class App < React::Component::Base
        def render
          div do
            Nav(login: method(:login))
            Messages()
            InputBox()
          end
        end

        def login(user_name)
          puts "*** #{user_name} has logged in"
        end
      end

      class Nav < React::Component::Base
        param :login, type: Proc

        before_mount do
          state.current_user_name! nil
          state.user_name_input! ""
        end

        def render
          div do
            input(type: :text, value: state.user_name_input, placeholder: "Enter Your Handle"
            ).on(:change) do |e|
              state.user_name_input! e.target.value
            end
            button(type: :button) { "login!" }.on(:click) do
              login!
            end if valid_new_input?
          end
        end

        def valid_new_input?
          state.user_name_input.present? && state.user_name_input != state.current_user_name
        end

        def login!
           state.current_user_name! state.user_name_input
           params.login(state.user_name_input)
        end
      end

NOTE: Must update the tutorial text which is being changed to ask the reader to ignore the warning. Please let @barriehadfield know.

barriehadfield avatar Sep 26 '16 12:09 barriehadfield

problem is that method(:login) returns a object of class Method not class Proc as the param expects.

You can do method(:login).to_proc to get rid of the warning.

The real problem is that the param mechanism should always attempt to do a to_xxx on any incoming param that does not match the type...

catmando avatar Sep 26 '16 12:09 catmando