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

Fix rootEnvironment not merged with .defaultEnvironment #461

Merged
merged 4 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Sources/TokamakCore/Environment/EnvironmentValues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ public struct EnvironmentValues: CustomStringConvertible {
values[bindable] = newValue
}
}

@_spi(TokamakCore)
public mutating func merge(_ other: Self?) {
if let other = other {
values.merge(other.values) { existing, new in
new
}
}
}

@_spi(TokamakCore)
public func merging(_ other: Self?) -> Self {
var merged = self
merged.merge(other)
return merged
}
}

struct IsEnabledKey: EnvironmentKey {
Expand Down
2 changes: 1 addition & 1 deletion Sources/TokamakDOM/DOMRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ final class DOMRenderer: Renderer {
reconciler = StackReconciler(
app: app,
target: DOMNode(ref),
environment: .defaultEnvironment,
environment: .defaultEnvironment.merging(rootEnvironment),
renderer: self
) { scheduler.schedule(options: nil, $0) }
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/TokamakGTK/GTKRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import CGTK
import Dispatch
import TokamakCore
@_spi(TokamakCore) import TokamakCore

extension EnvironmentValues {
/// Returns default settings for the GTK environment
Expand Down Expand Up @@ -56,7 +56,7 @@ final class GTKRenderer: Renderer {
self.reconciler = StackReconciler(
app: app,
target: Widget(window),
environment: .defaultEnvironment,
environment: .defaultEnvironment.merging(rootEnvironment),
renderer: self,
scheduler: { next in
DispatchQueue.main.async {
Expand Down
6 changes: 3 additions & 3 deletions Sources/TokamakStaticHTML/StaticHTMLRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// Created by Carson Katri on 7/20/20.
//

import TokamakCore
@_spi(TokamakCore) import TokamakCore

extension EnvironmentValues {
/// Returns default settings for the static HTML environment
Expand Down Expand Up @@ -90,7 +90,7 @@ public final class StaticHTMLRenderer: Renderer {
reconciler = StackReconciler(
view: view,
target: rootTarget,
environment: .defaultEnvironment,
environment: .defaultEnvironment.merging(rootEnvironment),
renderer: self,
scheduler: { _ in
fatalError("Stateful apps cannot be created with TokamakStaticHTML")
Expand All @@ -104,7 +104,7 @@ public final class StaticHTMLRenderer: Renderer {
reconciler = StackReconciler(
app: app,
target: rootTarget,
environment: .defaultEnvironment,
environment: .defaultEnvironment.merging(rootEnvironment),
renderer: self,
scheduler: { _ in
fatalError("Stateful apps cannot be created with TokamakStaticHTML")
Expand Down