Factory 2.1 Coming Soon #83
Replies: 3 comments 9 replies
-
I'm building a design system. For the brands we build it of we inject various tokens. The simplest token is a color, but it can essentially be any type. Besides a brand which is set at module initialisation, and then registers the correct factories we also have a sub theme approach which colors a subview to different colors, like light/dark, but then for a small part of the screen. My question is if I could use the context approach for this? But let me clarify with an exampele struct HelloWorldView: View {
@Intjected(\.textColor) private var textColor: Color
var body: some View {
Text("Hello World")
.foregroundColor(textColor)
}
} Now I would like to instantiate 2 instances of struct ContentView: View {
var body: some View {
VStack {
HelloWorldView()
.context("foo")
HelloWorldView()
.context("bar")
}
}
} In the above the context is a
|
Beta Was this translation helpful? Give feedback.
-
I have a question related to the context a of a factory. Now the context is switched global. But as I was reading the docs I expected the context to be something you set on a container instance, not on a factory and global. The idea is that you could build in hierarchy in your dependency chain. A bit like in SwiftUI how the environment works for example with If you in SwiftUI apply If you only can change the context of a factory instead of the context of a container it is not possible to apply local changes when using the technique in your docs of passing a container instance rather then using the Do you think it would be possible to add a context at the level of a |
Beta Was this translation helpful? Give feedback.
-
Could clarify what the This looks ideal for feature flags! |
Beta Was this translation helpful? Give feedback.
-
Features
Factory 2.1 has a set of exciting new features that include...
Let's peek at one of the new features:
Contexts
Once reason Factory 2.0 leaned heavily into the modifier syntax is that I knew this feature was coming. Now I'm happy to announce it!
Developers often use Factory to mock data for previews and unit tests. Now Factory 2.1 extends these capabilities by allowing them to easily specify dependencies based on the application's current context.
What if, for example, you never want your application's analytics library to be called when running unit tests?
Piece of cake. Just register a new factory closure for that service whenever it runs in that particular context.
Factory provides a variety of contexts for testing, debugging, previews, simulator, device, and for checking passed parameters when running UI tests and checking builds on services like BrowserStack.
As an example of the later:
Now you can have a single build change its behavior based on passed parameters.
Develop
I've currently putting some of the finishing touches on the documentation, but Factory 2.1 is currently available in the develop branch if you want to check it out.
Beta Was this translation helpful? Give feedback.
All reactions