You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
trackDerivedFunction<T>(derivation: IDerivation, f: () => T, context: any) {
const prevAllowStateReads = allowStateReadsStart(true)
// pre allocate array allocation + room for variation in deps
// array will be trimmed by bindDependencies
changeDependenciesStateTo0(derivation)
derivation.newObserving_ = new Array(derivation.observing_.length + 100)
derivation.unboundDepsCount_ = 0
derivation.runId_ = ++globalState.runId
const prevTracking = globalState.trackingDerivation
globalState.trackingDerivation = derivation
globalState.inBatch++
let result
if (globalState.disableErrorBoundaries === true) {
result = f.call(context)
} else {
try {
// 这里通过globalState同步关联
result = f.call(context)
} catch (e) {
result = new CaughtException(e)
}
}
globalState.inBatch--
globalState.trackingDerivation = prevTracking
// 这个地方是把Reaction 绑定到observable
bindDependencies(derivation)
warnAboutDerivationWithoutDependencies(derivation)
allowStateReadsEnd(prevAllowStateReads)
return result
}
const reaction = new Reaction(`${initialName}.render()`, () => {
if (!isRenderingPending) {
// N.B. Getting here *before mounting* means that a component constructor has side effects (see the relevant test in misc.js)
// This unidiomatic React usage but React will correctly warn about this so we continue as usual
// See #85 / Pull #44
isRenderingPending = true
if (this[mobxIsUnmounted] !== true) {
let hasError = true
try {
setHiddenProp(this, isForcingUpdateKey, true)
if (!this[skipRenderKey]) Component.prototype.forceUpdate.call(this)
hasError = false
} finally {
setHiddenProp(this, isForcingUpdateKey, false)
if (hasError) reaction.dispose()
}
}
}
})
why it doesn't re-render when i update simple context object, and it does when i update MOBX object?
mobx推荐不使用setstate是在说什么
通过几个问题来理解mobx的逻辑
how can let React render?how can let react escape rerender?
there are useState, setState and force-update
how MOBX render?
what does the inject of Mobx-react do?
what does the observe of Mobx-react do?
why it doesn't re-render when i update simple context object, and it does when i update MOBX object?
针对问题的思考
总结
同步是否易于开发?(就是个个人感知问题!)是不是最优解哪?hooks能不能解决上述问题
我的总结没有答案。我想说的是:基于一点点的不同,一点点的变化,一点点的用户习惯,造轮子有没有必要?前端生态的繁荣有时候就是靠这些一点点,才有我们今天应对各种场景时,选择方案的从容。
so保持开放的心态,持续学习
The text was updated successfully, but these errors were encountered: