Use IsEmpty rather than nullcheck for scbus types

* Use IsEmpty rather than nullcheck for scbus types
This commit is contained in:
Evan Simkowitz 2024-02-16 12:14:05 -08:00 committed by GitHub
parent e2e71898c1
commit fe3ffd1545
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 6 deletions

View File

@ -72,16 +72,16 @@ func (*ModelUpdatePacketType) GetType() string {
return ModelUpdateStr return ModelUpdateStr
} }
func (mu *ModelUpdatePacketType) IsEmpty() bool { func (upk *ModelUpdatePacketType) IsEmpty() bool {
if mu == nil || mu.Data == nil { if upk == nil {
return true return true
} }
return mu.Data.IsEmpty() return upk.Data.IsEmpty()
} }
// Clean the ClientData in an update, if present // Clean the ClientData in an update, if present
func (upk *ModelUpdatePacketType) Clean() { func (upk *ModelUpdatePacketType) Clean() {
if upk == nil || upk.Data == nil { if upk.IsEmpty() {
return return
} }
for _, item := range *(upk.Data) { for _, item := range *(upk.Data) {
@ -106,6 +106,9 @@ func MakeUpdatePacket() *ModelUpdatePacketType {
// Returns the items in the update that are of type I // Returns the items in the update that are of type I
func GetUpdateItems[I ModelUpdateItem](upk *ModelUpdatePacketType) []*I { func GetUpdateItems[I ModelUpdateItem](upk *ModelUpdatePacketType) []*I {
if upk.IsEmpty() {
return nil
}
ret := make([]*I, 0) ret := make([]*I, 0)
for _, item := range *(upk.Data) { for _, item := range *(upk.Data) {
if i, ok := (item).(I); ok { if i, ok := (item).(I); ok {

View File

@ -110,7 +110,7 @@ func MakeUpdateBus() *UpdateBus {
// Send an update to all channels in the collection // Send an update to all channels in the collection
func (bus *UpdateBus) DoUpdate(update UpdatePacket) { func (bus *UpdateBus) DoUpdate(update UpdatePacket) {
if update == nil || update.IsEmpty() { if update.IsEmpty() {
return return
} }
update.Clean() update.Clean()
@ -128,7 +128,7 @@ func (bus *UpdateBus) DoUpdate(update UpdatePacket) {
// Send a model update to only clients that are subscribed to the given screenId // Send a model update to only clients that are subscribed to the given screenId
func (bus *UpdateBus) DoScreenUpdate(screenId string, update UpdatePacket) { func (bus *UpdateBus) DoScreenUpdate(screenId string, update UpdatePacket) {
if update == nil { if update.IsEmpty() {
return return
} }
update.Clean() update.Clean()