Closed rockbruno closed 4 years ago
@willian-policiano-ifood @bocato @MichaelDouglasCS @alexandre-mestre-ifood I think you might be interested in importing this branch in your companies' forks, what do you think? 🙂
Since nobody commented on this, I'll merge it as it is.
I will update it right away! Thanks @rockbruno
The ugly boilerplate of this framework like
AnyFeature
andAnyDependenciesInitializer
are a result of the Swift compiler's limitation on generics. In this PR, I tested the creation of features using property wrappers instead of the usual dependencies struct. It worked, and by using Mirror to resolve the properties, I am able to drop the associated type from theFeature
and all other ugly type-erasures alongside it :)Here's how features looked before this change:
With property wrappers, I can remove all the boilerplate:
The
Feature
became a struct to make use of the compiler's synthesized initializers, and the properties are automatically resolved by RouterService. You don't need to create the annoyingdependenciesInitializer
type anymore and you don't need to worry about features that have zero or one dependency.This simplified structure makes it easier to develop and test new features. If you want to test
build()
, you can do either:or the more useful injection through the init:
The original
Dependency
protocol was also removed because it was just an alias forAnyObject
.