Hi everyone. I develop site with roles system. Sometimes user can access some states and sometimes not.
The easiest way to handle this constrains is:
// $currentUser -> service representing current user
$rootScope.$on('$stateChangeStart', function(event, toState) {
if (toState.name == 'private_page' && $currentUser.canAccess(toState.name) == false) {
event.preventDefault;
alert("go away, please");
}
})
This is okay solution, but not in cases where we have many states and many different constraints. This produce many event handlers and personally i think what guard constraints is a "state machine" responsibility ;) Also i don't like idea to define "guard functions" in separate place. I think this constraints should be defined in-place like this:
Hi everyone. I develop site with roles system. Sometimes user can access some states and sometimes not.
The easiest way to handle this constrains is:
This is okay solution, but not in cases where we have many states and many different constraints. This produce many event handlers and personally i think what guard constraints is a "state machine" responsibility ;) Also i don't like idea to define "guard functions" in separate place. I think this constraints should be defined in-place like this:
I patch some internals and implementation looks pretty easy:
So if community like this idea i will provide patch and tests. The main motivation for me: "State machine should handle guard conditions by self".