StanfordSpezi / Spezi

Open-source framework for rapid development of modern, interoperable digital health applications.
https://swiftpackageindex.com/StanfordSpezi/Spezi/documentation
MIT License
130 stars 10 forks source link

Support optional dependencies and unify @Dependency property wrappers #91

Closed Supereg closed 8 months ago

Supereg commented 8 months ago

Support optional dependencies and unify @Dependency property wrappers

:recycle: Current situation & Problem

As of right now, we support infrastructure for two property wrappers @Dependency and @DynamicDependencies. The latter one induces particularly hard to understand syntax. This PR revises the dependency infrastructure and removes @DynamicDependencies by introducing a result-builder-based approach.

Below code example demonstrates the difference:

class PreviousExample: Module {
    @DynamicDependencies var dynamicDependencies: [any Module]

    init() {
        self._dynamicDependencies = DynamicDependencies(
            moduleProperty: [
                Dependency(wrappedValue: ModuleA()),
                Dependency(wrappedValue: ModuleB())
            ]
        )
    }
}

class NewExample: Module {
    @Dependency var dependencies: [any Module]

    init() {
        _dependencies = Dependency {
            ModuleA()
            ModuleB()
        }
    }
}

:gear: Release Notes

:books: Documentation

Documentation was updated.

:white_check_mark: Testing

Functionality was verified with existing test cases. New tests were added for new functionality.

:pencil: Code of Conduct & Contributing Guidelines

By submitting creating this pull request, you agree to follow our Code of Conduct and Contributing Guidelines:

codecov[bot] commented 8 months ago

Codecov Report

Merging #91 (ee34612) into main (cf93e19) will decrease coverage by 2.00%. The diff coverage is 88.71%.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/StanfordSpezi/Spezi/pull/91/graphs/tree.svg?width=650&height=150&src=pr&token=KHU2K1HTAM&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi)](https://app.codecov.io/gh/StanfordSpezi/Spezi/pull/91?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi) ```diff @@ Coverage Diff @@ ## main #91 +/- ## ========================================== - Coverage 93.46% 91.46% -2.00% ========================================== Files 28 30 +2 Lines 565 655 +90 ========================================== + Hits 528 599 +71 - Misses 37 56 +19 ``` | [Files](https://app.codecov.io/gh/StanfordSpezi/Spezi/pull/91?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi) | Coverage Δ | | |---|---|---| | [...ilities/Communication/CollectPropertyWrapper.swift](https://app.codecov.io/gh/StanfordSpezi/Spezi/pull/91?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aS9DYXBhYmlsaXRpZXMvQ29tbXVuaWNhdGlvbi9Db2xsZWN0UHJvcGVydHlXcmFwcGVyLnN3aWZ0) | `100.00% <ø> (ø)` | | | [...ilities/Communication/ProvidePropertyWrapper.swift](https://app.codecov.io/gh/StanfordSpezi/Spezi/pull/91?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aS9DYXBhYmlsaXRpZXMvQ29tbXVuaWNhdGlvbi9Qcm92aWRlUHJvcGVydHlXcmFwcGVyLnN3aWZ0) | `100.00% <ø> (ø)` | | | [...bilities/Communication/StorageValueCollector.swift](https://app.codecov.io/gh/StanfordSpezi/Spezi/pull/91?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aS9DYXBhYmlsaXRpZXMvQ29tbXVuaWNhdGlvbi9TdG9yYWdlVmFsdWVDb2xsZWN0b3Iuc3dpZnQ=) | `100.00% <100.00%> (ø)` | | | [...abilities/Communication/StorageValueProvider.swift](https://app.codecov.io/gh/StanfordSpezi/Spezi/pull/91?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aS9DYXBhYmlsaXRpZXMvQ29tbXVuaWNhdGlvbi9TdG9yYWdlVmFsdWVQcm92aWRlci5zd2lmdA==) | `100.00% <100.00%> (ø)` | | | [...ces/Spezi/Dependencies/DependencyDeclaration.swift](https://app.codecov.io/gh/StanfordSpezi/Spezi/pull/91?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aS9EZXBlbmRlbmNpZXMvRGVwZW5kZW5jeURlY2xhcmF0aW9uLnN3aWZ0) | `100.00% <100.00%> (ø)` | | | [Sources/Spezi/Dependencies/DependencyManager.swift](https://app.codecov.io/gh/StanfordSpezi/Spezi/pull/91?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aS9EZXBlbmRlbmNpZXMvRGVwZW5kZW5jeU1hbmFnZXIuc3dpZnQ=) | `98.12% <100.00%> (+1.12%)` | :arrow_up: | | [Sources/Spezi/Module/Module.swift](https://app.codecov.io/gh/StanfordSpezi/Spezi/pull/91?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aS9Nb2R1bGUvTW9kdWxlLnN3aWZ0) | `100.00% <ø> (ø)` | | | [...rces/Spezi/Dependencies/DependencyCollection.swift](https://app.codecov.io/gh/StanfordSpezi/Spezi/pull/91?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aS9EZXBlbmRlbmNpZXMvRGVwZW5kZW5jeUNvbGxlY3Rpb24uc3dpZnQ=) | `97.06% <97.06%> (ø)` | | | [Sources/Spezi/Dependencies/DependencyContext.swift](https://app.codecov.io/gh/StanfordSpezi/Spezi/pull/91?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aS9EZXBlbmRlbmNpZXMvRGVwZW5kZW5jeUNvbnRleHQuc3dpZnQ=) | `93.34% <93.34%> (ø)` | | | [...Spezi/Dependencies/DependencyPropertyWrapper.swift](https://app.codecov.io/gh/StanfordSpezi/Spezi/pull/91?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aS9EZXBlbmRlbmNpZXMvRGVwZW5kZW5jeVByb3BlcnR5V3JhcHBlci5zd2lmdA==) | `90.20% <90.20%> (ø)` | | | ... and [1 more](https://app.codecov.io/gh/StanfordSpezi/Spezi/pull/91?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi) | | ------ [Continue to review full report in Codecov by Sentry](https://app.codecov.io/gh/StanfordSpezi/Spezi/pull/91?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://app.codecov.io/gh/StanfordSpezi/Spezi/pull/91?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi). Last update [cf93e19...ee34612](https://app.codecov.io/gh/StanfordSpezi/Spezi/pull/91?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi).