Skip to content

Commit

Permalink
Update docs for #Preview
Browse files Browse the repository at this point in the history
  • Loading branch information
hmlongco committed Oct 28, 2023
1 parent 01f576d commit faa7665
Show file tree
Hide file tree
Showing 240 changed files with 262 additions and 225 deletions.
23 changes: 23 additions & 0 deletions Sources/Factory/Factory.docc/Development/Previews.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@ struct ContentView_Previews: PreviewProvider {
}
```
If we can control where the view model gets its data then we can put the view model into pretty much any state we choose.

## SwiftUI #Previews

The same can be done for the new #Preview option, with one minor change.

```swift
#Preview {
let _ = Container.myService.register { MockServiceN(4) }
return ContentView()
}
```
The #Preview closure is not a ViewBuilder, so if we add our let statement we just need to explicitly return our view.

Or we could simply turn it into a ViewBuilder using our old friend, Group.
```swift
#Preview {
Group {
let _ = Container.myService.register { MockServiceN(4) }
ContentView()
}
}
```
Group actually has a few additional uses...

## Multiple Previews

Expand Down
2 changes: 1 addition & 1 deletion docs/data/documentation/factory.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/data/documentation/factory/autoregistering.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"kind":"symbol","primaryContentSections":[{"kind":"declarations","declarations":[{"platforms":["macOS"],"tokens":[{"text":"protocol","kind":"keyword"},{"text":" ","kind":"text"},{"kind":"identifier","text":"AutoRegistering"}],"languages":["swift"]}]},{"kind":"content","content":[{"level":2,"text":"Overview","anchor":"overview","type":"heading"},{"type":"paragraph","inlineContent":[{"type":"text","text":"Add this protocol to a container to support first-time registration of needed dependencies prior to first resolution"},{"type":"text","text":" "},{"type":"text","text":"of a dependency on that container."}]},{"code":["extension Container: AutoRegistering {"," func autoRegister() {"," someService.register {"," CrossModuleService()"," }"," }","}"],"type":"codeListing","syntax":"swift"},{"type":"paragraph","inlineContent":[{"type":"text","text":"The "},{"type":"codeVoice","code":"autoRegister"},{"type":"text","text":" function is called on each instantiated container prior to"},{"text":" ","type":"text"},{"type":"text","text":"the first resolution of a Factory on that container."}]},{"name":"Warning","type":"aside","style":"warning","content":[{"type":"paragraph","inlineContent":[{"type":"text","text":"Calling "},{"code":"container.manager.reset(options: .all)","type":"codeVoice"},{"type":"text","text":" restores the container to it’s initial state"},{"type":"text","text":" "},{"text":"and autoRegister will be called again if it exists.","type":"text"}]}]}]}],"sections":[],"topicSections":[{"title":"Instance Methods","identifiers":["doc:\/\/Factory\/documentation\/Factory\/AutoRegistering\/autoRegister()"]}],"identifier":{"url":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering","interfaceLanguage":"swift"},"metadata":{"roleHeading":"Protocol","navigatorTitle":[{"text":"AutoRegistering","kind":"identifier"}],"fragments":[{"kind":"keyword","text":"protocol"},{"text":" ","kind":"text"},{"text":"AutoRegistering","kind":"identifier"}],"title":"AutoRegistering","modules":[{"name":"Factory"}],"externalID":"s:7Factory15AutoRegisteringP","role":"symbol","symbolKind":"protocol"},"schemaVersion":{"minor":3,"patch":0,"major":0},"variants":[{"traits":[{"interfaceLanguage":"swift"}],"paths":["\/documentation\/factory\/autoregistering"]}],"abstract":[{"type":"text","text":"Adds an registration “hook” to a "},{"type":"codeVoice","code":"Container"},{"type":"text","text":"."}],"hierarchy":{"paths":[["doc:\/\/Factory\/documentation\/Factory"]]},"references":{"doc://Factory/documentation/Factory/AutoRegistering":{"url":"\/documentation\/factory\/autoregistering","type":"topic","fragments":[{"text":"protocol","kind":"keyword"},{"text":" ","kind":"text"},{"text":"AutoRegistering","kind":"identifier"}],"title":"AutoRegistering","identifier":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering","navigatorTitle":[{"text":"AutoRegistering","kind":"identifier"}],"abstract":[{"type":"text","text":"Adds an registration “hook” to a "},{"type":"codeVoice","code":"Container"},{"type":"text","text":"."}],"role":"symbol","kind":"symbol"},"doc://Factory/documentation/Factory":{"role":"collection","title":"Factory","type":"topic","identifier":"doc:\/\/Factory\/documentation\/Factory","kind":"symbol","url":"\/documentation\/factory","abstract":[{"type":"text","text":"A new approach to Container-Based Dependency Injection for Swift and SwiftUI."}]},"doc://Factory/documentation/Factory/AutoRegistering/autoRegister()":{"required":true,"role":"symbol","url":"\/documentation\/factory\/autoregistering\/autoregister()","fragments":[{"text":"func","kind":"keyword"},{"text":" ","kind":"text"},{"text":"autoRegister","kind":"identifier"},{"text":"()","kind":"text"}],"kind":"symbol","type":"topic","identifier":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering\/autoRegister()","title":"autoRegister()","abstract":[{"type":"text","text":"User provided function that supports first-time registration of needed dependencies prior to first resolution"},{"text":" ","type":"text"},{"type":"text","text":"of a dependency on that container."}]}}}
{"schemaVersion":{"patch":0,"major":0,"minor":3},"metadata":{"symbolKind":"protocol","roleHeading":"Protocol","role":"symbol","title":"AutoRegistering","externalID":"s:7Factory15AutoRegisteringP","modules":[{"name":"Factory"}],"navigatorTitle":[{"text":"AutoRegistering","kind":"identifier"}],"fragments":[{"text":"protocol","kind":"keyword"},{"text":" ","kind":"text"},{"text":"AutoRegistering","kind":"identifier"}]},"sections":[],"primaryContentSections":[{"declarations":[{"platforms":["macOS"],"languages":["swift"],"tokens":[{"text":"protocol","kind":"keyword"},{"text":" ","kind":"text"},{"text":"AutoRegistering","kind":"identifier"}]}],"kind":"declarations"},{"kind":"content","content":[{"anchor":"overview","text":"Overview","level":2,"type":"heading"},{"inlineContent":[{"type":"text","text":"Add this protocol to a container to support first-time registration of needed dependencies prior to first resolution"},{"type":"text","text":" "},{"text":"of a dependency on that container.","type":"text"}],"type":"paragraph"},{"syntax":"swift","type":"codeListing","code":["extension Container: AutoRegistering {"," func autoRegister() {"," someService.register {"," CrossModuleService()"," }"," }","}"]},{"type":"paragraph","inlineContent":[{"text":"The ","type":"text"},{"code":"autoRegister","type":"codeVoice"},{"text":" function is called on each instantiated container prior to","type":"text"},{"type":"text","text":" "},{"text":"the first resolution of a Factory on that container.","type":"text"}]},{"content":[{"type":"paragraph","inlineContent":[{"text":"Calling ","type":"text"},{"code":"container.manager.reset(options: .all)","type":"codeVoice"},{"text":" restores the container to it’s initial state","type":"text"},{"type":"text","text":" "},{"text":"and autoRegister will be called again if it exists.","type":"text"}]}],"type":"aside","name":"Warning","style":"warning"}]}],"variants":[{"paths":["\/documentation\/factory\/autoregistering"],"traits":[{"interfaceLanguage":"swift"}]}],"topicSections":[{"identifiers":["doc:\/\/Factory\/documentation\/Factory\/AutoRegistering\/autoRegister()"],"title":"Instance Methods"}],"abstract":[{"type":"text","text":"Adds an registration “hook” to a "},{"code":"Container","type":"codeVoice"},{"text":".","type":"text"}],"kind":"symbol","hierarchy":{"paths":[["doc:\/\/Factory\/documentation\/Factory"]]},"identifier":{"interfaceLanguage":"swift","url":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering"},"references":{"doc://Factory/documentation/Factory/AutoRegistering/autoRegister()":{"fragments":[{"kind":"keyword","text":"func"},{"kind":"text","text":" "},{"text":"autoRegister","kind":"identifier"},{"text":"()","kind":"text"}],"required":true,"type":"topic","url":"\/documentation\/factory\/autoregistering\/autoregister()","role":"symbol","title":"autoRegister()","identifier":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering\/autoRegister()","abstract":[{"text":"User provided function that supports first-time registration of needed dependencies prior to first resolution","type":"text"},{"text":" ","type":"text"},{"text":"of a dependency on that container.","type":"text"}],"kind":"symbol"},"doc://Factory/documentation/Factory/AutoRegistering":{"title":"AutoRegistering","abstract":[{"type":"text","text":"Adds an registration “hook” to a "},{"type":"codeVoice","code":"Container"},{"text":".","type":"text"}],"fragments":[{"text":"protocol","kind":"keyword"},{"kind":"text","text":" "},{"text":"AutoRegistering","kind":"identifier"}],"navigatorTitle":[{"kind":"identifier","text":"AutoRegistering"}],"url":"\/documentation\/factory\/autoregistering","role":"symbol","type":"topic","kind":"symbol","identifier":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering"},"doc://Factory/documentation/Factory":{"abstract":[{"type":"text","text":"A new approach to Container-Based Dependency Injection for Swift and SwiftUI."}],"type":"topic","identifier":"doc:\/\/Factory\/documentation\/Factory","kind":"symbol","role":"collection","url":"\/documentation\/factory","title":"Factory"}}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"hierarchy":{"paths":[["doc:\/\/Factory\/documentation\/Factory","doc:\/\/Factory\/documentation\/Factory\/AutoRegistering"]]},"sections":[],"schemaVersion":{"major":0,"patch":0,"minor":3},"abstract":[{"text":"User provided function that supports first-time registration of needed dependencies prior to first resolution","type":"text"},{"type":"text","text":" "},{"text":"of a dependency on that container.","type":"text"}],"primaryContentSections":[{"declarations":[{"tokens":[{"kind":"keyword","text":"func"},{"text":" ","kind":"text"},{"text":"autoRegister","kind":"identifier"},{"kind":"text","text":"()"}],"platforms":["macOS"],"languages":["swift"]}],"kind":"declarations"}],"metadata":{"externalID":"s:7Factory15AutoRegisteringP12autoRegisteryyF","modules":[{"name":"Factory"}],"roleHeading":"Instance Method","role":"symbol","fragments":[{"text":"func","kind":"keyword"},{"text":" ","kind":"text"},{"text":"autoRegister","kind":"identifier"},{"text":"()","kind":"text"}],"symbolKind":"method","title":"autoRegister()","required":true},"variants":[{"paths":["\/documentation\/factory\/autoregistering\/autoregister()"],"traits":[{"interfaceLanguage":"swift"}]}],"identifier":{"url":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering\/autoRegister()","interfaceLanguage":"swift"},"kind":"symbol","references":{"doc://Factory/documentation/Factory/AutoRegistering/autoRegister()":{"required":true,"role":"symbol","url":"\/documentation\/factory\/autoregistering\/autoregister()","fragments":[{"text":"func","kind":"keyword"},{"text":" ","kind":"text"},{"text":"autoRegister","kind":"identifier"},{"text":"()","kind":"text"}],"kind":"symbol","type":"topic","identifier":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering\/autoRegister()","title":"autoRegister()","abstract":[{"type":"text","text":"User provided function that supports first-time registration of needed dependencies prior to first resolution"},{"text":" ","type":"text"},{"type":"text","text":"of a dependency on that container."}]},"doc://Factory/documentation/Factory":{"role":"collection","title":"Factory","type":"topic","identifier":"doc:\/\/Factory\/documentation\/Factory","kind":"symbol","url":"\/documentation\/factory","abstract":[{"type":"text","text":"A new approach to Container-Based Dependency Injection for Swift and SwiftUI."}]},"doc://Factory/documentation/Factory/AutoRegistering":{"url":"\/documentation\/factory\/autoregistering","type":"topic","fragments":[{"text":"protocol","kind":"keyword"},{"text":" ","kind":"text"},{"text":"AutoRegistering","kind":"identifier"}],"title":"AutoRegistering","identifier":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering","navigatorTitle":[{"text":"AutoRegistering","kind":"identifier"}],"abstract":[{"type":"text","text":"Adds an registration “hook” to a "},{"type":"codeVoice","code":"Container"},{"type":"text","text":"."}],"role":"symbol","kind":"symbol"}}}
{"variants":[{"traits":[{"interfaceLanguage":"swift"}],"paths":["\/documentation\/factory\/autoregistering\/autoregister()"]}],"sections":[],"abstract":[{"type":"text","text":"User provided function that supports first-time registration of needed dependencies prior to first resolution"},{"text":" ","type":"text"},{"text":"of a dependency on that container.","type":"text"}],"kind":"symbol","metadata":{"symbolKind":"method","roleHeading":"Instance Method","title":"autoRegister()","fragments":[{"text":"func","kind":"keyword"},{"text":" ","kind":"text"},{"text":"autoRegister","kind":"identifier"},{"kind":"text","text":"()"}],"modules":[{"name":"Factory"}],"role":"symbol","externalID":"s:7Factory15AutoRegisteringP12autoRegisteryyF","required":true},"identifier":{"url":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering\/autoRegister()","interfaceLanguage":"swift"},"primaryContentSections":[{"kind":"declarations","declarations":[{"tokens":[{"kind":"keyword","text":"func"},{"text":" ","kind":"text"},{"text":"autoRegister","kind":"identifier"},{"text":"()","kind":"text"}],"languages":["swift"],"platforms":["macOS"]}]}],"schemaVersion":{"minor":3,"major":0,"patch":0},"hierarchy":{"paths":[["doc:\/\/Factory\/documentation\/Factory","doc:\/\/Factory\/documentation\/Factory\/AutoRegistering"]]},"references":{"doc://Factory/documentation/Factory":{"abstract":[{"type":"text","text":"A new approach to Container-Based Dependency Injection for Swift and SwiftUI."}],"type":"topic","identifier":"doc:\/\/Factory\/documentation\/Factory","kind":"symbol","role":"collection","url":"\/documentation\/factory","title":"Factory"},"doc://Factory/documentation/Factory/AutoRegistering":{"title":"AutoRegistering","abstract":[{"type":"text","text":"Adds an registration “hook” to a "},{"type":"codeVoice","code":"Container"},{"text":".","type":"text"}],"fragments":[{"text":"protocol","kind":"keyword"},{"kind":"text","text":" "},{"text":"AutoRegistering","kind":"identifier"}],"navigatorTitle":[{"kind":"identifier","text":"AutoRegistering"}],"url":"\/documentation\/factory\/autoregistering","role":"symbol","type":"topic","kind":"symbol","identifier":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering"},"doc://Factory/documentation/Factory/AutoRegistering/autoRegister()":{"fragments":[{"kind":"keyword","text":"func"},{"kind":"text","text":" "},{"text":"autoRegister","kind":"identifier"},{"text":"()","kind":"text"}],"required":true,"type":"topic","url":"\/documentation\/factory\/autoregistering\/autoregister()","role":"symbol","title":"autoRegister()","identifier":"doc:\/\/Factory\/documentation\/Factory\/AutoRegistering\/autoRegister()","abstract":[{"text":"User provided function that supports first-time registration of needed dependencies prior to first resolution","type":"text"},{"text":" ","type":"text"},{"text":"of a dependency on that container.","type":"text"}],"kind":"symbol"}}}
Loading

0 comments on commit faa7665

Please sign in to comment.