Skip to content

Commit 1afe6f6

Browse files
committed
Add subEntry parent tracking
1 parent 40aa3f1 commit 1afe6f6

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "canopen",
3-
"version": "2.7.4",
3+
"version": "2.8.0",
44
"description": "CANopen implementation for Javascript",
55
"main": "index.js",
66
"scripts": {

source/eds.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,12 @@ function typeToRaw(value, type) {
282282
* @protected
283283
*/
284284
class DataObject extends EventEmitter {
285-
constructor(index, subIndex, args) {
285+
constructor(index, subIndex, args, parent=null) {
286286
super();
287287

288288
this.index = index;
289289
this.subIndex = subIndex;
290+
this.parent = parent;
290291

291292
if(args instanceof DataObject)
292293
args = args.objectify();
@@ -634,7 +635,13 @@ class DataObject extends EventEmitter {
634635
if(subIndex > this.subNumber)
635636
throw RangeError(`SubIndex must be >= ${this.subNumber}`)
636637

637-
this._subObjects[subIndex] = new DataObject(this.index, subIndex, args);
638+
if(args instanceof DataObject) {
639+
this._subObjects[subIndex] = args;
640+
}
641+
else {
642+
this._subObjects[subIndex] = new DataObject(
643+
this.index, subIndex, args, this);
644+
}
638645
}
639646
};
640647

@@ -925,7 +932,7 @@ class Eds {
925932
if(entry.subNumber < subIndex)
926933
throw ReferenceError(`0x${index.toString(16)}[${subIndex}] does not exist`);
927934

928-
const subEntry = new DataObject(index, subIndex, args);
935+
const subEntry = new DataObject(index, subIndex, args, entry);
929936
entry[subIndex] = subEntry;
930937

931938
return subEntry;

0 commit comments

Comments
 (0)