杨锴
2025-04-16 09a372bc45fde16fd42257ab6f78b8deeecf720b
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
//  Bag+Rx.swift
//  RxSwift
//
//  Created by Krunoslav Zaher on 10/19/16.
//  Copyright © 2016 Krunoslav Zaher. All rights reserved.
//
 
 
// MARK: forEach
 
@inline(__always)
func dispatch<Element>(_ bag: Bag<(Event<Element>) -> Void>, _ event: Event<Element>) {
    bag._value0?(event)
 
    if bag._onlyFastPath {
        return
    }
 
    let pairs = bag._pairs
    for i in 0 ..< pairs.count {
        pairs[i].value(event)
    }
 
    if let dictionary = bag._dictionary {
        for element in dictionary.values {
            element(event)
        }
    }
}
 
/// Dispatches `dispose` to all disposables contained inside bag.
func disposeAll(in bag: Bag<Disposable>) {
    bag._value0?.dispose()
 
    if bag._onlyFastPath {
        return
    }
 
    let pairs = bag._pairs
    for i in 0 ..< pairs.count {
        pairs[i].value.dispose()
    }
 
    if let dictionary = bag._dictionary {
        for element in dictionary.values {
            element.dispose()
        }
    }
}