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

Support optional dependencies and unify @Dependency property wrappers #91

Merged
merged 1 commit into from
Nov 8, 2023

Conversation

Supereg
Copy link
Member

@Supereg Supereg commented Nov 8, 2023

Support optional dependencies and unify @dependency property wrappers

♻️ 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()
        }
    }
}

⚙️ Release Notes

  • Added support for optional dependencies
  • Removed @DynamicDependencies in favor of a new DSL-based approach used within the @Dependency property wrapper directly.

📚 Documentation

Documentation was updated.

✅ Testing

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

📝 Code of Conduct & Contributing Guidelines

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

@Supereg Supereg requested a review from PSchmiedmayer November 8, 2023 03:42
Copy link

codecov bot commented Nov 8, 2023

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

@@            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 Coverage Δ
...ilities/Communication/CollectPropertyWrapper.swift 100.00% <ø> (ø)
...ilities/Communication/ProvidePropertyWrapper.swift 100.00% <ø> (ø)
...bilities/Communication/StorageValueCollector.swift 100.00% <100.00%> (ø)
...abilities/Communication/StorageValueProvider.swift 100.00% <100.00%> (ø)
...ces/Spezi/Dependencies/DependencyDeclaration.swift 100.00% <100.00%> (ø)
Sources/Spezi/Dependencies/DependencyManager.swift 98.12% <100.00%> (+1.12%) ⬆️
Sources/Spezi/Module/Module.swift 100.00% <ø> (ø)
...rces/Spezi/Dependencies/DependencyCollection.swift 97.06% <97.06%> (ø)
Sources/Spezi/Dependencies/DependencyContext.swift 93.34% <93.34%> (ø)
...Spezi/Dependencies/DependencyPropertyWrapper.swift 90.20% <90.20%> (ø)
... and 1 more

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cf93e19...ee34612. Read the comment docs.

Copy link
Member

@PSchmiedmayer PSchmiedmayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the changes! As we already synced on this int he office: This looks great!

Amazing work over the lsat weeks where in Spezi to get it to 1.0, really appreciated @Supereg! 🚀

@Supereg Supereg merged commit b82fb37 into main Nov 8, 2023
8 checks passed
@Supereg Supereg deleted the feature/simplify-dependencies branch November 8, 2023 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants