Famous / Famous/engine

[question] Node removeChild() set to null

Open
#375 6 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
JavaScript
Stars
1.7k
Forks
249
PR merge metrics
No merged PRs in 30d

Description

When Node1.removeChild(node2) is called, the index of node2 in Node1._children array is set to NULL.
This causes an error when, after a removeChild, i use events:

Uncaught TypeError: Cannot read property 'onReceive' of null

here:

Dispatch.prototype.dispatch = function dispatch (event, payload) {
if (!event) throw new Error('dispatch requires an event name as it\'s first argument');

```
var queue = this._queue;
var item;
var i;
var len;
var children;

queue.length = 0;
queue.push(this._context);

while (queue.length) {
item = queue.shift();
if (item.onReceive) item.onReceive(event, payload);
children = item.getChildren();
for (i = 0, len = children.length ; i < len ; i++) queue.push(children[i]);
}
```

};

I managed to fix this, by changing:

this._children[index] = null;

with:

this._children.splice(index, 1);

in the removeChild() function of core/Node.

Is this intentional?
Does this change affect other things?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.