Skip to content

[feature] optimize withViewModel HOC (remove observer wrapper)#51

Open
js2me wants to merge 1 commit into
masterfrom
refactor/optimize-with-view-model-hoc
Open

[feature] optimize withViewModel HOC (remove observer wrapper)#51
js2me wants to merge 1 commit into
masterfrom
refactor/optimize-with-view-model-hoc

Conversation

@js2me
Copy link
Copy Markdown
Owner

@js2me js2me commented Jan 23, 2026

Summary by CodeRabbit

  • Tests

    • Added comprehensive tests for component mount and unmount state transitions
    • Enhanced payload validation accuracy in existing tests
  • Refactor

    • Optimized internal rendering logic to improve performance and reduce unnecessary renders

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 23, 2026

📝 Walkthrough

Walkthrough

Refactored the withViewModel HOC to use mobx-react-lite's <Observer> component instead of wrapping with observer(). Moved render decision logic inside the Observer callback. Removed top-level observer wrapping from the HOC. Updated tests to reflect behavioral changes.

Changes

Cohort / File(s) Summary
Changeset documentation
.changeset/tame-lands-drive.md
Added entry documenting minor version bump for "mobx-view-model" with optimization description: refactor withViewModel HOC by replacing observer() wrap with <Observer> component.
Test updates
src/react/hoc/with-view-model.test.tsx
Added two new tests for isMounted state transitions. Updated render count expectations in existing tests (2→1). Enhanced payload validation with strict object matching for techreviewId and selectedCompIds.
Implementation refactoring
src/react/hoc/with-view-model.tsx
Introduced Observer import and replaced direct rendering with Observer-wrapped render path. Moved isRenderAllowed logic inside Observer callback. Removed explicit early return outside observer context and eliminated top-level observer() wrapping on HOC wrapper. Retained inner component observer wrapping when enabled.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A hop, a skip, with Observer in place,
No more wrapping the HOC's embrace!
Render logic dances inside the flow,
Tests now tell a simpler story to know.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly and specifically describes the main optimization in the changeset: refactoring the withViewModel HOC by removing the observer wrapper.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/optimize-with-view-model-hoc

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@js2me
Copy link
Copy Markdown
Owner Author

js2me commented Jan 24, 2026

Меняет поведение инициализации классов VM - написать больше юнит тестов

@js2me js2me changed the title feat: optimize withViewModel HOC (remove observer wrapper) [feature] optimize withViewModel HOC (remove observer wrapper) Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant