1- import  {  mergeRight ,  clone  }  from  'ramda' 
2- 3- export  class  VueInheritance  { 
4-  constructor  ( { 
5-  props, 
6-  methods, 
7-  computed
8-  } )  { 
9-  this . props  =  clone ( props ) 
10-  this . methods  =  clone ( methods ) 
11-  this . computed  =  clone ( computed ) 
1+ import  {  clone ,  isNil ,  isNotNil ,  has ,  isEmpty  }  from  'ramda' 
2+ 3+ /** 
4+  * Vue3Component 
5+  * @class  
6+  * @private  
7+  * @author  pedro.yang、 ocean.tsai 
8+  * @description  
9+  */ 
10+ class  Vue3Component  { 
11+  /** 
12+  * InvalidInterfaceKeys 
13+  * @static  
14+  * @constant  
15+  * @private  
16+  * @type  
17+  * @description  interfaceDefine will be checked, if it conforms to the interface, it return true; otherwise, it returns false. 
18+  */ 
19+  static  InvalidInterfaceKeys  =  Object . freeze ( [ 
20+  'watch' , 
21+  'beforeCreate' ,  'created' , 
22+  'beforeMount' ,  'mounted' ,  'beforeUpdate' ,  'updated' ,  'beforeUnmount' ,  'unmounted' , 
23+  'errorCaptured' ,  'renderTracked' ,  'activated' ,  'deactivated' ,  'serverPrefetch' 
24+  ] ) 
25+ 26+  /** 
27+  * validateInterface 
28+  * @static  
29+  * @method  
30+  * @protected  
31+  * @param  {VueInterface } interfaceDefine the param will be checked. 
32+  * @description  interfaceDefine will be checked, if it conforms to the interface, it return true; otherwise, it returns false. 
33+  */ 
34+  static  validateInterface  ( interfaceDefine )  { 
35+  // hasIn 是包含 prototype has 不會含 prototype 
36+  return  Vue3Component . InvalidInterfaceKeys . every ( ( key )  =>  ! has ( key ,  interfaceDefine ) ) 
37+  } 
38+ 39+  /** 
40+  * typeCheck 
41+  * @static  
42+  * @method  
43+  * @protected  
44+  * @param  {VueInterface } interfaceDefine the param will be checked. 
45+  * @description  interfaceDefine will be checked, if it conforms to the interface, it return true; otherwise, it returns false. 
46+  */ 
47+  static  typeCheck  ( interfaceDefine )  { 
48+  if  ( isNil ( interfaceDefine ) )  { 
49+  throw  new  Error ( 'Interface cannot be null or undefined.' ) 
50+  }  else  if  ( isEmpty ( interfaceDefine ) )  { 
51+  throw  new  Error ( 'Interface cannot be empty object.' ) 
52+  }  else  if  ( ! Vue3Component . validateInterface ( interfaceDefine ) )  { 
53+  throw  new  Error ( 'The incoming parameter must be an interface.' ) 
54+  } 
55+  } 
56+ 57+  /** 
58+  * extend 
59+  * @static  
60+  * @method  
61+  * @param  {VueComponent } componentDefine componentDefine to be inherited. 
62+  * @param  {VueComponent } override override to be override. 
63+  * @description  
64+  */ 
65+  static  extend  ( componentDefine ,  override )  { 
66+  const  vue3Component  =  isNotNil ( componentDefine ) 
67+  ? Object . assign ( new  Vue3Component ( ) ,  clone ( componentDefine ) ) 
68+  : new  Vue3Component ( ) 
69+ 70+  return  isNotNil ( override ) 
71+  ? Object . assign ( vue3Component ,  clone ( override ) ) 
72+  : vue3Component 
73+  } 
74+ 75+  /** 
76+  * implement 
77+  * @static  
78+  * @method  
79+  * @public  
80+  * @param  {VueComponent } interfaceDefine interfaceDefine to be inherited. 
81+  * @description  Vue's interface can only define props、methods. 
82+  */ 
83+  static  implement  ( interfaceDefine )  { 
84+  Vue3Component . typeCheck ( interfaceDefine ) 
85+  return  Vue3Component . extend ( interfaceDefine ) 
1286 } 
13-  static  extend  ( extendOptions )  { 
14-  const  sub  =  new  VueInheritance ( extendOptions ) 
15-  sub . extend ( extendOptions . extends  ||  { } ) 
16-  return  sub 
87+ 88+  // eslint-disable-next-line no-useless-constructor 
89+  constructor  ( componentOptions )  { 
1790 } 
1891
19-  static  implement  =  VueInheritance . extend 
20- 21-  extend  ( extendOptions )  { 
22-  const  cloneExtendOptions  =  clone ( extendOptions ) 
23-  try  { 
24-  this . props  =  mergeRight ( this . props ,  cloneExtendOptions . props ) 
25-  this . methods  =  mergeRight ( this . methods ,  cloneExtendOptions . methods ) 
26-  this . computed  =  mergeRight ( this . computed ,  cloneExtendOptions . computed ) 
27-  return  this 
28-  }  catch  ( e )  { 
29-  throw  new  TypeError ( 'extend error' ) 
92+  /** 
93+  * extends 
94+  * @type  {VueComponent } extends 
95+  * @description  property of Vue component option api. 
96+  */ 
97+  extends  =  null 
98+ 99+  /** 
100+  * implement 
101+  * @static  
102+  * @method  
103+  * @public  
104+  * @param  {VueInterface } interface interface to be inherited. 
105+  * @description  Vue's interface can only define props、methods. 
106+  */ 
107+  implement  ( interfaceDefine )  { 
108+  Vue3Component . typeCheck ( interfaceDefine ) 
109+ 110+  if  ( isNil ( this . extends )  ||  isEmpty ( this . extends ) )  { 
111+  this . extends  =  clone ( interfaceDefine ) 
112+  }  else  { 
113+  let  deepestNode  =  this . extends 
114+  // find deepes node. 
115+  while  ( isNotNil ( deepestNode . extends ) )  { 
116+  deepestNode  =  deepestNode . extends 
117+  } 
118+  deepestNode . extends  =  clone ( interfaceDefine ) 
30119 } 
120+  return  this 
31121 } 
122+ } 
123+ 124+ /** 
125+  * VueInheritance 
126+  * @static  
127+  * @public  
128+  * @description  
129+  */ 
130+ const  VueInheritance  =  Object . freeze ( { 
131+  extend : Vue3Component . extend , 
132+  implement : Vue3Component . implement 
133+ } ) 
32134
33-  implement  =  this . extend 
34- } 
135+ export  default  VueInheritance 
0 commit comments