Skip to content

Commit d64ee9e

Browse files
committed
Reintroduce suppressTemplateNotifications and gate Dom-change & renderedItemCount on that.
Matches Polymer 1 setting for better backward compatibility.
1 parent e9e0cd1 commit d64ee9e

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

lib/elements/dom-if.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { microTask } from '../utils/async.js';
1515
import { root } from '../utils/path.js';
1616
import { wrap } from '../utils/wrap.js';
1717
import { hideElementsGlobally } from '../utils/hide-template-controls.js';
18-
import { fastDomIf, strictTemplatePolicy, legacyOptimizations } from '../utils/settings.js';
18+
import { fastDomIf, strictTemplatePolicy, suppressTemplateNotifications } from '../utils/settings.js';
1919
import { showHideChildren, templatize } from '../utils/templatize.js';
2020

2121
/**
@@ -66,7 +66,7 @@ class DomIfBase extends PolymerElement {
6666
},
6767

6868
/**
69-
* When the global `legacyOptimizations` setting is used, setting
69+
* When the global `suppressTemplateNotifications` setting is used, setting
7070
* `notifyDomChange: true` will enable firing `dom-change` events on this
7171
* element.
7272
*/
@@ -252,7 +252,8 @@ class DomIfBase extends PolymerElement {
252252
this.__teardownInstance();
253253
}
254254
this._showHideChildren();
255-
if ((!legacyOptimizations || this.notifyDomChange) && this.if != this._lastIf) {
255+
if ((!suppressTemplateNotifications || this.notifyDomChange)
256+
&& this.if != this._lastIf) {
256257
this.dispatchEvent(new CustomEvent('dom-change', {
257258
bubbles: true,
258259
composed: true

lib/elements/dom-repeat.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { matches, translate } from '../utils/path.js';
1717
import { timeOut, microTask } from '../utils/async.js';
1818
import { wrap } from '../utils/wrap.js';
1919
import { hideElementsGlobally } from '../utils/hide-template-controls.js';
20-
import { legacyOptimizations } from '../utils/settings.js';
20+
import { suppressTemplateNotifications } from '../utils/settings.js';
2121

2222
/**
2323
* @constructor
@@ -240,7 +240,7 @@ export class DomRepeat extends domRepeatBase {
240240
*/
241241
renderedItemCount: {
242242
type: Number,
243-
notify: !legacyOptimizations,
243+
notify: !suppressTemplateNotifications,
244244
readOnly: true
245245
},
246246

@@ -279,7 +279,7 @@ export class DomRepeat extends domRepeatBase {
279279
},
280280

281281
/**
282-
* When the global `legacyOptimizations` setting is used, setting
282+
* When the global `suppressTemplateNotifications` setting is used, setting
283283
* `notifyDomChange: true` will enable firing `dom-change` events on this
284284
* element.
285285
*/
@@ -555,7 +555,7 @@ export class DomRepeat extends domRepeatBase {
555555
// Set rendered item count
556556
this._setRenderedItemCount(this.__instances.length);
557557
// Notify users
558-
if (!legacyOptimizations || this.notifyDomChange) {
558+
if (!suppressTemplateNotifications || this.notifyDomChange) {
559559
this.dispatchEvent(new CustomEvent('dom-change', {
560560
bubbles: true,
561561
composed: true

lib/utils/settings.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,22 @@ export let fastDomIf = window.Polymer && window.Polymer.fastDomIf || false;
278278
export const setFastDomIf = function(useFastDomIf) {
279279
fastDomIf = useFastDomIf;
280280
};
281+
282+
/**
283+
* Setting to disable `dom-change` and `rendered-item-count` events from
284+
* `dom-if` and `dom-repeat`. Users can opt back into `dom-change` events by
285+
* setting the `notify-dom-change` attribute (`notifyDomChange: true` property)
286+
* to `dom-if`/`don-repeat` instances.
287+
*/
288+
export let suppressTemplateNotifications =
289+
window.Polymer && window.Polymer.suppressTemplateNotifications || false;
290+
291+
/**
292+
* Sets `fastDomIf` globally, to put `dom-if` in a performance-optimized mode.
293+
*
294+
* @param {boolean} suppress enable or disable `suppressTemplateNotifications`
295+
* @return {void}
296+
*/
297+
export const setSuppressTemplateNotifications = function(suppress) {
298+
suppressTemplateNotifications = suppress;
299+
};

0 commit comments

Comments
 (0)