mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-22 16:48: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
|
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 {
|
||||||
|
@ -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()
|
||||||
|
Loading…
Reference in New Issue
Block a user