-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
InjectStorage.swift
27 lines (23 loc) · 918 Bytes
/
InjectStorage.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import Storage
/// `InjectStorage` subclass of `DelegatedStorage` that uses a `[AnyHashable: Any]`.
open class InjectStorage: DelegatedStorage {
/// `InjectStorage` shared instance.
open class var standard: InjectStorage { shared }
private static let shared = InjectStorage()
var groups = [DependencyGroupKey: InjectStorage]()
var storage = [StoreKey: [Any]]()
/**
Returns the `[Any]` of dependencies associated with the specified `StoreKey`.
- Parameter key: A `StoreKey` in storage.
*/
override open func array(forKey key: StoreKey) -> [Any]? { storage[hash(key)] }
override open func set(object: Any?, forKey key: StoreKey) {
let storeKey = hash(key)
if let dependency = object {
if storage[storeKey] == nil {
storage[storeKey] = [Any]()
}
storage[storeKey]?.append(dependency)
}
}
}