• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mobalazs / rotor-framework / 21648678972

03 Feb 2026 09:32PM UTC coverage: 85.951% (-0.8%) from 86.779%
21648678972

push

github

web-flow
Refactor/focus plugin and view model changes (#22)

* refactor(Focus Plugin): enhance spatial navigation rules and add direction validation
* fix(WidgetCreate): enhance self-update logic for ViewModels by including id and HID
* refactor(Focus Plugin): enhance focus management during widget destruction and restoration
* refactor(Focus Plugin): improve lastFocusedHID fallback logic to check both focus items and groups
* refactor(ViewModel Reference): update onUpdateView documentation for clarity on default behavior and customization options
* update(copyright): update copyright year to 2025-2026

77 of 113 new or added lines in 2 files covered. (68.14%)

2 existing lines in 1 file now uncovered.

2074 of 2413 relevant lines covered (85.95%)

1.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/src/source/base/BaseViewModel.bs
1
namespace Rotor
2

3
    ' =====================================================================
4
    ' ViewModel (BaseViewModel) - Base class for ViewModels that extends Widget to provide view lifecycle management
5
    '
6
    ' ViewModels act as controllers for views, managing:
7
    '   - props: Immutable properties passed from parent (read-only)
8
    '   - viewModelState: Mutable local state (read-write)
9
    '   - template: Declarative UI structure
10
    '   - Lifecycle hooks: onCreateView, onMountView, onUpdateView, onDestroyView
11
    '
12
    ' Key Features:
13
    '   - Scoped state: props and viewModelState shared across all child widgets
14
    '   - Template system: template() returns widget tree configuration
15
    '   - Lifecycle management: Hooks for view creation, mounting, updates, destruction
16
    '   - No prop drilling: Children access parent ViewModel state directly
17
    ' =====================================================================
18
    class ViewModel extends Rotor.Widget
19

20
        ' =============================================================
21
        ' MEMBER VARIABLES
22
        ' =============================================================
23

24
        isViewModel = true ' Identifies this as a ViewModel
25

26
        viewModelState = {} ' Mutable state shared across ViewModel's widgets
27
        props = {} ' Immutable props shared across ViewModel's widgets
28

29
        ' =============================================================
30
        ' PROPS MANAGEMENT
31
        ' =============================================================
32

33
        ' ---------------------------------------------------------------------
34
        ' setProps - Updates props and triggers view update
35
        '
36
        ' Merges new props into existing props and calls onUpdateView lifecycle hook.
37
        '
38
        ' @param {object} newProps - New properties to merge
39
        '
40
        sub setProps(newProps as object)
41
            m.props.append(newProps)
1✔
42
            m.onUpdateView()
1✔
43
        end sub
44

45
        ' =============================================================
46
        ' LIFECYCLE HOOKS
47
        ' =============================================================
48

49
        ' ---------------------------------------------------------------------
50
        ' onCreateView - Called when view is being created
51
        '
52
        ' Override to perform initialization tasks before template is generated.
53
        ' Use this to set up initial viewModelState or props.
54
        '
55
        sub onCreateView()
56
        end sub
57

58
        ' ---------------------------------------------------------------------
59
        ' onTemplateCreated - Called after template has been created
60
        '
61
        ' Override to access and modify the created template structure.
62
        ' Useful for dynamic template manipulation.
63
        '
64
        ' @param {object} template - The created template object
65
        '
66
        sub onTemplateCreated(template as object)
67
        end sub
68

69
        ' ---------------------------------------------------------------------
70
        ' onMountView - Called when view is mounted to SceneGraph
71
        '
72
        ' Override to perform post-mount operations like starting animations,
73
        ' fetching data, or setting up observers.
74
        '
75
        sub onMountView()
76
        end sub
77

78
        ' ---------------------------------------------------------------------
79
        ' onUpdateView - Called when view needs to update
80
        '
81
        ' Override to handle state or props changes.
82
        ' Called automatically when setProps() is invoked.
83
        '
84
        sub onUpdateView()
85
            ' Re-render template
NEW
86
            m.render()
×
87
        end sub
88

89
        ' ---------------------------------------------------------------------
90
        ' onDestroyView - Called when view is being destroyed
91
        '
92
        ' Override to perform cleanup tasks like removing observers,
93
        ' stopping timers, or clearing resources.
94
        '
95
        sub onDestroyView()
96
        end sub
97

98
        ' =============================================================
99
        ' TEMPLATE
100
        ' =============================================================
101

102
        ' ---------------------------------------------------------------------
103
        ' template - Returns view template structure
104
        '
105
        ' Override to define custom view structure using declarative widget config.
106
        ' Return an object with widget configuration including children.
107
        '
108
        ' @returns {object} Widget tree configuration
109
        '
110
        ' Example:
111
        '   function template() as object
112
        '       return {
113
        '           nodeType: "Group",
114
        '           children: [
115
        '               { id: "label", nodeType: "Label", fields: { text: m.props.title } }
116
        '           ]
117
        '       }
118
        '   end function
119
        '
120
        function template() as object
121
            return {}
1✔
122
        end function
123

124
    end class
125

126
end namespace
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc