(originalRender: any)
| 179 | } |
| 180 | |
| 181 | function 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 | |
| 217 | function createReaction(admin: ObserverAdministration) { |
| 218 | return new Reaction(`${admin.name}.render()`, () => { |
nothing calls this directly
no test coverage detected
searching dependent graphs…