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

hypercomponent class not inheriting correctly #60

Closed
catmando opened this issue Nov 15, 2018 · 3 comments
Closed

hypercomponent class not inheriting correctly #60

catmando opened this issue Nov 15, 2018 · 3 comments
Labels
bug Something isn't working

Comments

@catmando
Copy link
Contributor

This spec fails:

  it "can create an inherited component's  insert_element alias" do
    mount 'Tester' do
      module Container
        class Base < HyperComponent
          before_mount do
            @_instance_data = []
          end
        end
        class Thing < Base
          before_mount do
            @_instance_data << "works!"
          end
          render { @_instance_data.join(" ") }
        end
      end
      class Tester < HyperComponent
        render { Container::Thing() }
      end
    end
    expect(page).to have_content('works!')
  end

No method Thing for Container!

@catmando
Copy link
Contributor Author

The fix for this relies on the render macro calling Tags.included(self) which registers the class name in the parent.

So we need to deprecate all use of def render.

@catmando
Copy link
Contributor Author

This is closed pending release.

Be aware that component class inheritance will not work correctly unless using the render macro. If you want to get rid of the warning temporarily and work around the inheritance problem do this in your base component class:

class LegacyBaseClass
   def self.inherited(base) 
      base.include Hyperstack::Component::Base
    end
    def self.allow_deprecated_render_definition?
       true
    end
    ...
end

In Legacy Hyperloop the Hyperloop Component base class defined the inherited method as shown above. But in Hyperstack we don't want to force use of a base class prefering module includes instead. However some features, notably the ability to reference the component's insert_element method by using the class name followed by parenthesis (i.e. Foo::Bar()) depends on knowing when the component class is defined.

Since every runnable component must have a render callback, we use the callback definition as a hook to add the class method definition.

@catmando catmando added the bug Something isn't working label Nov 15, 2018
@barriehadfield
Copy link
Contributor

@catmando all of the docs and examples use render do already

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

2 participants