Famous / Famous/framework

'$if' causes an error when triggered by a state change from another component

Open
#41 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
394
Forks
62
PR merge metrics
No merged PRs in 30d

Description

This doesn't happen when all the code is in one component. Only when I have two components like this:

```
FamousFramework.component('ildar:my-component', {
behaviors: {
'#test': {
'$if': function(example) {
return example === 'a';
},
},
},
events: {
'#test': {
'test-event': function($state) {
$state.set('example', 'b');
}
}
},
states: {
'example': 'a',
},
tree: `

`
});
```

The other component emits an event (and the previous component above listens to it).

```
FamousFramework.component('ildar:test', {
behaviors: {
'#clickNode': {
'content': "Click me",
}
},
events: {
'#clickNode': {
'click': function($dispatcher) {
$dispatcher.emit('test-event');
}
},
},
tree: `

`
});
```

Clicking on the node causes the following error: `Uncaught TypeError: Cannot read property 'parentNode' of null` in the `while` statement of the function defined in famous-framework.development.bundle.js:

```
Dispatcher.prototype.emit = function(key, message) {
var element = this.domNode;
var event = new CustomEvent(key, {
detail: message,
bubbles: true
});
if (Dispatcher.willEventsBubbleInDetachedDOM) {
element.dispatchEvent(event);
}
else {
while (element.parentNode) {
element.dispatchEvent(event);
element = element.parentNode;
}
}
};
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.