Created
August 16, 2016 09:42
-
-
Save belozer/85e14f3919405b7565522f8e554eaed6 to your computer and use it in GitHub Desktop.
Проблема с bemDom.update()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
modules.define('app', | |
['i-bem-dom', 'render', 'store', 'store-router', 'redux-watch'], | |
function(provide, bemDom, render, store, router, watch) { | |
provide(bemDom.declBlock(this.name, { | |
onSetMod: { | |
js: { | |
'inited': function() { | |
setTimeout(() => this.setMod('showed'), 100); | |
const w = watch(store.getState, 'router.app.handler'); | |
this._unstore = store.subscribe(w(handler => { | |
this.replaceContent(handler); | |
})); | |
}, | |
'': function() { | |
this._unstore(); | |
} | |
} | |
}, | |
replaceContent: function(handler) { | |
const content = this.findChildBlock('content'); | |
bemDom.replace(content.domElem, render( | |
{}, | |
{ | |
block: 'content', | |
mix: [{block: 'app', elem: 'content'}], | |
mods: {handler: handler} | |
} | |
)); | |
} | |
})); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
modules.define('page', | |
['i-bem-dom', 'render', 'store', 'store-router', 'store-auth', 'redux-watch', 'next-tick'], | |
function(provide, bemDom, render, store, router, auth, reduxWatch, nextTick) { | |
provide(bemDom.declBlock(this.name, { | |
onSetMod: { | |
js: { | |
inited: function() { | |
// Так работает | |
nextTick(() => this._onNextTick()); | |
// Так проблема | |
// this._onNextTick(); | |
} | |
} | |
}, | |
_onNextTick: function() { | |
this._authCheck(); | |
const w = reduxWatch(store.getState, 'auth.user'); | |
store.subscribe(w(user => { | |
if (user) { | |
this.onLogin(user); | |
} else { | |
this.onLogout(); | |
} | |
})); | |
}, | |
_authCheck: function() { | |
const state = store.getState(); | |
if (auth.isAuth()) { | |
this.onLogin(state.auth.user); | |
} else { | |
this.onLogout(); | |
} | |
}, | |
onLogin: function(userData) { | |
this.delMod('bg-fill'); | |
const handler = router.currentHandler(); | |
bemDom.update(this.domElem, render( | |
{isAuth: true, user: userData, contentHandler: handler}, | |
{block: 'app'} | |
)); | |
}, | |
onLogout: function() { | |
this.setMod('bg-fill'); | |
bemDom.update(this.domElem, render( | |
{isAuth: false}, | |
{block: 'app'} | |
)); | |
} | |
})); | |
}); | |
modules.require('page', function() {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Если делать без некстика в page, то код в
app
будет срабатывать 2 раза (в призрачном инстансе и в реальном)