2022-12-05 22:50:36 +01:00
|
|
|
//
|
|
|
|
// DependencyStore.swift
|
2022-12-11 19:55:21 +01:00
|
|
|
// DependencyInjection
|
2022-12-05 22:50:36 +01:00
|
|
|
//
|
|
|
|
// Created by Javier Cicchelli on 05/12/2022.
|
|
|
|
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
public struct DependencyStore {
|
|
|
|
|
|
|
|
// MARK: Properties
|
|
|
|
|
|
|
|
private static var current = Self()
|
|
|
|
|
|
|
|
// MARK: Functions
|
|
|
|
|
|
|
|
public static subscript<K>(key: K.Type) -> K.Value where K: DependencyKey {
|
|
|
|
get { key.currentValue }
|
|
|
|
set { key.currentValue = newValue }
|
|
|
|
}
|
|
|
|
|
|
|
|
public static subscript<D>(_ keyPath: WritableKeyPath<DependencyStore, D>) -> D {
|
|
|
|
get { current[keyPath: keyPath] }
|
|
|
|
set { current[keyPath: keyPath] = newValue }
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|