Преглед изворни кода

ref(ToolbarButton): Remove dispatch

master
hristoterezov пре 7 година
родитељ
комит
025f7204d5

+ 35
- 47
react/features/toolbox/components/Toolbar.web.js Прегледај датотеку

23
      * @static
23
      * @static
24
      */
24
      */
25
     static propTypes = {
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
          * Children of current React component.
27
          * Children of current React component.
39
          */
28
          */
44
          */
33
          */
45
         className: React.PropTypes.string,
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
          * Map with toolbar buttons.
43
          * Map with toolbar buttons.
49
          */
44
          */
80
         return (
75
         return (
81
             <div
76
             <div
82
                 className = { `toolbar ${className}` }
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
                     [ ...this.props.toolbarButtons.entries() ]
81
                     [ ...this.props.toolbarButtons.entries() ]
87
-                        .reduce(this._renderToolbarButton, [])
82
+                    .reduce(this._renderToolbarButton, [])
88
                 }
83
                 }
89
                 {
84
                 {
90
                     this.props.children
85
                     this.props.children
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
      * Renders toolbar button. Method is passed to reduce function.
112
      * Renders toolbar button. Method is passed to reduce function.
98
      *
113
      *
120
 
135
 
121
         const { onClick, onMount, onUnmount } = button;
136
         const { onClick, onMount, onUnmount } = button;
122
 
137
 
138
+        const onClickHandler
139
+            = (...args) =>
140
+                onClick(this.props.dispatch, ...args);
141
+
123
         acc.push(
142
         acc.push(
124
             <ToolbarButton
143
             <ToolbarButton
125
                 button = { button }
144
                 button = { button }
126
                 key = { key }
145
                 key = { key }
127
-                onClick = { onClick }
146
+                onClick = { onClickHandler }
128
                 onMount = { onMount }
147
                 onMount = { onMount }
129
                 onUnmount = { onUnmount }
148
                 onUnmount = { onUnmount }
130
                 tooltipPosition = { tooltipPosition } />
149
                 tooltipPosition = { tooltipPosition } />
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
 /* @flow */
1
 /* @flow */
2
 
2
 
3
 import React from 'react';
3
 import React from 'react';
4
-import { connect } from 'react-redux';
5
 
4
 
6
 import { translate } from '../../base/i18n';
5
 import { translate } from '../../base/i18n';
7
 
6
 
37
          */
36
          */
38
         button: React.PropTypes.object.isRequired,
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
          * Handler for component mount.
40
          * Handler for component mount.
47
          */
41
          */
157
         } = button;
151
         } = button;
158
 
152
 
159
         if (enabled && !unclickable && onClick) {
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
     }
234
     }
245
 }
235
 }
246
 
236
 
247
-export default translate(connect()(ToolbarButton));
237
+export default translate(ToolbarButton);

+ 8
- 8
react/features/toolbox/defaultToolbarButtons.js Прегледај датотеку

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

Loading…
Откажи
Сачувај