telefonicaid / telefonicaid/iotagent-node-lib
Question: Should this codebase move towards using classes?
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 62
- Forks
- 90
- Avg merge
- 2h 35m
- Merged PRs (30d)
- 1
Description
As I'm sure you know, Node 10 reaches end-of-life at the end of April 2021. Node 12 introduces Public class fields support to Node.
It would therefore make sense to transition to proper class based structure for the codebase.
As an experiment I have converted the Devices directory to use classes and still work with Node 10 and I'm looking on feedback on how to proceed. The full diff can be found here
The new look collects classes with the same interface together (e.g. all files in handlers offer the same interface) and identifies dependencies in a separate folder with a function. It is also easier to see which methods are in the interface and which are just helper methods. The first step shouldn't be creating proper encapsulated constructors - at least whilst node 10 is around, but that could be done later.
Since Node 10 doesn't natively support public class fields there are a few issues I've been having with this pointers e.g:
let mongodb; // single instance
class AlarmDeviceRegistryMongoDB {
constructor() {
mongodb = new DeviceRegistryMongoDB();
}
...
clear(callback) {
alarmsInt(constants.MONGO_ALARM, mongodb.clear(callback));
}
}
works but
class AlarmDeviceRegistryMongoDB {
constructor() {
this.mongodb = new DeviceRegistryMongoDB(); // property of the class
}
...
clear(callback) {
alarmsInt(constants.MONGO_ALARM, this.mongodb.clear(callback));
}
}
runs but doesn't find this in Node 10 and
class AlarmDeviceRegistryMongoDB {
#mongod; // private
constructor() {
this.#mongodb = new DeviceRegistryMongoDB(); // property of the class
}
...
clear(callback) {
alarmsInt(constants.MONGO_ALARM, this.#mongodb.clear(callback));
}
}
doesn't compile in Node 10.
So how to proceed with this work?
- Convert the NGSI handlers one by one as a series of separate PRs? (one for device, entities, subscriptions etc.)
- Create an NGSI handlers big-bang and see if E2E performance is affected?
- Repeat the exercise with Registries (one for device and a second for group or altogether?)
- Combine this with the removal of NGSI-v1 maybe?
Basically looking to create a roadmap for this before doing any serious work.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the proposed conversion in lib/services/devices and the linked feature/class diff, then inspect the NGSI handlers and Registries areas mentioned in the issue. Compare the separate-PR and big-bang options, including Node 10 compatibility and E2E performance concerns. Done means an agreed roadmap for sequencing the refactor and deciding whether to combine it with NGSI-v1 removal.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, backend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100