@@ -70,7 +70,7 @@ public enum ChannelState: String {
70
70
/// Represents the different events that can be sent through
71
71
/// a channel regarding a Channel's lifecycle or
72
72
/// that can be registered to be notified of.
73
- public enum ChannelEvent {
73
+ public enum ChannelEvent : RawRepresentable {
74
74
case heartbeat
75
75
case join
76
76
case leave
@@ -85,7 +85,7 @@ public enum ChannelEvent {
85
85
86
86
case channelReply( String )
87
87
88
- public var raw : String {
88
+ public var rawValue : String {
89
89
switch self {
90
90
case . heartbeat: return " heartbeat "
91
91
case . join: return " phx_join "
@@ -103,8 +103,8 @@ public enum ChannelEvent {
103
103
}
104
104
}
105
105
106
- public init ? ( from type : String ) {
107
- switch type . lowercased ( ) {
106
+ public init ? ( rawValue : String ) {
107
+ switch rawValue . lowercased ( ) {
108
108
case " heartbeat " : self = . heartbeat
109
109
case " phx_join " : self = . join
110
110
case " phx_leave " : self = . leave
@@ -124,30 +124,20 @@ public enum ChannelEvent {
124
124
switch event {
125
125
case . join, . leave, . reply, . error, . close: return true
126
126
case . heartbeat, . all, . insert, . update, . delete, . channelReply: return false
127
- // Most likely new events will be about notification
128
- // not about lifecycle.
129
- @unknown default : return false
130
127
}
131
128
}
132
129
}
133
130
134
- extension ChannelEvent : Equatable {
135
- public static func == ( lhs: ChannelEvent , rhs: ChannelEvent ) -> Bool {
136
- return lhs. raw == rhs. raw
137
- }
138
- }
139
-
140
- /// Represents the different topic
141
- // a channel can subscribe to.
142
- public enum ChannelTopic {
131
+ /// Represents the different topic a channel can subscribe to.
132
+ public enum ChannelTopic : RawRepresentable , Equatable {
143
133
case all
144
134
case schema( _ schema: String )
145
135
case table( _ table: String , schema: String )
146
136
case column( _ column: String , value: String , table: String , schema: String )
147
137
148
138
case heartbeat
149
139
150
- public var raw : String {
140
+ public var rawValue : String {
151
141
switch self {
152
142
case . all: return " realtime:* "
153
143
case . schema( let name) : return " realtime: \( name) "
@@ -157,13 +147,13 @@ public enum ChannelTopic {
157
147
}
158
148
}
159
149
160
- public init ? ( from type : String ) {
161
- if type == " realtime:* " || type == " * " {
150
+ public init ? ( rawValue : String ) {
151
+ if rawValue == " realtime:* " || rawValue == " * " {
162
152
self = . all
163
- } else if type == " phoenix " {
153
+ } else if rawValue == " phoenix " {
164
154
self = . heartbeat
165
155
} else {
166
- let parts = type . split ( separator: " : " )
156
+ let parts = rawValue . replacingOccurrences ( of : " realtime: " , with : " " ) . split ( separator: " : " )
167
157
switch parts. count {
168
158
case 1 :
169
159
self = . schema( String ( parts [ 0 ] ) )
@@ -183,9 +173,3 @@ public enum ChannelTopic {
183
173
}
184
174
}
185
175
}
186
-
187
- extension ChannelTopic {
188
- public static func == ( lhs: ChannelTopic , rhs: ChannelTopic ) -> Bool {
189
- return lhs. raw == rhs. raw
190
- }
191
- }
0 commit comments