Skip to content

Commit

Permalink
Use AsyncStream
Browse files Browse the repository at this point in the history
  • Loading branch information
shp7724 committed Sep 6, 2024
1 parent 53c4a71 commit 0160679
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ReactNativeKit/ReactNativeKit/EventEmitter/EventEmitter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public actor EventEmitter<EventType: SupportedEvent> {
RNEventEmitter.shared
}

public var jsEventPublisher: AnyPublisher<JSEvent, Never> {
emitter.jsEventSubject.eraseToAnyPublisher()
public var jsEventStream: AsyncStream<JSEvent> {
emitter.jsEventStream.stream
}

public func emitEvent(_ event: EventType, payload: [AnyHashable: Any]? = [:]) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Combine

@objc(RNEventEmitter)
class RNEventEmitter: RCTEventEmitter {
let jsEventSubject = PassthroughSubject<JSEvent, Never>()
let jsEventStream = AsyncStream.makeStream(of: JSEvent.self)
let registerEventSubject = CurrentValueSubject<RegisterEvent, Never>(.deregister)

private static var _shared: RNEventEmitter?
Expand Down Expand Up @@ -38,11 +38,11 @@ class RNEventEmitter: RCTEventEmitter {
registerEventSubject.value = registerEvent
}
let jsEvent = JSEvent(name: name, payload: payload)
jsEventSubject.send(jsEvent)
jsEventStream.continuation.yield(jsEvent)
}
}

public struct JSEvent {
public struct JSEvent: @unchecked Sendable {
public let name: String
public let payload: [AnyHashable: Any]?
}
Expand Down
1 change: 1 addition & 0 deletions ReactNativeKit/ReactNativeKit/React.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import UIKit
/// - initialProperties: The initial properties that should be passed to the React Native module. These are made available in the React Native application via this.props.
/// - backgroundColor: The background color for the React Native View. Default is .clear.
/// - Returns: A UIView configured to run the specified React Native application.
@MainActor
public func makeReactView(
bundleURL: URL,
moduleName: String,
Expand Down

0 comments on commit 0160679

Please sign in to comment.