mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
Use IsEmpty rather than nullcheck for scbus types
* Use IsEmpty rather than nullcheck for scbus types
This commit is contained in:
parent
e2e71898c1
commit
fe3ffd1545
@ -72,16 +72,16 @@ func (*ModelUpdatePacketType) GetType() string {
|
||||
return ModelUpdateStr
|
||||
}
|
||||
|
||||
func (mu *ModelUpdatePacketType) IsEmpty() bool {
|
||||
if mu == nil || mu.Data == nil {
|
||||
func (upk *ModelUpdatePacketType) IsEmpty() bool {
|
||||
if upk == nil {
|
||||
return true
|
||||
}
|
||||
return mu.Data.IsEmpty()
|
||||
return upk.Data.IsEmpty()
|
||||
}
|
||||
|
||||
// Clean the ClientData in an update, if present
|
||||
func (upk *ModelUpdatePacketType) Clean() {
|
||||
if upk == nil || upk.Data == nil {
|
||||
if upk.IsEmpty() {
|
||||
return
|
||||
}
|
||||
for _, item := range *(upk.Data) {
|
||||
@ -106,6 +106,9 @@ func MakeUpdatePacket() *ModelUpdatePacketType {
|
||||
|
||||
// Returns the items in the update that are of type I
|
||||
func GetUpdateItems[I ModelUpdateItem](upk *ModelUpdatePacketType) []*I {
|
||||
if upk.IsEmpty() {
|
||||
return nil
|
||||
}
|
||||
ret := make([]*I, 0)
|
||||
for _, item := range *(upk.Data) {
|
||||
if i, ok := (item).(I); ok {
|
||||
|
@ -110,7 +110,7 @@ func MakeUpdateBus() *UpdateBus {
|
||||
|
||||
// Send an update to all channels in the collection
|
||||
func (bus *UpdateBus) DoUpdate(update UpdatePacket) {
|
||||
if update == nil || update.IsEmpty() {
|
||||
if update.IsEmpty() {
|
||||
return
|
||||
}
|
||||
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
|
||||
func (bus *UpdateBus) DoScreenUpdate(screenId string, update UpdatePacket) {
|
||||
if update == nil {
|
||||
if update.IsEmpty() {
|
||||
return
|
||||
}
|
||||
update.Clean()
|
||||
|
Loading…
Reference in New Issue
Block a user