MCPcopy Index your code
hub / github.com/mobxjs/mobx / createReactiveRender

Function createReactiveRender

packages/mobx-react/src/observerClass.ts:181–215  ·  view source on GitHub ↗
(originalRender: any)

Source from the content-addressed store, hash-verified

179}
180
181function createReactiveRender(originalRender: any) {
182 const boundOriginalRender = originalRender.bind(this)
183
184 const admin = getAdministration(this)
185
186 function reactiveRender() {
187 if (!admin.reaction) {
188 // Create reaction lazily to support re-mounting #3395
189 admin.reaction = createReaction(admin)
190 if (!admin.mounted) {
191 // React can abandon this instance and never call `componentDidMount`/`componentWillUnmount`,
192 // we have to make sure reaction will be disposed.
193 observerFinalizationRegistry.register(this, admin, this)
194 }
195 }
196
197 let error: unknown = undefined
198 let renderResult = undefined
199 admin.reaction.track(() => {
200 try {
201 // TODO@major
202 // Optimization: replace with _allowStateChangesStart/End (not available in mobx@6.0.0)
203 renderResult = _allowStateChanges(false, boundOriginalRender)
204 } catch (e) {
205 error = e
206 }
207 })
208 if (error) {
209 throw error
210 }
211 return renderResult
212 }
213
214 return reactiveRender
215}
216
217function createReaction(admin: ObserverAdministration) {
218 return new Reaction(`${admin.name}.render()`, () => {

Callers

nothing calls this directly

Calls 1

getAdministrationFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…