File tree 3 files changed +47
-22
lines changed 3 files changed +47
-22
lines changed Original file line number Diff line number Diff line change @@ -82,21 +82,28 @@ export function mixin(Vue: VueConstructor) {
82
82
'attrs' , // confirmed in rfc
83
83
// 'listeners', // very likely
84
84
] ;
85
- const method = [
85
+ const methodWithoutReturn = [
86
86
// 'on', // very likely
87
87
// 'once', // very likely
88
88
// 'off', // very likely
89
89
'emit' , // confirmed in rfc
90
90
// 'forceUpdate',
91
91
// 'destroy'
92
92
] ;
93
- props . forEach ( key =>
94
- proxy ( ctx , key , ( ) => vm [ key ] , function ( ) {
93
+ props . forEach ( key => {
94
+ proxy ( ctx , key , ( ) => vm [ `$ ${ key } ` ] , function ( ) {
95
95
Vue . util . warn ( `Cannot assign to '${ key } ' because it is a read-only property` , vm ) ;
96
+ } ) ;
97
+ } ) ;
98
+ methodWithoutReturn . forEach ( key =>
99
+ proxy ( ctx , key , ( ) => {
100
+ const vmKey = `$${ key } ` ;
101
+ return ( ...args : any [ ] ) => {
102
+ const fn : Function = vm [ vmKey ] ;
103
+ fn . apply ( vm , args ) ;
104
+ } ;
96
105
} )
97
106
) ;
98
- method . forEach ( key => proxy ( ctx , key , ( ) => vm [ key ] ) ) ;
99
-
100
107
if ( process . env . NODE_ENV === 'test' ) {
101
108
( ctx as any ) . _vm = vm ;
102
109
}
Original file line number Diff line number Diff line change 1
- import Vue , { ComponentOptions , VNode } from 'vue/' ;
2
- import { NormalizedScopedSlot } from 'vue/types/vnode' ;
1
+ import Vue , { VNode } from 'vue/' ;
3
2
4
3
export interface Context {
5
- readonly el : Element ;
6
- readonly options : ComponentOptions < Vue > ;
7
4
readonly parent : Vue ;
8
5
readonly root : Vue ;
9
- readonly children : Vue [ ] ;
10
6
readonly refs : { [ key : string ] : Vue | Element | Vue [ ] | Element [ ] } ;
11
7
readonly slots : { [ key : string ] : VNode [ ] | undefined } ;
12
- readonly scopedSlots : { [ key : string ] : NormalizedScopedSlot | undefined } ;
13
- readonly isServer : boolean ;
14
- readonly ssrContext : any ;
15
- readonly vnode : VNode ;
16
- readonly attrs : Record < string , string > ; //
17
- readonly listeners : Record < string , Function | Function [ ] > ;
8
+ readonly attrs : Record < string , string > ;
18
9
19
- on ( event : string | string [ ] , callback : Function ) : this;
20
- once ( event : string | string [ ] , callback : Function ) : this;
21
- off ( event ?: string | string [ ] , callback ?: Function ) : this;
22
- emit ( event : string , ...args : any [ ] ) : this;
23
- forceUpdate ( ) : void ;
24
- destroy ( ) : void ;
10
+ emit ( event : string , ...args : any [ ] ) : void ;
25
11
}
Original file line number Diff line number Diff line change @@ -11,6 +11,38 @@ describe('setup', () => {
11
11
warn . mockRestore ( ) ;
12
12
} ) ;
13
13
14
+ it ( 'should reveive props as first params' , done => {
15
+ new Vue ( {
16
+ props : [ 'a' ] ,
17
+ setup ( props ) {
18
+ expect ( props . a ) . toBe ( 1 ) ;
19
+ done ( ) ;
20
+ } ,
21
+ propsData : {
22
+ a : 1 ,
23
+ } ,
24
+ } ) ;
25
+ } ) ;
26
+
27
+ it ( 'should reveive context second params' , done => {
28
+ new Vue ( {
29
+ setup ( _ , ctx ) {
30
+ expect ( ctx ) . toBeDefined ( ) ;
31
+ expect ( 'parent' in ctx ) . toBe ( true ) ;
32
+ expect ( ctx ) . toEqual (
33
+ expect . objectContaining ( {
34
+ root : expect . any ( Object ) ,
35
+ refs : expect . any ( Object ) ,
36
+ slots : expect . any ( Object ) ,
37
+ attrs : expect . any ( Object ) ,
38
+ emit : expect . any ( Function ) ,
39
+ } )
40
+ ) ;
41
+ done ( ) ;
42
+ } ,
43
+ } ) ;
44
+ } ) ;
45
+
14
46
it ( 'warn for exist property(data)' , ( ) => {
15
47
new Vue ( {
16
48
data ( ) {
You can’t perform that action at this time.
0 commit comments