@@ -9,7 +9,7 @@ function getDisplayName(WrappedComponent) {
9
9
}
10
10
11
11
const defaultMapStateToProps = ( ) => ( { } ) ;
12
- export default function connect ( mapStateToProps ) {
12
+ export default function connect ( mapStateToProps , injectExtraPropsKey ) {
13
13
const shouldSubscribe = ! ! mapStateToProps ;
14
14
const finalMapStateToProps = mapStateToProps || defaultMapStateToProps ;
15
15
return function wrapWithConnect ( WrappedComponent ) {
@@ -25,18 +25,43 @@ export default function connect(mapStateToProps) {
25
25
props,
26
26
inject : {
27
27
storeContext : { default : ( ) => ( { } ) } ,
28
+ ...( injectExtraPropsKey
29
+ ? {
30
+ injectExtraContext : {
31
+ from : injectExtraPropsKey ,
32
+ default : ( ) => ( { } ) ,
33
+ } ,
34
+ }
35
+ : { } ) ,
36
+ } ,
37
+ computed : {
38
+ injectExtraProps ( ) {
39
+ return this . injectExtraContext ? this . injectExtraContext . $attrs : { } ;
40
+ } ,
41
+ injectExtraListeners ( ) {
42
+ return this . injectExtraContext ? this . injectExtraContext . $listeners : { } ;
43
+ } ,
28
44
} ,
29
45
data ( ) {
30
46
this . store = this . storeContext . store ;
31
- this . preProps = omit ( getOptionProps ( this ) , [ '__propsSymbol__' ] ) ;
47
+ this . preProps = {
48
+ ...omit ( getOptionProps ( this ) , [ '__propsSymbol__' ] ) ,
49
+ ...this . injectExtraProps ,
50
+ } ;
32
51
return {
33
- subscribed : finalMapStateToProps ( this . store . getState ( ) , this . $props ) ,
52
+ subscribed : finalMapStateToProps ( this . store . getState ( ) , {
53
+ ...this . $props ,
54
+ ...this . injectExtraProps ,
55
+ } ) ,
34
56
} ;
35
57
} ,
36
58
watch : {
37
59
__propsSymbol__ ( ) {
38
60
if ( mapStateToProps && mapStateToProps . length === 2 ) {
39
- this . subscribed = finalMapStateToProps ( this . store . getState ( ) , this . $props ) ;
61
+ this . subscribed = finalMapStateToProps ( this . store . getState ( ) , {
62
+ ...this . $props ,
63
+ ...this . injectExtraProps ,
64
+ } ) ;
40
65
}
41
66
} ,
42
67
} ,
@@ -52,7 +77,10 @@ export default function connect(mapStateToProps) {
52
77
if ( ! this . unsubscribe ) {
53
78
return ;
54
79
}
55
- const props = omit ( getOptionProps ( this ) , [ '__propsSymbol__' ] ) ;
80
+ const props = {
81
+ ...omit ( getOptionProps ( this ) , [ '__propsSymbol__' ] ) ,
82
+ ...this . injectExtraProps ,
83
+ } ;
56
84
const nextSubscribed = finalMapStateToProps ( this . store . getState ( ) , props ) ;
57
85
if (
58
86
! shallowEqual ( this . preProps , props ) ||
@@ -81,15 +109,15 @@ export default function connect(mapStateToProps) {
81
109
} ,
82
110
render ( ) {
83
111
const { $slots = { } , $scopedSlots, subscribed, store } = this ;
84
- const props = getOptionProps ( this ) ;
112
+ const props = { ... getOptionProps ( this ) , ... this . injectExtraProps } ;
85
113
this . preProps = { ...omit ( props , [ '__propsSymbol__' ] ) } ;
86
114
const wrapProps = {
87
115
props : {
88
116
...props ,
89
117
...subscribed ,
90
118
store,
91
119
} ,
92
- on : getListeners ( this ) ,
120
+ on : { ... getListeners ( this ) , ... this . injectExtraListeners } ,
93
121
scopedSlots : $scopedSlots ,
94
122
} ;
95
123
return (
0 commit comments