trailblazer-operation icon indicating copy to clipboard operation
trailblazer-operation copied to clipboard

Class Dependencies (possible implementation change)

Open apotonick opened this issue 3 years ago • 0 comments

Class Dependencies

  • Class dependencies allow setting (temporary?) ctx variables for an operation.
  • Currently, those variables stay in the result ctx and hence bleed through to the outer operation when nested. Maybe an expose: true could configure this?
class Index < Trailblazer::Operation
    extend ClassDependencies

    self["model.class"] = Module

    step ->(ctx, **) { ctx["a"] = ctx["model.class"] }
  end

Implementation

  • Currently, in #public_call and #call_with_circuit_interface we create a new Context where those variables are set.
  • Ideally, we should use :inject and/or :input instead in the outer operation and set the inner class variables with an injection. This would also reduce run-time logic. E.g. the Subprocess() macro could take care of this.
  • For the topmost operation, the endpoint could be doing this, instead of clumsily hacking this feature.

apotonick avatar Nov 05 '21 10:11 apotonick