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

mobalazs / rotor-framework / 18919729013

29 Oct 2025 07:21PM UTC coverage: 85.379% (-0.1%) from 85.479%
18919729013

push

github

mobalazs
fix: update debug setting in bsconfig to enable debugging

1781 of 2086 relevant lines covered (85.38%)

1.16 hits per line

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

80.0
/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
        ' =============================================================
24
        ' CONSTRUCTOR
25
        ' =============================================================
26

27
        ' ---------------------------------------------------------------------
28
        ' new - Initializes the DispatcherProviderPlugin instance
29
        '
30
        ' @param {string} key - Plugin identifier (default: "dispatcher")
31
        '
32
        sub new(key = "dispatcher" as string)
33
            super(key)
1✔
34
        end sub
35

36
        ' =============================================================
37
        ' LIFECYCLE HOOKS
38
        ' =============================================================
39

40
        hooks = {
41
            ' ---------------------------------------------------------------------
42
            ' beforeMount - Attaches dispatchers when widget is mounted
43
            '
44
            ' Creates dispatcher facades and stores them in viewModelState.
45
            '
46
            ' @param {object} scope - Plugin instance (m)
47
            ' @param {object} widget - Widget being mounted
48
            '
49
            beforeMount: sub(scope as object, widget as object)
50
                scope.setDispatcherOnContext(widget, scope.key)
1✔
51
            end sub,
52

53
            ' ---------------------------------------------------------------------
54
            ' beforeUpdate - Updates dispatcher configuration
55
            '
56
            ' Extends existing dispatcher list with new IDs (prevents duplicates).
57
            ' Creates facades for any newly added dispatchers.
58
            '
59
            ' @param {object} scope - Plugin instance (m)
60
            ' @param {object} widget - Widget being updated
61
            ' @param {dynamic} newValue - New dispatcher ID(s)
62
            ' @param {dynamic} oldValue - Previous dispatcher ID(s)
63
            '
64
            beforeUpdate: sub(scope as object, widget as object, newValue, oldValue = [])
65
                ' Merge old and new dispatcher IDs (no duplicates)
66
                oldArrayOfDispatcherIds = Rotor.Utils.ensureArray(oldValue ?? [])
×
67
                newArrayOfDispatcherIds = Rotor.Utils.ensureArray(newValue)
×
68
                widget[scope.key] = Rotor.Utils.extendArrayOfStrings(oldArrayOfDispatcherIds, newArrayOfDispatcherIds)
×
69
                scope.setDispatcherOnContext(widget, scope.key)
×
70
            end sub,
71

72
            ' ---------------------------------------------------------------------
73
            ' beforeDestroy - Cleans up dispatchers before widget destruction
74
            '
75
            ' Destroys all dispatcher facades and clears references.
76
            '
77
            ' @param {object} scope - Plugin instance (m)
78
            ' @param {object} widget - Widget being destroyed
79
            '
80
            beforeDestroy: sub(scope as object, widget as object)
81
                dispatcherFacades = widget.viewModelState[scope.key]
1✔
82
                if dispatcherFacades.Count() > 0
3✔
83
                    for each dispatcherFacadeKey in dispatcherFacades
1✔
84
                        dispatcherFacadeInstance = dispatcherFacades[dispatcherFacadeKey]
1✔
85
                        dispatcherFacadeInstance.destroy()
1✔
86
                        widget.viewModelState[scope.key][dispatcherFacadeKey] = invalid
1✔
87
                    end for
88
                end if
89
            end sub
90
        }
91

92
        ' =============================================================
93
        ' DISPATCHER MANAGEMENT
94
        ' =============================================================
95

96
        ' ---------------------------------------------------------------------
97
        ' setDispatcherOnContext - Creates and stores dispatcher facades
98
        '
99
        ' For each dispatcher ID in the widget config:
100
        '   1. Initializes viewModelState.dispatcher object if needed
101
        '   2. Checks if facade already exists for this ID
102
        '   3. Creates new facade via DispatcherProvider if not present
103
        '   4. Stores facade in viewModelState.dispatcher[dispatcherId]
104
        '
105
        ' @param {object} widget - Widget instance
106
        ' @param {string} scopeKey - Plugin key (typically "dispatcher")
107
        '
108
        sub setDispatcherOnContext(widget, scopeKey)
109
            viewModelState = widget.viewModelState
1✔
110
            config = widget[scopeKey]
1✔
111

112
            for each dispatcherId in Rotor.Utils.ensureArray(config)
1✔
113
                ' Initialize dispatcher storage in viewModelState
114
                if viewModelState[m.key] = invalid then viewModelState[m.key] = {}
1✔
115

116
                ' Create facade if it doesn't exist
117
                if not viewModelState[m.key].DoesExist(dispatcherId)
3✔
118
                    globalScope = GetGlobalAA()
1✔
119
                    frameworkInstance = globalScope.rotor_framework_helper.frameworkInstance
1✔
120
                    viewModelState[m.key][dispatcherId] = frameworkInstance.dispatcherProvider.getFacade(dispatcherId, widget)
1✔
121
                end if
122
            end for
123
        end sub
124

125
    end class
126

127
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