Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nested component class lookup fails #181

Closed
catmando opened this issue May 2, 2019 · 0 comments
Closed

nested component class lookup fails #181

catmando opened this issue May 2, 2019 · 0 comments
Labels
bug Something isn't working
Milestone

Comments

@catmando
Copy link
Contributor

catmando commented May 2, 2019

For example this test case will fail:

  it 'Looks up components in nested namespaces correctly' do
    mount 'Foo::Bar::Zoom' do
      module Foo
        module Bar
          class Zoom < HyperComponent
            render do
              Wham()
            end
          end
        end
      end

      module Wham
      end

      module Foo
        module Bar
          class Wham < HyperComponent
            render(DIV) do
              "found me!"
            end
          end
        end
      end
    end
    expect(page).to have_content('found me!')
  end

The problem is in the lookup_const method in the Tags module the const_defined? and const_get calls must include the second false parameter to prevent looking up the ancestor tree.

You can patch it like this:

module Hyperstack
  module Internal
    module Component    
      module Tags
        def lookup_const(name)
          return nil unless name =~ /^[A-Z]/
          scopes = self.class.name.to_s.split('::').inject([Object]) do |nesting, next_const|
            nesting + [nesting.last.const_get(next_const)]
          end.reverse
          scope = scopes.detect { |s| s.const_defined?(name, false) }
          scope.const_get(name, false) if scope
        end
      end
    end
  end
end

For the hyperloop legacy branch the same method is in

module React
  module Component
    module Tags
      def lookup_const(name) 
        ...
      end
    end
  end
end

However this has a knock on effect that breaks hyper-model's INPUT tag redefinition. In that method redefinition the newly defined tag constants are made on the Tag module scope (incorrectly) and this bug allowed that to work. So that has to also be fixed, i.e. the new tags need to be defined against Object.

@catmando catmando added the bug Something isn't working label May 2, 2019
@catmando catmando added this to the alpha1.5 milestone May 2, 2019
@catmando catmando changed the title nest component class lookup fails nested component class lookup fails May 2, 2019
catmando added a commit that referenced this issue May 2, 2019
catmando added a commit that referenced this issue May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant