Skip to content

Commit

Permalink
Adds legacyNoBatch setting
Browse files Browse the repository at this point in the history
Avoids batching properties after startup to more closely match Polymer 1 behavior.
  • Loading branch information
Steven Orvell committed Feb 8, 2019
1 parent 52a559f commit 363bef2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/mixins/property-accessors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import '../utils/boot.js';
import { dedupingMixin } from '../utils/mixin.js';
import { camelToDashCase, dashToCamelCase } from '../utils/case-map.js';
import { PropertiesChanged } from './properties-changed.js';
import { legacyNoBatch } from '../utils/settings.js';

// Save map of native properties; this forms a blacklist or properties
// that won't have their values "saved" by `saveAccessorValue`, since
Expand Down Expand Up @@ -289,7 +290,14 @@ export const PropertyAccessors = dedupingMixin(superClass => {
* @override
*/
_definePropertyAccessor(property, readOnly) {
saveAccessorValue(this, property);
if (legacyNoBatch) {
const ready = this.__dataReady;
this.__dataReady = false;
saveAccessorValue(this, property);
this.__dataReady = ready;
} else {
saveAccessorValue(this, property);
}
super._definePropertyAccessor(property, readOnly);
}

Expand Down
5 changes: 4 additions & 1 deletion lib/mixins/property-effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { camelToDashCase, dashToCamelCase } from '../utils/case-map.js';
import { PropertyAccessors } from './property-accessors.js';
/* for annotated effects */
import { TemplateStamp } from './template-stamp.js';
import { sanitizeDOMValue, legacyUndefined } from '../utils/settings.js';
import { sanitizeDOMValue, legacyUndefined, legacyNoBatch } from '../utils/settings.js';

// Monotonically increasing unique ID used for de-duping effects triggered
// from multiple properties in the same turn
Expand Down Expand Up @@ -1481,6 +1481,9 @@ export const PropertyEffects = dedupingMixin(superClass => {
this.__dataToNotify = this.__dataToNotify || {};
this.__dataToNotify[property] = shouldNotify;
}
if (legacyNoBatch) {
this._invalidateProperties();
}
return true;
}
return false;
Expand Down
18 changes: 18 additions & 0 deletions lib/utils/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,21 @@ export let legacyUndefined = false;
export const setLegacyUndefined = function(useLegacyUndefined) {
legacyUndefined = useLegacyUndefined;
};

/**
* Setting to retain the legacy Polymer 1 behavior for setting properties. Does
* not batch property sets.
*/
export let legacyNoBatch = false;

/**
* Sets `legacyNoBatch` globally for all elements to enable legacy
* behavior for setting properties.
*
* @param {boolean} useLegacyNoBatch enable or disable legacy
* property setting behavior.
* @return {void}
*/
export const setLegacyNoBatch = function(useLegacyNoBatch) {
legacyNoBatch = useLegacyNoBatch;
};

0 comments on commit 363bef2

Please sign in to comment.