我目前无法使用StateManager来管理哪个状态应该处于活动状态,具体取决于对服务器的会话检查.我本以为有一个启动状态来检查会话并确定一个退出或签名状态是否应该是活动的.
App = Ember.Application.create(); App.sessionController = Ember.Object.create({ signedIn: false,isSignedIn: function() { return this.signedIn; },signOut: function() { this.signedIn = false; App.stateManager.goToState('signedout'); },signIn: function() { this.signedIn = true; App.stateManager.goToState('signedin'); } }); App.stateManager = Ember.StateManager.create({ start: Ember.State.create({ enter: function(sm) { this._super(sm); if (App.sessionController.isSignedIn()) { sm.goToState('signedin'); } else { sm.goToState('signedout'); } } }),signedin: Ember.State.create({ enter: function(sm) { this._super(sm); console.log('entered signedin state'); },exit: function(sm) { this._super(sm); console.log('exited signedin state'); } }),signedout: Ember.State.create({ enter: function(sm) { this._super(sm); console.log('entered signedout state'); },exit: function(sm) { this._super(sm); console.log('exited signedout state'); } }) }); App.sessionController.signIn();
这样做似乎导致退出无法正确执行.所以我问,处理需要身份验证的Ember.js应用程序的状态的首选方法(正如我的显然是错误的)是什么?