This might be a welcomed alternative to finding a unique name for something that, in most situations, doesn't require naming. Plus it has the added benefit of being familiar to someone coming from one of the many frameworks that use this approach.
My current approach, sadly, uses AnyCodable as Leaf's encoder isn't public.
import Vapor
import AnyCodable
extension ViewRenderer {
public func render(_ name: String, _ context: [String: Any]) async throws -> View {
let data = context.reduce(into: [:]) { $0[$1.0] = AnyCodable($1.1) }
return try await self.render(name, data)
}
}
Maybe making Leaf's builtin encoder public might be a possible compromise.
This might be a welcomed alternative to finding a unique name for something that, in most situations, doesn't require naming. Plus it has the added benefit of being familiar to someone coming from one of the many frameworks that use this approach.
My current approach, sadly, uses
AnyCodableas Leaf's encoder isn't public.Maybe making Leaf's builtin encoder public might be a possible compromise.