How should organizers function? #3
Replies: 1 comment 3 replies
-
Hey @taylorthurlow, I think this can be done by separating the concept of input params to an interactor/organizer and the context itself. If I understand properly what you are trying to achieve here with attributes is that you don't want people to be able to dump in a bunch of attributes to the context that just pollute it with crap that will never be used and, also to make sure that the params they enter is everything the interactor/organizer need to complete its work. If something is missing throw an error one time as the interactor will not be able to complete successfully. I think this is great as you can now open the interactor file and just a quick look the code you can determine all the params that the interactor needs to do its work. In the case with organizers since organizer will take the input params and change them into a context object and then pass the context object to the individual interactors in the organizer we can let that happen with no filtering. The individual interactors will still have the attribute concept but only when supplying them with a hash. if you supply them with a context they just use the context. I think we can do this easily by changing a couple lines. you currently check the attributes in the execute method here interaktor/lib/interaktor/callable.rb Lines 176 to 187 in 9413084 I would say instead of checking there to check attributes in the build method for the context interaktor/lib/interaktor/context.rb Lines 20 to 22 in 9413084 we could change it to something like this return context if context.is_a?(Interaktor::Context)
# check attributes here to make sure everyhting is good if it is not good
# then raise Interaktor::Error::MissingAttributeError if everything is good
# run the following line to build and return a Interaktor::Context object
new(context) That would allow organizers to work the way they always did and allow for explicit attributes to be passed in. The organizer will be responsible for checking the params hash passed in and the individual interaktors will just do they work. Let me know what you think about this approach and if it makes sense for your project. |
Beta Was this translation helpful? Give feedback.
-
With the more restrictive interface that interaktors provide over interactors, comes some uncertainty regarding how organizers should be treated.
My thought is to only allow organizers to specify a series of interaktors to organize and nothing more. The attributes that you pass to the organizer would be determined by the first interaktor in the organizer. This seems to fit the ethos of Interactor (per the README, "Its single purpose is to run other interactors.").
There is some uncertainty as far as to which interaktors your attributes apply, when calling the organizer. Additionally, it is not clear how the attributes should be passed between interaktors. In Interactor, the concept of a context is publicly exposed, and because that is no longer the case, it needs to be made clearer how the attributes are passed from one interaktor to the next. It could be possible to use the success attributes of an interaktor as the input attributes (required/optional attributes) of the next interaktor, but this might strong-hand the user into building interaktors which are only useful in the context of the organizer. I'm not sure if this is a good or bad thing.
Beta Was this translation helpful? Give feedback.
All reactions