Skip to content

Commit

Permalink
Merge pull request #5591 from Polymer/legach-undefined-noBatch-opt
Browse files Browse the repository at this point in the history
Applies micro-optimizations and removes obsolete settings
  • Loading branch information
kevinpschaaf authored Sep 23, 2019
2 parents 042d95b + cbc722b commit 6c3bb48
Show file tree
Hide file tree
Showing 12 changed files with 5,088 additions and 2,561 deletions.
19 changes: 11 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
language: node_js
sudo: false
dist: trusty
node_js: '9'
dist: xenial
node_js: '10'
services:
- xvfb
addons:
firefox: "66.0"
chrome: stable
cache:
directories:
- node_modules
firefox: latest
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
before_script:
- npm install -g gulp-cli@1
- gulp lint-eslint
script:
- node ./node_modules/.bin/polymer test --npm --module-resolution=node -l chrome
- xvfb-run node ./node_modules/.bin/polymer test --npm --module-resolution=node -l firefox
- node ./node_modules/.bin/polymer test --npm --module-resolution=node -l firefox
- if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then travis_wait 30 ./util/travis-sauce-test.sh; fi
env:
global:
Expand Down
6 changes: 6 additions & 0 deletions externs/polymer-externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ Polymer.legacyNotifyOrder;
/** @type {boolean} */
Polymer.orderedComputed;

/** @type {boolean} */
Polymer.fastDomIf;

/** @type {boolean} */
Polymer.suppressTemplateNotifications;

// nb. This is explicitly 'var', as Closure Compiler checks that this is the case.
/**
* @constructor
Expand Down
15 changes: 12 additions & 3 deletions lib/elements/dom-if.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { microTask } from '../utils/async.js';
import { root } from '../utils/path.js';
import { wrap } from '../utils/wrap.js';
import { hideElementsGlobally } from '../utils/hide-template-controls.js';
import { fastDomIf, strictTemplatePolicy } from '../utils/settings.js';
import { fastDomIf, strictTemplatePolicy, suppressTemplateNotifications } from '../utils/settings.js';
import { showHideChildren, templatize } from '../utils/templatize.js';

/**
Expand Down Expand Up @@ -63,8 +63,16 @@ class DomIfBase extends PolymerElement {
restamp: {
type: Boolean,
observer: '__debounceRender'
}
},

/**
* When the global `suppressTemplateNotifications` setting is used, setting
* `notifyDomChange: true` will enable firing `dom-change` events on this
* element.
*/
notifyDomChange: {
type: Boolean
}
};

}
Expand Down Expand Up @@ -244,7 +252,8 @@ class DomIfBase extends PolymerElement {
this.__teardownInstance();
}
this._showHideChildren();
if (this.if != this._lastIf) {
if ((!suppressTemplateNotifications || this.notifyDomChange)
&& this.if != this._lastIf) {
this.dispatchEvent(new CustomEvent('dom-change', {
bubbles: true,
composed: true
Expand Down
22 changes: 17 additions & 5 deletions lib/elements/dom-repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { matches, translate } from '../utils/path.js';
import { timeOut, microTask } from '../utils/async.js';
import { wrap } from '../utils/wrap.js';
import { hideElementsGlobally } from '../utils/hide-template-controls.js';
import { suppressTemplateNotifications } from '../utils/settings.js';

/**
* @constructor
Expand Down Expand Up @@ -239,7 +240,7 @@ export class DomRepeat extends domRepeatBase {
*/
renderedItemCount: {
type: Number,
notify: true,
notify: !suppressTemplateNotifications,
readOnly: true
},

Expand Down Expand Up @@ -275,6 +276,15 @@ export class DomRepeat extends domRepeatBase {
_targetFrameTime: {
type: Number,
computed: '__computeFrameTime(targetFramerate)'
},

/**
* When the global `suppressTemplateNotifications` setting is used, setting
* `notifyDomChange: true` will enable firing `dom-change` events on this
* element.
*/
notifyDomChange: {
type: Boolean
}

};
Expand Down Expand Up @@ -545,10 +555,12 @@ export class DomRepeat extends domRepeatBase {
// Set rendered item count
this._setRenderedItemCount(this.__instances.length);
// Notify users
this.dispatchEvent(new CustomEvent('dom-change', {
bubbles: true,
composed: true
}));
if (!suppressTemplateNotifications || this.notifyDomChange) {
this.dispatchEvent(new CustomEvent('dom-change', {
bubbles: true,
composed: true
}));
}
// Check to see if we need to render more items
this.__tryRenderChunk();
}
Expand Down
13 changes: 11 additions & 2 deletions lib/mixins/properties-changed.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,15 @@ export const PropertiesChanged = dedupingMixin(
/* eslint-disable valid-jsdoc */
/** @this {PropertiesChanged} */
get() {
return this._getProperty(property);
// Inline for perf instead of using `_getProperty`
return this.__data[property];
},
/** @this {PropertiesChanged} */
set: readOnly ? function () {} : function (value) {
this._setProperty(property, value);
// Inline for perf instead of using `_setProperty`
if (this._setPendingProperty(property, value, true)) {
this._invalidateProperties();
}
}
/* eslint-enable */
});
Expand All @@ -180,6 +184,9 @@ export const PropertiesChanged = dedupingMixin(
this.__dataPending = null;
this.__dataOld = null;
this.__dataInstanceProps = null;
/** @type {number} */
// NOTE: used to track re-entrant calls to `_flushProperties`
this.__dataCounter = 0;
this.__serializing = false;
this._initializeProperties();
}
Expand Down Expand Up @@ -367,6 +374,7 @@ export const PropertiesChanged = dedupingMixin(
* @override
*/
_flushProperties() {
this.__dataCounter++;
const props = this.__data;
const changedProps = this.__dataPending;
const old = this.__dataOld;
Expand All @@ -375,6 +383,7 @@ export const PropertiesChanged = dedupingMixin(
this.__dataOld = null;
this._propertiesChanged(props, changedProps, old);
}
this.__dataCounter--;
}

/**
Expand Down
11 changes: 1 addition & 10 deletions lib/mixins/property-accessors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ 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 @@ -295,15 +294,7 @@ export const PropertyAccessors = dedupingMixin(superClass => {
* @override
*/
_definePropertyAccessor(property, readOnly) {
if (legacyNoBatch) {
// Ensure properties are not flushed when adding instance effects
const ready = this.__dataReady;
this.__dataReady = false;
saveAccessorValue(this, property);
this.__dataReady = ready;
} else {
saveAccessorValue(this, property);
}
saveAccessorValue(this, property);
super._definePropertyAccessor(property, readOnly);
}

Expand Down
Loading

0 comments on commit 6c3bb48

Please sign in to comment.