Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #8 from spotify/nil-ctx
Browse files Browse the repository at this point in the history
Unset ctx is null rather than empty
  • Loading branch information
fabriziodemaria authored Apr 13, 2023
2 parents 0faccc3 + 2bc72b4 commit 4e28848
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Sources/OpenFeature/FeatureProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ public protocol FeatureProvider {
var metadata: Metadata { get }

// Called by OpenFeatureAPI whenever the new Provider is registered
func initialize(initialContext: EvaluationContext) async
func initialize(initialContext: EvaluationContext?) async

// Called by OpenFeatureAPI whenever a new EvaluationContext is set by the application
func onContextSet(oldContext: EvaluationContext, newContext: EvaluationContext) async
func onContextSet(oldContext: EvaluationContext?, newContext: EvaluationContext) async

func getBooleanEvaluation(key: String, defaultValue: Bool) throws -> ProviderEvaluation<
Bool
Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenFeature/NoOpProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class NoOpProvider: FeatureProvider {
var metadata: Metadata = NoOpMetadata(name: "No-op provider")
var hooks: [AnyHook] = []

func onContextSet(oldContext: EvaluationContext, newContext: EvaluationContext) {
func onContextSet(oldContext: EvaluationContext?, newContext: EvaluationContext) {
// no-op
}

func initialize(initialContext: EvaluationContext) {
func initialize(initialContext: EvaluationContext?) {
// no-op
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenFeature/OpenFeatureAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Foundation
/// Configuration here will be shared across all ``Client``s.
public class OpenFeatureAPI {
private var _provider: FeatureProvider?
private var _context: EvaluationContext = MutableContext()
private var _context: EvaluationContext?
private(set) var hooks: [AnyHook] = []

/// The ``OpenFeatureAPI`` singleton
Expand Down
5 changes: 5 additions & 0 deletions Sources/OpenFeature/exceptions/OpenFeatureError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum OpenFeatureError: Error, Equatable {
case targetingKeyMissingError
case typeMismatchError
case valueNotConvertableError
case providerNotReadyError

public func errorCode() -> ErrorCode {
switch self {
Expand All @@ -25,6 +26,8 @@ public enum OpenFeatureError: Error, Equatable {
return .typeMismatch
case .valueNotConvertableError:
return .general
case .providerNotReadyError:
return .providerNotReady
}
}
}
Expand All @@ -46,6 +49,8 @@ extension OpenFeatureError: CustomStringConvertible {
return "Type mismatch"
case .valueNotConvertableError:
return "Could not convert value"
case .providerNotReadyError:
return "The value was resolved before the provider was ready"
}
}
}
4 changes: 2 additions & 2 deletions Tests/OpenFeatureTests/Helpers/AlwaysBrokenProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class AlwaysBrokenProvider: FeatureProvider {
var metadata: Metadata = AlwaysBrokenMetadata()
var hooks: [AnyHook] = []

func onContextSet(oldContext: OpenFeature.EvaluationContext, newContext: OpenFeature.EvaluationContext) {
func onContextSet(oldContext: OpenFeature.EvaluationContext?, newContext: OpenFeature.EvaluationContext) {
// no-op
}

func initialize(initialContext: OpenFeature.EvaluationContext) {
func initialize(initialContext: OpenFeature.EvaluationContext?) {
// no-op
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/OpenFeatureTests/Helpers/DoSomethingProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import OpenFeature
class DoSomethingProvider: FeatureProvider {
public static let name = "Something"

func onContextSet(oldContext: OpenFeature.EvaluationContext, newContext: OpenFeature.EvaluationContext) {
func onContextSet(oldContext: OpenFeature.EvaluationContext?, newContext: OpenFeature.EvaluationContext) {
// no-op
}

func initialize(initialContext: OpenFeature.EvaluationContext) {
func initialize(initialContext: OpenFeature.EvaluationContext?) {
// no-op
}

Expand Down

0 comments on commit 4e28848

Please sign in to comment.