-
Notifications
You must be signed in to change notification settings - Fork 65
Open
Labels
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: `
<node id="home" class="page"> <div> HOME </div> </node>
<node id="blog" class="page"> <div> BLOG </div> </node>
<node id="about" class="page"> <div> ABOUT </div> </node>
`
});
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: `
<node id="home" class="page"> <div> HOME </div> </node>
<node id="blog" class="page"> <div> BLOG </div> </node>
<node id="about" class="page"> <div> ABOUT </div> </node>
`
});
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: `
<node id="home" class="page"> <div> HOME </div> </node>
<node id="blog" class="page"> <div> BLOG </div> </node>
<node id="about" class="page"> <div> ABOUT </div> </node>
`
});
Could be related to #41