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

Hyperloop Operation mangles Hash class #10

Open
illogikal opened this issue Jul 20, 2017 · 0 comments
Open

Hyperloop Operation mangles Hash class #10

illogikal opened this issue Jul 20, 2017 · 0 comments
Milestone

Comments

@illogikal
Copy link

illogikal commented Jul 20, 2017

class TestPage < Hyperloop::Component
  def render
    div do
      form do
        TestField(store: TestStore, 
                  update_op: UpdateTestForm, 
                  form_key: :test_form, 
                  field_name: :test)
        button(type: :submit)
      end
    end
  end
end

class TestField < Hyperloop::Component
  param :field_name, required: false
  param :form_key,   type: String, required: false
  param :store,      required: true
  param :update_op,  required: true

  def update_value val
    params.update_op.run(test_field: val.gsub(/\s/, ''))
  end

  def valid?
     params.store.send(params.form_key)[field_error_name].present?
  end

  def field_error_name
    "#{params.field_name}_error"
  end

  def render
    div {
      p { valid? ? "Valid" : "Invalid" }
      input(type: :text).
        on(:key_down, :key_up) { |e| update_value e.target.value }
    }
  end
end

class UpdateTestForm < Hyperloop::Operation
  param :test_field, type: String, default: ''
  param :test_field_error, type: String, default: ''
  step { update_form }

  def update_form
    params.test_field_error = params.test_field.present? ? '' : "Can't be blank."
  end
end

class TestStore < Hyperloop::Store
  state test_form: {}, scope: :shared

  receives UpdateTestForm do |params|
    mutate.test_form(params)
  end

  def self.test_form
    state.test_form
  end
end

hyperloop-loader-system.self-ebeb435….js?bo…:20 Exception raised while rendering #<TestField:0xade>: undefined method `[]' for {"test_field"=>"", "test_field_error"=>"Test is invalid"}

Not sure what I'm doing incorrectly, as inspecting the TestStore.test_form outputs the correct hash, but it seems like it's a different class to Hash, and using hash methods on it does not work.

@catmando catmando added this to the Release 0.15 milestone Nov 15, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants