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

Remove deferred render entirely #805

Merged
merged 2 commits into from
Oct 3, 2024
Merged

Conversation

joeldrapper
Copy link
Collaborator

@joeldrapper joeldrapper commented Oct 3, 2024

This abstraction is too confusing. If you understand the concept, you can still use it by yielding early.

def view_template
  vanish { yield }

  # ...
end

This PR also changes the callbacks so before_template is given the block and can yield it.

def before_template
  vanish { yield }
end

You can put this in a module called DeferredRender if you want. It’s up to you.

@willcosgrove
Copy link
Contributor

I like this change, I think this actually going to be easier to explain, even though it requires "more code" to use. Because you can see what's happening.

What do you think about also adding the block to the after_template just for consistency? I don't know what the actual usecase would be for someone yielding the block in an after template (there wasn't really a reason to want to in the before_template either, before this).

@davekaro
Copy link
Contributor

davekaro commented Oct 3, 2024

This works great for me. I had to adjust the vanish call to be vanish { yield(self) if defined?(yield) }. I think for sure you want to yield(self) otherwise you can't call methods on the component. The if defined?(yield) is because sometimes I don't pass a block to customize the render.

@willcosgrove
Copy link
Contributor

@davekaro I had wondered about that as well. I think this works nicely and is succinct:

def before_template(&)
  vanish(&)
  super
end

super isn't strictly necessary, but it will let any other modules or parent classes continue with any hooks they might have installed.

@davekaro
Copy link
Contributor

davekaro commented Oct 3, 2024

Even better!

@joeldrapper joeldrapper merged commit 42228c2 into main Oct 3, 2024
5 checks passed
@joeldrapper joeldrapper deleted the remove-deferred-render-entirely branch October 3, 2024 23:46
joeldrapper pushed a commit that referenced this pull request Nov 8, 2024
This commit tidies up the API by making the naming consistent with
#805
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants