Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty .items array in componet does not trigger "get" event #450

Closed
mStirner opened this issue Apr 25, 2024 · 2 comments
Closed

Empty .items array in componet does not trigger "get" event #450

mStirner opened this issue Apr 25, 2024 · 2 comments
Labels
close Discuss to be closed or closed soon investigate

Comments

@mStirner
Copy link
Member

Steps to reproduce:

wscat --connect http://0.0.0.0:8080/api/events
curl http://127.0.0.1:8080/api/devices

If no room items are set/defined, (curls shows only the empty json array "[]"), wscat does not show anything/get event.
When a item is added, wscat show something.

[
  {
    "_id": "65818918d32dad8dab53e433",
    "name": "SmartMeter",
    "interfaces": [
      {
        "_id": "6581c55abc21a0a3122b9998",
        "type": "ETHERNET",
        "description": "WebSocket API",
        "settings": {
          "host": "192.168.2.155",
          "port": 8080,
          "socket": "tcp",
          "mac": null
        },
        "adapter": [
          "raw"
        ]
      }
    ],
    "room": "62a4bc8bd9256b5e8d6988a0",
    "icon": "fa-solid fa-gauge-high",
    "labels": [
      "test=true",
      "protected=false",
      "foo=bar"
    ],
    "timestamps": {
      "created": 1713963788927,
      "updated": null
    },
    "enabled": true
  }
]
@mStirner
Copy link
Member Author

Thought:

If no item exists, what are there to "get"? A empty array?
Why should a empty array emit/trigger a get?

@mStirner mStirner added the close Discuss to be closed or closed soon label May 22, 2024
@mStirner
Copy link
Member Author

The cause of this "problem" is the get trap:

get: (target, prop) => {
// ignore all methods/properties
// NOTE check if prop is a number/index?
if (new RegExp(/^\d+$/).test(prop)) {
this.events.emit("get", target[prop]);
}
return target[prop];
},

When a http call is done on a empty component items array it looks like this:

get trap;  length
get trap;  slice
get trap;  length
get trap;  constructor

However, when there are items in the array, it looks like this:

get trap;  length
get trap;  slice
get trap;  length
get trap;  constructor
get trap;  0
get trap;  1

Each number then triggers a "get" event. On a empty array there a simple not indexes to access.
Therefor no get event is triggered.

@mStirner mStirner closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
close Discuss to be closed or closed soon investigate
Projects
None yet
Development

No branches or pull requests

1 participant