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

Result Injection improvements #833

Merged

Conversation

danthorpe
Copy link
Member

@danthorpe danthorpe commented May 3, 2018

Result injection works really well to chain units of work together, mapping state via a sequence of Input -> Output transitions.

However, the common scenario, once this has been built will be to encapsulate those smaller units of work with a GroupProcedure to hide the details of that state transition. At the moment, this is totally possible, but it does require unnecessary boiler plate, which we can remove.

Essentially, we want to be able to do something like this:

final class MyGroup: GroupProcedure, InputProcedure, OutputProcedure {

    typealias StageA = TransformProcedure<Foo, Bar>
    typealias StageB = TransformProcedure<Bar, Baz>
    typealias StageC = TransformProcedure<Baz, Bat>

    var input: Pending<Foo>
    var ouput: Pending<ProcedureResult<Bat>>

    init() {
 
        let a = StageA { /* etc */ }
        let b = StageB { /* etc */ }.injectResult(from: a)
        let c = StageC { /* etc */ }.injectResult(from: b)

        super.init(operations: [a, b, c])

        // We want to "bind" the input property 
        //   of the StageA procedure to the group itself
        bind(to: a)

        // We want to "bind" the output property 
        //    of the group (i.e. self) to the StageC procedure output
        bind(from: c) 
    }
}

Those two "bind" APIs will use observers to set the input and output properties to the equivalent of the property on the receiver.

@danthorpe danthorpe added this to the 4.6 milestone May 3, 2018
@danthorpe danthorpe merged commit c1615f7 into development May 3, 2018
@danthorpe danthorpe modified the milestone: 4.6 May 5, 2018
@danthorpe danthorpe modified the milestones: 4.6, 5.0.0 Jun 18, 2018
@danthorpe danthorpe deleted the feature/OPR-833_result_injection_improvements branch June 23, 2018 14:43
@slessans
Copy link

@danthorpe could you provide a hint or reference for the boilerplate required to do this when working with the 4.5.0 version of the library?

@danthorpe
Copy link
Member Author

@slessans the bind APIs are not in v4.5.0, they will be in v5.0.0. They work pretty much as in this boiler-plate code.

The development branch is 5.0.0.beta.1. There are some breaking changes however from 4.5.0. You might want to do a test to see how the changes impact your codebase - I’ve added deprecation Fix-its where possible to make it easy to upgrade.

Also be aware that more breaking changes around logging (beta.2) & potentially block procedures (beta.3) are in the works - so might want to hold off.

Please post feedback on any upgrade issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants