Skip to content

Commit

Permalink
Simplify APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
fjaeger committed Jun 25, 2024
1 parent 6b889ed commit 6e9fe8d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
13 changes: 1 addition & 12 deletions Sources/ACActionCable/ACCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public struct ACCommand {

// MARK: Initialization

init?<T: Encodable>(type: ACCommandType, identifier: ACChannelIdentifier, action: String? = nil, object: T? = nil) {
init?(type: ACCommandType, identifier: ACChannelIdentifier, action: String? = nil, object: Encodable? = nil) {
self.type = type
self.identifier = identifier

Expand All @@ -58,17 +58,6 @@ public struct ACCommand {
if type == .message && (self.data ?? [:]).isEmpty { return nil }
}

init?(type: ACCommandType, identifier: ACChannelIdentifier, action: String? = nil) {
self.type = type
self.identifier = identifier

if type == .message {
guard let action else { return nil }

self.data = ["action": action]
}
}

// MARK: Helpers

private func json(from dictionary: [String: Any]) -> String? {
Expand Down
7 changes: 1 addition & 6 deletions Sources/ACActionCable/ACSubscription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,10 @@ public class ACSubscription {

// MARK: Sending

public func send<T: Encodable>(action: String? = nil, object: T, completion: ACEventHandler? = nil) {
public func send(action: String? = nil, object: Encodable? = nil, completion: ACEventHandler? = nil) {
guard let command = ACCommand(type: .message, identifier: channelIdentifier, action: action, object: object) else { return }
client.send(command, completion: completion)
}

public func send(action: String, completion: ACEventHandler? = nil) {
guard let command = ACCommand(type: .message, identifier: channelIdentifier, action: action) else { return }
client.send(command, completion: completion)
}
}

// MARK: Equatable
Expand Down

0 comments on commit 6e9fe8d

Please sign in to comment.