Skip to content

Make EnvironmentValues available in prepare().#765

Closed
JPToroDev wants to merge 2 commits intotwostraws:mainfrom
JPToroDev:host
Closed

Make EnvironmentValues available in prepare().#765
JPToroDev wants to merge 2 commits intotwostraws:mainfrom
JPToroDev:host

Conversation

@JPToroDev
Copy link
Copy Markdown
Collaborator

This PR gives users access to a subset of available environment values—like a site's articles—in Site's prepare() method.

@twostraws
Copy link
Copy Markdown
Owner

I'm keen to avoid leaking implementation details if possible; if we can get @Environment to work in Site it would be preferable to passing in values. For example, in the case of making content available in prepare(), could we push the content parsing phase up so that it happens before prepare() is called?

@JPToroDev
Copy link
Copy Markdown
Collaborator Author

Sure, we could move parseContent() to the initialize() method.

The reason I went with this approach is because @Environment has a page property that won't be relevant in this context. In the future, we might add other properties that are not valid before the publishing phase, too.

We could make them optional, but that might start to muck up the API.

That, coupled with using a property wrapper outside of a view, struck me as a potential point of confusion.

@JPToroDev
Copy link
Copy Markdown
Collaborator Author

I also took a bit of inspiration from SwiftUI's ShapeStyle.

@twostraws
Copy link
Copy Markdown
Owner

Think of it a bit like how SwiftUI's @State property wrapper can be used in a View or in the main App struct; both will work. You can also use it in an external view model class, but there SwiftUI will issue a runtime warning that you've screwed up.

@JPToroDev
Copy link
Copy Markdown
Collaborator Author

That makes sense. I'll submit a new PR with that approach. Then I think we're good to push a small tag and set our sights on the multilingual stuff.

@JPToroDev JPToroDev closed this Mar 26, 2025
@JPToroDev JPToroDev deleted the host branch April 4, 2025 22:26
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