浏览代码

ref(ToolbarButton): Remove dispatch

master
hristoterezov 7 年前
父节点
当前提交
025f7204d5

+ 35
- 47
react/features/toolbox/components/Toolbar.web.js 查看文件

@@ -23,17 +23,6 @@ class Toolbar extends Component {
23 23
      * @static
24 24
      */
25 25
     static propTypes = {
26
-
27
-        /**
28
-         *  Handler for mouse out event.
29
-         */
30
-        _onMouseOut: React.PropTypes.func,
31
-
32
-        /**
33
-         * Handler for mouse over event.
34
-         */
35
-        _onMouseOver: React.PropTypes.func,
36
-
37 26
         /**
38 27
          * Children of current React component.
39 28
          */
@@ -44,6 +33,12 @@ class Toolbar extends Component {
44 33
          */
45 34
         className: React.PropTypes.string,
46 35
 
36
+        /**
37
+         * Used to dispatch an action when a button is clicked or on mouse
38
+         * out/in event.
39
+         */
40
+        dispatch: React.PropTypes.func,
41
+
47 42
         /**
48 43
          * Map with toolbar buttons.
49 44
          */
@@ -80,11 +75,11 @@ class Toolbar extends Component {
80 75
         return (
81 76
             <div
82 77
                 className = { `toolbar ${className}` }
83
-                onMouseOut = { this.props._onMouseOut }
84
-                onMouseOver = { this.props._onMouseOver }>
78
+                onMouseOut = { this._onMouseOut }
79
+                onMouseOver = { this._onMouseOver }>
85 80
                 {
86 81
                     [ ...this.props.toolbarButtons.entries() ]
87
-                        .reduce(this._renderToolbarButton, [])
82
+                    .reduce(this._renderToolbarButton, [])
88 83
                 }
89 84
                 {
90 85
                     this.props.children
@@ -93,6 +88,26 @@ class Toolbar extends Component {
93 88
         );
94 89
     }
95 90
 
91
+    /**
92
+     * Dispatches an action signalling that toolbar is no being hovered.
93
+     *
94
+     * @protected
95
+     * @returns {Object} Dispatched action.
96
+     */
97
+    _onMouseOut() {
98
+        this.props.dispatch(setToolbarHovered(false));
99
+    }
100
+
101
+    /**
102
+     * Dispatches an action signalling that toolbar is now being hovered.
103
+     *
104
+     * @protected
105
+     * @returns {Object} Dispatched action.
106
+     */
107
+    _onMouseOver() {
108
+        this.props.dispatch(setToolbarHovered(true));
109
+    }
110
+
96 111
     /**
97 112
      * Renders toolbar button. Method is passed to reduce function.
98 113
      *
@@ -120,11 +135,15 @@ class Toolbar extends Component {
120 135
 
121 136
         const { onClick, onMount, onUnmount } = button;
122 137
 
138
+        const onClickHandler
139
+            = (...args) =>
140
+                onClick(this.props.dispatch, ...args);
141
+
123 142
         acc.push(
124 143
             <ToolbarButton
125 144
                 button = { button }
126 145
                 key = { key }
127
-                onClick = { onClick }
146
+                onClick = { onClickHandler }
128 147
                 onMount = { onMount }
129 148
                 onUnmount = { onUnmount }
130 149
                 tooltipPosition = { tooltipPosition } />
@@ -134,35 +153,4 @@ class Toolbar extends Component {
134 153
     }
135 154
 }
136 155
 
137
-/**
138
- * Maps part of Redux actions to component's props.
139
- *
140
- * @param {Function} dispatch - Redux action dispatcher.
141
- * @private
142
- * @returns {Object}
143
- */
144
-function _mapDispatchToProps(dispatch: Function): Object {
145
-    return {
146
-        /**
147
-         * Dispatches an action signalling that toolbar is no being hovered.
148
-         *
149
-         * @protected
150
-         * @returns {Object} Dispatched action.
151
-         */
152
-        _onMouseOut() {
153
-            dispatch(setToolbarHovered(false));
154
-        },
155
-
156
-        /**
157
-         * Dispatches an action signalling that toolbar is now being hovered.
158
-         *
159
-         * @protected
160
-         * @returns {Object} Dispatched action.
161
-         */
162
-        _onMouseOver() {
163
-            dispatch(setToolbarHovered(true));
164
-        }
165
-    };
166
-}
167
-
168
-export default connect(undefined, _mapDispatchToProps)(Toolbar);
156
+export default connect()(Toolbar);

+ 2
- 12
react/features/toolbox/components/ToolbarButton.web.js 查看文件

@@ -1,7 +1,6 @@
1 1
 /* @flow */
2 2
 
3 3
 import React from 'react';
4
-import { connect } from 'react-redux';
5 4
 
6 5
 import { translate } from '../../base/i18n';
7 6
 
@@ -37,11 +36,6 @@ class ToolbarButton extends AbstractToolbarButton {
37 36
          */
38 37
         button: React.PropTypes.object.isRequired,
39 38
 
40
-        /**
41
-         * Used to dispatch an action when the button is clicked.
42
-         */
43
-        dispatch: React.PropTypes.func,
44
-
45 39
         /**
46 40
          * Handler for component mount.
47 41
          */
@@ -157,11 +151,7 @@ class ToolbarButton extends AbstractToolbarButton {
157 151
         } = button;
158 152
 
159 153
         if (enabled && !unclickable && onClick) {
160
-            const action = onClick(event);
161
-
162
-            if (action) {
163
-                this.props.dispatch(action);
164
-            }
154
+            onClick(event);
165 155
         }
166 156
     }
167 157
 
@@ -244,4 +234,4 @@ class ToolbarButton extends AbstractToolbarButton {
244 234
     }
245 235
 }
246 236
 
247
-export default translate(connect()(ToolbarButton));
237
+export default translate(ToolbarButton);

+ 8
- 8
react/features/toolbox/defaultToolbarButtons.js 查看文件

@@ -22,10 +22,10 @@ const buttons: Object = {
22 22
         enabled: true,
23 23
         id: 'toolbar_button_add',
24 24
         isDisplayed: () => !APP.store.getState()['features/jwt'].isGuest,
25
-        onClick() {
25
+        onClick(dispatch) {
26 26
             JitsiMeetJS.analytics.sendEvent('toolbar.add.clicked');
27 27
 
28
-            return openAddPeopleDialog();
28
+            dispatch(openAddPeopleDialog());
29 29
         },
30 30
         tooltipKey: 'toolbar.addPeople'
31 31
     },
@@ -167,10 +167,10 @@ const buttons: Object = {
167 167
         // Will be displayed once the SIP calls functionality is detected.
168 168
         hidden: true,
169 169
         id: 'toolbar_button_dial_out',
170
-        onClick() {
170
+        onClick(dispatch) {
171 171
             JitsiMeetJS.analytics.sendEvent('toolbar.sip.clicked');
172 172
 
173
-            return openDialOutDialog();
173
+            dispatch(openDialOutDialog());
174 174
         },
175 175
         tooltipKey: 'dialOut.dialOut'
176 176
     },
@@ -185,11 +185,11 @@ const buttons: Object = {
185 185
             return interfaceConfig.filmStripOnly;
186 186
         },
187 187
         id: 'toolbar_button_fodeviceselection',
188
-        onClick() {
188
+        onClick(dispatch) {
189 189
             JitsiMeetJS.analytics.sendEvent(
190 190
                 'toolbar.fodeviceselection.toggled');
191 191
 
192
-            return openDeviceSelectionDialog();
192
+            dispatch(openDeviceSelectionDialog());
193 193
         },
194 194
         sideContainerId: 'settings_container',
195 195
         tooltipKey: 'toolbar.Settings'
@@ -270,10 +270,10 @@ const buttons: Object = {
270 270
         classNames: [ 'button', 'icon-link' ],
271 271
         enabled: true,
272 272
         id: 'toolbar_button_link',
273
-        onClick() {
273
+        onClick(dispatch) {
274 274
             JitsiMeetJS.analytics.sendEvent('toolbar.invite.clicked');
275 275
 
276
-            return openInviteDialog();
276
+            dispatch(openInviteDialog());
277 277
         },
278 278
         tooltipKey: 'toolbar.invite'
279 279
     },

正在加载...
取消
保存