@@ -15,6 +15,8 @@ import { dedupingMixin } from '../utils/mixin.js';
15
15
16
16
const DISABLED_ATTR = 'disable-upgrade' ;
17
17
18
+ let observedAttributesGetter ;
19
+
18
20
/**
19
21
* Element class mixin that allows the element to boot up in a non-enabled
20
22
* state when the `disable-upgrade` attribute is present. This mixin is
@@ -51,18 +53,49 @@ export const DisableUpgradeMixin = dedupingMixin((base) => {
51
53
*/
52
54
const superClass = ElementMixin ( base ) ;
53
55
56
+ // Work around for closure bug #126934458. Using `super` in a property
57
+ // getter does not work so instead we search the Base prototype for an
58
+ // implementation of observedAttributes so that we can override and call
59
+ // the `super` getter. Note, this is done one time ever because we assume
60
+ // that `Base` is always comes from `Polymer.LegacyElementMixn`.
61
+ if ( ! observedAttributesGetter ) {
62
+ let ctor = superClass ;
63
+ while ( ctor && ! observedAttributesGetter ) {
64
+ const desc = Object . getOwnPropertyDescriptor ( ctor , 'observedAttributes' ) ;
65
+ if ( desc ) {
66
+ observedAttributesGetter = desc . get ;
67
+ }
68
+ ctor = Object . getPrototypeOf ( ctor . prototype ) . constructor ;
69
+ }
70
+ }
71
+
54
72
/**
55
73
* @polymer
56
74
* @mixinClass
57
75
* @implements {Polymer_DisableUpgradeMixin}
58
76
*/
59
77
class DisableUpgradeClass extends superClass {
60
78
61
- /**
62
- * @suppress {missingProperties} go/missingfnprops
63
- */
64
79
static get observedAttributes ( ) {
65
- return super . observedAttributes . concat ( DISABLED_ATTR ) ;
80
+ return observedAttributesGetter . call ( this ) . concat ( DISABLED_ATTR ) ;
81
+ }
82
+
83
+ // Prevent element from initializing properties when it's upgrade disabled.
84
+ /** @override */
85
+ _initializeProperties ( ) {
86
+ if ( ! this . hasAttribute ( DISABLED_ATTR ) ) {
87
+ super . _initializeProperties ( ) ;
88
+ } else {
89
+ this . __isUpgradeDisabled = true ;
90
+ }
91
+ }
92
+
93
+ // Prevent element from enabling properties when it's upgrade disabled.
94
+ /** @override */
95
+ _enableProperties ( ) {
96
+ if ( ! this . __isUpgradeDisabled ) {
97
+ super . _enableProperties ( ) ;
98
+ }
66
99
}
67
100
68
101
/**
@@ -75,46 +108,33 @@ export const DisableUpgradeMixin = dedupingMixin((base) => {
75
108
*/
76
109
attributeChangedCallback ( name , old , value , namespace ) {
77
110
if ( name == DISABLED_ATTR ) {
78
- if ( ! this . __dataEnabled && value == null && this . isConnected ) {
79
- super . connectedCallback ( ) ;
111
+ // When disable-upgrade is removed, intialize properties and
112
+ // provoke connectedCallback if the element is already connected.
113
+ if ( ! this . __dataEnabled && value == null ) {
114
+ super . _initializeProperties ( ) ;
115
+ this . __isUpgradeDisabled = false ;
116
+ if ( this . isConnected ) {
117
+ super . connectedCallback ( ) ;
118
+ }
80
119
}
81
120
} else {
82
121
super . attributeChangedCallback (
83
122
name , old , value , /** @type {null|string } */ ( namespace ) ) ;
84
123
}
85
124
}
86
125
87
- /*
88
- NOTE: cannot gate on attribute because this is called before
89
- attributes are delivered. Therefore, we stub this out and
90
- call `super._initializeProperties()` manually.
91
- */
92
- /** @override */
93
- _initializeProperties ( ) { }
94
-
95
- // prevent user code in connected from running
126
+ // Prevent element from connecting when it's upgrade disabled.
96
127
/** @override */
97
128
connectedCallback ( ) {
98
- if ( this . __dataEnabled || ! this . hasAttribute ( DISABLED_ATTR ) ) {
129
+ if ( ! this . __isUpgradeDisabled ) {
99
130
super . connectedCallback ( ) ;
100
131
}
101
132
}
102
133
103
- // prevent element from turning on properties
104
- /** @override */
105
- _enableProperties ( ) {
106
- if ( ! this . hasAttribute ( DISABLED_ATTR ) ) {
107
- if ( ! this . __dataEnabled ) {
108
- super . _initializeProperties ( ) ;
109
- }
110
- super . _enableProperties ( ) ;
111
- }
112
- }
113
-
114
- // only go if "enabled"
134
+ // Prevent element from disconnecting when it's upgrade disabled.
115
135
/** @override */
116
136
disconnectedCallback ( ) {
117
- if ( this . __dataEnabled ) {
137
+ if ( ! this . __isUpgradeDisabled ) {
118
138
super . disconnectedCallback ( ) ;
119
139
}
120
140
}
0 commit comments