@@ -9,11 +9,19 @@ try { process.env.NODE_ENV } catch(e) { var process = { env: { NODE_ENV: 'produc
9
9
10
10
const defaultMethod = ( host , value ) => value ;
11
11
12
+ const callbacksMap = new WeakMap ( ) ;
13
+ const propsMap = new WeakMap ( ) ;
14
+
12
15
function compile ( Hybrid , descriptors ) {
13
16
Hybrid . hybrids = descriptors ;
14
- Hybrid . callbacks = [ ] ;
15
17
16
- Object . keys ( descriptors ) . forEach ( key => {
18
+ const callbacks = [ ] ;
19
+ const props = Object . keys ( descriptors ) ;
20
+
21
+ callbacksMap . set ( Hybrid , callbacks ) ;
22
+ propsMap . set ( Hybrid , props ) ;
23
+
24
+ props . forEach ( key => {
17
25
const desc = descriptors [ key ] ;
18
26
const type = typeof desc ;
19
27
@@ -46,13 +54,13 @@ function compile(Hybrid, descriptors) {
46
54
} ) ;
47
55
48
56
if ( config . observe ) {
49
- Hybrid . callbacks . unshift ( host =>
57
+ callbacks . unshift ( host =>
50
58
cache . observe ( host , key , config . get , config . observe ) ,
51
59
) ;
52
60
}
53
61
54
62
if ( config . connect ) {
55
- Hybrid . callbacks . push ( host =>
63
+ callbacks . push ( host =>
56
64
config . connect ( host , key , ( ) => {
57
65
cache . invalidate ( host , key ) ;
58
66
} ) ,
@@ -143,8 +151,23 @@ function defineElement(tagName, hybridsOrConstructor) {
143
151
return tagName ;
144
152
}
145
153
154
+ constructor ( ) {
155
+ super ( ) ;
156
+
157
+ const props = propsMap . get ( Hybrid ) ;
158
+
159
+ for ( let index = 0 ; index < props . length ; index += 1 ) {
160
+ const key = props [ index ] ;
161
+ if ( Object . prototype . hasOwnProperty . call ( this , key ) ) {
162
+ const value = this [ key ] ;
163
+ delete this [ key ] ;
164
+ this [ key ] = value ;
165
+ }
166
+ }
167
+ }
168
+
146
169
connectedCallback ( ) {
147
- const { callbacks } = this . constructor ;
170
+ const callbacks = callbacksMap . get ( Hybrid ) ;
148
171
const list = [ ] ;
149
172
150
173
for ( let index = 0 ; index < callbacks . length ; index += 1 ) {
0 commit comments