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

Prototype: process an additional param that is sent to associations #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

urnf
Copy link

@urnf urnf commented Jun 6, 2019

DO NOT MERGE. MEANT FOR DISCUSSION.

Proof of concept meant to explore passing additional options to dynamic associations. While this is tailored towards the placeholder "firstFiftyAssociations ", meant to address a current problem with pagination, something like this would lay the groundwork for additional options.

In the presenter, association definition goes from

dynamic: lambda {|model| model.scope }

to

dynamic: lambda {|model, options = {}| some_option_based_behavior ? model.something_else : model.scope }

The new param is not required to maintain backwards compatibility and leaves the responsibility of handling that option up to the association proc itself. The procs themselves would probably end up needing to be refactored wholesale to support any new features that would be added to them, such as pagination.

- Method here is a simple extra param passed in; real effort should focus around allowing include to specify perPage for associations
if options[:lookup]
run_on_with_lookup(model, context, helper_instance)
elsif options[:dynamic]
proc = options[:dynamic]
if proc.arity == 1
if proc.arity == -2
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the expected association proc format takes in model and options = {}, we start with arity 2, and with one of the params not required, makes it -2.

I'm not sure about the case at the bottom with no arity - as far as I know, our documentation requires that at least a model is passed in, resulting in arity 1?

@urnf urnf added the WIP label Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

1 participant