1
1
'use strict' ;
2
2
3
- var setPrototypeOf = Object . setPrototypeOf || function ( obj , proto ) {
4
- /* jshint proto:true */
5
- obj . __proto__ = proto ;
6
- return obj ;
7
- } ;
8
-
9
3
module . exports = function ( React ) {
10
4
var mounted = [ ] ;
11
5
var Mixin = {
@@ -19,63 +13,75 @@ module.exports = function (React) {
19
13
} ;
20
14
21
15
var assimilatePrototype = ( function ( ) {
22
- var storedPrototype ;
23
-
24
- function assimilateProperty ( freshPrototype , key ) {
25
- function get ( ) {
26
- if ( typeof storedPrototype [ key ] !== 'function' ||
27
- key === 'type' ||
28
- key === 'constructor' ) {
16
+ var storedPrototype ,
17
+ knownPrototypes = [ ] ;
29
18
30
- return storedPrototype [ key ] ;
19
+ function wrapFunction ( key ) {
20
+ return function ( ) {
21
+ if ( storedPrototype [ key ] ) {
22
+ return storedPrototype [ key ] . apply ( this , arguments ) ;
31
23
}
24
+ } ;
25
+ }
32
26
33
- return function ( ) {
34
- var value = storedPrototype [ key ] ;
35
- if ( typeof value === 'function' ) {
36
- return value . apply ( this , arguments ) ;
37
- } else {
38
- console . warn ( 'A call to ' + key + ' was made after it was deleted. Acting as no-op.' ) ;
39
- }
40
- } ;
41
- }
27
+ function patchProperty ( proto , key ) {
28
+ proto [ key ] = storedPrototype [ key ] ;
42
29
43
- function set ( value ) {
44
- storedPrototype [ key ] = value ;
30
+ if ( typeof proto [ key ] !== 'function' ||
31
+ key === 'type' ||
32
+ key === 'constructor' ) {
33
+ return ;
45
34
}
46
35
47
- storedPrototype [ key ] = freshPrototype [ key ] ;
48
- Object . defineProperty ( freshPrototype , key , {
49
- configurable : false ,
50
- enumerable : true ,
51
- get : get ,
52
- set : set
53
- } ) ;
36
+ proto [ key ] = wrapFunction ( key ) ;
37
+
38
+ if ( proto . __reactAutoBindMap [ key ] ) {
39
+ proto . __reactAutoBindMap [ key ] = proto [ key ] ;
40
+ }
54
41
}
55
42
56
- return function assimilatePrototype ( freshPrototype ) {
43
+ function updateStoredPrototype ( freshPrototype ) {
57
44
storedPrototype = { } ;
45
+
58
46
for ( var key in freshPrototype ) {
59
- assimilateProperty ( freshPrototype , key ) ;
47
+ if ( freshPrototype . hasOwnProperty ( key ) ) {
48
+ storedPrototype [ key ] = freshPrototype [ key ] ;
49
+ }
60
50
}
51
+ }
52
+
53
+ function reconcileWithStoredPrototypes ( freshPrototype ) {
54
+ knownPrototypes . push ( freshPrototype ) ;
55
+ knownPrototypes . forEach ( function ( proto ) {
56
+ for ( var key in storedPrototype ) {
57
+ patchProperty ( proto , key ) ;
58
+ }
59
+ } ) ;
60
+ }
61
+
62
+ return function ( freshPrototype ) {
63
+ updateStoredPrototype ( freshPrototype ) ;
64
+ reconcileWithStoredPrototypes ( freshPrototype ) ;
61
65
} ;
62
66
} ) ( ) ;
63
67
68
+ function injectMixinAndAssimilatePrototype ( spec ) {
69
+ spec . mixins = spec . mixins || [ ] ;
70
+ spec . mixins . push ( Mixin ) ;
71
+ var Component = React . createClass ( spec ) ;
72
+ assimilatePrototype ( Component . type . prototype ) ;
73
+ return Component ;
74
+ }
75
+
64
76
var Component ;
65
77
return {
66
78
createClass : function ( spec ) {
67
- spec . mixins = spec . mixins || [ ] ;
68
- spec . mixins . push ( Mixin ) ;
69
-
70
- Component = React . createClass ( spec ) ;
71
- assimilatePrototype ( Component . componentConstructor . prototype ) ;
72
-
79
+ Component = injectMixinAndAssimilatePrototype ( spec ) ;
73
80
return Component ;
74
81
} ,
75
82
76
83
updateClass : function ( spec ) {
77
- var UpdatedComponent = React . createClass ( spec ) ;
78
- assimilatePrototype ( UpdatedComponent . componentConstructor . prototype ) ;
84
+ injectMixinAndAssimilatePrototype ( spec ) ;
79
85
80
86
mounted . forEach ( function ( instance ) {
81
87
instance . _bindAutoBindMethods ( ) ;
0 commit comments