Famous / Famous/framework

Cannot use `$if` together with setting `$state` from within `$lifecycle`

Open
#44 9 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

In short, I can't use `$if` together with setting `$state` from within `post-load`.

This works:

```
FamousFramework.scene('ildar:page-controller', {
behaviors: {
// '#home': {
// '$if': function(path) { return path === '/' }
// },
// '#blog': {
// '$if': function(path) { return path === '/blog' }
// },
// '#about': {
// '$if': function(path) { return path === '/about' }
// },
'.page': {
'size': [200, 200],
'align': [0.5, 0.5],
'mount-point': [0.5, 0.5],
'style': {
'background': 'whitesmoke'
}
}
},
events: {
'$lifecycle': {
'post-load': function($state) {
console.log('post-load');
$state.set('path', '/');
}
},
'.page': {
'click': function($state) {
console.log('WORKS');
$state.set('path', '/blog');
}
}
},
states: {
path: null,
},
tree: `

HOME

BLOG

ABOUT

`
});
```

This also works:

```
FamousFramework.scene('ildar:page-controller', {
behaviors: {
'#home': {
'$if': function(path) { return path === '/' }
},
'#blog': {
'$if': function(path) { return path === '/blog' }
},
'#about': {
'$if': function(path) { return path === '/about' }
},
'.page': {
'size': [200, 200],
'align': [0.5, 0.5],
'mount-point': [0.5, 0.5],
'style': {
'background': 'whitesmoke'
}
}
},
events: {
'$lifecycle': {
'post-load': function($state) {
console.log('post-load');
//
// If $state isn't set from here, the code works.
//
// $state.set('path', '/');
}
},
'.page': {
'click': function($state) {
console.log('WORKS');
$state.set('path', '/blog');
}
}
},
states: {
path: '/',
},
tree: `

HOME

BLOG

ABOUT

`
});
```

But this doesn't work:

```
FamousFramework.scene('ildar:page-controller', {
behaviors: {
'#home': {
'$if': function(path) { return path === '/' }
},
'#blog': {
'$if': function(path) { return path === '/blog' }
},
'#about': {
'$if': function(path) { return path === '/about' }
},
'.page': {
'size': [200, 200],
'align': [0.5, 0.5],
'mount-point': [0.5, 0.5],
'style': {
'background': 'whitesmoke'
}
}
},
events: {
'$lifecycle': {
'post-load': function($state) {
console.log('post-load');
$state.set('path', '/');
}
},
'.page': {
'click': function($state) {
console.log('WORKS');
$state.set('path', '/blog');
}
}
},
states: {
path: null,
},
tree: `

HOME

BLOG

ABOUT

`
});
```

Could be related to #41

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.