@@ -9,7 +9,7 @@ function getDisplayName(WrappedComponent) {
99}
1010
1111const defaultMapStateToProps = ( ) => ( { } ) ;
12- export default function connect ( mapStateToProps ) {
12+ export default function connect ( mapStateToProps , injectExtraPropsKey ) {
1313 const shouldSubscribe = ! ! mapStateToProps ;
1414 const finalMapStateToProps = mapStateToProps || defaultMapStateToProps ;
1515 return function wrapWithConnect ( WrappedComponent ) {
@@ -25,18 +25,43 @@ export default function connect(mapStateToProps) {
2525 props,
2626 inject : {
2727 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+ } ,
2844 } ,
2945 data ( ) {
3046 this . store = this . storeContext . store ;
31- this . preProps = omit ( getOptionProps ( this ) , [ '__propsSymbol__' ] ) ;
47+ this . preProps = {
48+ ...omit ( getOptionProps ( this ) , [ '__propsSymbol__' ] ) ,
49+ ...this . injectExtraProps ,
50+ } ;
3251 return {
33- subscribed : finalMapStateToProps ( this . store . getState ( ) , this . $props ) ,
52+ subscribed : finalMapStateToProps ( this . store . getState ( ) , {
53+ ...this . $props ,
54+ ...this . injectExtraProps ,
55+ } ) ,
3456 } ;
3557 } ,
3658 watch : {
3759 __propsSymbol__ ( ) {
3860 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+ } ) ;
4065 }
4166 } ,
4267 } ,
@@ -52,7 +77,10 @@ export default function connect(mapStateToProps) {
5277 if ( ! this . unsubscribe ) {
5378 return ;
5479 }
55- const props = omit ( getOptionProps ( this ) , [ '__propsSymbol__' ] ) ;
80+ const props = {
81+ ...omit ( getOptionProps ( this ) , [ '__propsSymbol__' ] ) ,
82+ ...this . injectExtraProps ,
83+ } ;
5684 const nextSubscribed = finalMapStateToProps ( this . store . getState ( ) , props ) ;
5785 if (
5886 ! shallowEqual ( this . preProps , props ) ||
@@ -81,15 +109,15 @@ export default function connect(mapStateToProps) {
81109 } ,
82110 render ( ) {
83111 const { $slots = { } , $scopedSlots, subscribed, store } = this ;
84- const props = getOptionProps ( this ) ;
112+ const props = { ... getOptionProps ( this ) , ... this . injectExtraProps } ;
85113 this . preProps = { ...omit ( props , [ '__propsSymbol__' ] ) } ;
86114 const wrapProps = {
87115 props : {
88116 ...props ,
89117 ...subscribed ,
90118 store,
91119 } ,
92- on : getListeners ( this ) ,
120+ on : { ... getListeners ( this ) , ... this . injectExtraListeners } ,
93121 scopedSlots : $scopedSlots ,
94122 } ;
95123 return (
0 commit comments