Skip to content

Was there a recommend approach in Alchmey 6 for "fallback elements" #2441

Answered by phantomwhale
phantomwhale asked this question in Q&A
Discussion options

You must be logged in to vote

Ah cool - have pulled code out of the Alchemy 5.x version of the code, and written a naive one as follows:

As you say, might need some eager loading (although suspect this should be no worse than the current library code, given it's a straight copy/paste of what's needed)

module Alchemy
  class FallbackElementsFinder < ElementsFinder
    def initialize(options = {})
      @fallback_options = options.delete(:fallback)
      super(options)
    end

    def elements(page:)
      elements = super(page: page)
      elements = elements.merge(fallback_elements) if with_fallback?(elements)
      elements
    end

    private

    attr_reader :fallback_options

    def with_fallback?(elements)
   …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by tvdeyen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants