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

mobalazs / rotor-framework / 20096587030

10 Dec 2025 11:11AM UTC coverage: 69.168% (-16.5%) from 85.707%
20096587030

Pull #11

github

web-flow
Merge 015752b30 into 5c8e97a93
Pull Request #11: Refactor/plugin adapter and decorators

52 of 84 new or added lines in 8 files covered. (61.9%)

328 existing lines in 3 files now uncovered.

1438 of 2079 relevant lines covered (69.17%)

0.92 hits per line

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

78.95
/src/source/plugins/DispatcherProviderPlugin.bs
1
import "../base/BasePlugin.bs"
2

3
namespace Rotor
4

5
    ' =====================================================================
6
    ' DispatcherProviderPlugin - Manages MVI dispatcher integration with widgets
7
    '
8
    ' Rotor Framework plugin for managing MVI dispatcher integration with widgets.
9
    '
10
    ' Key Responsibilities:
11
    '   - Provides dispatcher facades to widgets for state management
12
    '   - Manages dispatcher lifecycle (creation, updates, cleanup)
13
    '   - Integrates cross-thread MVI pattern with widget context
14
    '   - Stores dispatcher references in viewModelState for easy access
15
    '
16
    ' Usage:
17
    '   Widget config: dispatcher: "dispatcherId" or dispatcher: ["id1", "id2"]
18
    '   Access: widget.viewModelState.dispatcher[dispatcherId]
19
    '
20
    ' =====================================================================
21
    class DispatcherProviderPlugin extends Rotor.BasePlugin
22

23
        pluginKey = "dispatcher"
24

25
        ' =============================================================
26
        ' LIFECYCLE HOOKS
27
        ' =============================================================
28

29
        hooks = {
30
            ' ---------------------------------------------------------------------
31
            ' beforeMount - Attaches dispatchers when widget is mounted
32
            '
33
            ' Creates dispatcher facades and stores them in viewModelState.
34
            '
35
            ' @param {object} scope - Plugin instance (m)
36
            ' @param {object} widget - Widget being mounted
37
            '
38
            beforeMount: sub(scope as object, widget as object)
39
                scope.setDispatcherOnContext(widget, scope.pluginKey)
1✔
40
            end sub,
41

42
            ' ---------------------------------------------------------------------
43
            ' beforeUpdate - Updates dispatcher configuration
44
            '
45
            ' Extends existing dispatcher list with new IDs (prevents duplicates).
46
            ' Creates facades for any newly added dispatchers.
47
            '
48
            ' @param {object} scope - Plugin instance (m)
49
            ' @param {object} widget - Widget being updated
50
            ' @param {dynamic} newValue - New dispatcher ID(s)
51
            ' @param {dynamic} oldValue - Previous dispatcher ID(s)
52
            '
53
            beforeUpdate: sub(scope as object, widget as object, newValue, oldValue = [])
54
                ' Merge old and new dispatcher IDs (no duplicates)
55
                oldArrayOfDispatcherIds = Rotor.Utils.ensureArray(oldValue ?? [])
×
56
                newArrayOfDispatcherIds = Rotor.Utils.ensureArray(newValue)
×
NEW
57
                widget[scope.pluginKey] = Rotor.Utils.extendArrayOfStrings(oldArrayOfDispatcherIds, newArrayOfDispatcherIds)
×
NEW
58
                scope.setDispatcherOnContext(widget, scope.pluginKey)
×
59
            end sub,
60

61
            ' ---------------------------------------------------------------------
62
            ' beforeDestroy - Cleans up dispatchers before widget destruction
63
            '
64
            ' Destroys all dispatcher facades and clears references.
65
            '
66
            ' @param {object} scope - Plugin instance (m)
67
            ' @param {object} widget - Widget being destroyed
68
            '
69
            beforeDestroy: sub(scope as object, widget as object)
70
                dispatcherFacades = widget.viewModelState[scope.pluginKey]
1✔
71
                if dispatcherFacades.Count() > 0
3✔
72
                    for each dispatcherFacadeKey in dispatcherFacades
1✔
73
                        dispatcherFacadeInstance = dispatcherFacades[dispatcherFacadeKey]
1✔
74
                        dispatcherFacadeInstance.destroy()
1✔
75
                        widget.viewModelState[scope.pluginKey][dispatcherFacadeKey] = invalid
1✔
76
                    end for
77
                end if
78
            end sub
79
        }
80

81
        ' =============================================================
82
        ' DISPATCHER MANAGEMENT
83
        ' =============================================================
84

85
        ' ---------------------------------------------------------------------
86
        ' setDispatcherOnContext - Creates and stores dispatcher facades
87
        '
88
        ' For each dispatcher ID in the widget config:
89
        '   1. Initializes viewModelState.dispatcher object if needed
90
        '   2. Checks if facade already exists for this ID
91
        '   3. Creates new facade via DispatcherProvider if not present
92
        '   4. Stores facade in viewModelState.dispatcher[dispatcherId]
93
        '
94
        ' @param {object} widget - Widget instance
95
        ' @param {string} scopeKey - Plugin key (typically "dispatcher")
96
        '
97
        sub setDispatcherOnContext(widget, scopeKey)
98
            viewModelState = widget.viewModelState
1✔
99
            config = widget[scopeKey]
1✔
100

101
            for each dispatcherId in Rotor.Utils.ensureArray(config)
1✔
102
                ' Initialize dispatcher storage in viewModelState
103
                if viewModelState[m.pluginKey] = invalid then viewModelState[m.pluginKey] = {}
1✔
104

105
                ' Create facade if it doesn't exist
106
                if not viewModelState[m.pluginKey].DoesExist(dispatcherId)
3✔
107
                    globalScope = GetGlobalAA()
1✔
108
                    frameworkInstance = globalScope.rotor_framework_helper.frameworkInstance
1✔
109
                    viewModelState[m.pluginKey][dispatcherId] = frameworkInstance.dispatcherProvider.getFacade(dispatcherId, widget)
1✔
110
                end if
111
            end for
112
        end sub
113

114
    end class
115

116
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