Skip to content

Commit

Permalink
fix: move property management into update or willUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
Westbrook committed May 12, 2022
1 parent fd7a7f9 commit f66069f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/base/src/sizedMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ export function SizedMixin<T extends Constructor<ReactiveElement>>(

private _size: ElementSize | null = defaultSize;

protected firstUpdated(changes: PropertyValues): void {
super.firstUpdated(changes);
protected update(changes: PropertyValues): void {
if (!this.hasAttribute('size') && !noDefaultSize) {
this.setAttribute('size', this.size);
}
super.update(changes);
}
}
return SizedElement;
Expand Down
9 changes: 4 additions & 5 deletions packages/field-label/src/FieldLabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,16 @@ export class FieldLabel extends SizedMixin(SpectrumElement) {

protected firstUpdated(changes: PropertyValues): void {
super.firstUpdated(changes);
this.addEventListener('click', this.handleClick);
}

protected willUpdate(changes: PropertyValues): void {
if (!this.hasAttribute('id')) {
this.setAttribute(
'id',
`${this.tagName.toLowerCase()}-${FieldLabel.instanceCount++}`
);
}
this.addEventListener('click', this.handleClick);
}

protected updated(changes: PropertyValues): void {
super.updated(changes);
if (changes.has('for') || changes.has('id')) {
this.manageFor();
}
Expand Down
3 changes: 2 additions & 1 deletion test/benchmark/bench-runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
const params = new URLSearchParams(window.location.search);
const pack = params.get('package');
const bench = params.get('bench');
const dir = params.get('dir');
window.tachometerStart = params.get('start');
import(`../../packages/${pack}/test/benchmark/${bench}.js`);
import(`../../${dir}/${pack}/test/benchmark/${bench}.js`);
</script>
</body>
</html>
25 changes: 18 additions & 7 deletions test/benchmark/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ governing permissions and limitations under the License.
*/
import { main } from 'tachometer/lib/cli';
import { ConfigFile } from 'tachometer/lib/configfile';
import { readdirSync, writeFileSync } from 'fs';
import { existsSync, readdirSync, writeFileSync } from 'fs';
import { join as pathjoin } from 'path';
import * as commandLineArgs from 'command-line-args';
import * as commandLineUsage from 'command-line-usage';
Expand Down Expand Up @@ -163,7 +163,12 @@ $ node test/benchmark/cli -n 20
benchmarks: [],
};

const hasTests = readdirSync(pathjoin('packages', packageName)).find(
// Naively assume any change that doesn't exist is "packages" exists in "tools".
const monorepoDir = existsSync(pathjoin('packages', packageName))
? 'packages'
: 'tools';

const hasTests = readdirSync(pathjoin(monorepoDir, packageName)).find(
(dirEntry) => dirEntry === 'test'
);

Expand All @@ -172,15 +177,15 @@ $ node test/benchmark/cli -n 20
}

const hasBenchmarks = readdirSync(
pathjoin('packages', packageName, 'test')
pathjoin(monorepoDir, packageName, 'test')
).find((dirEntry) => dirEntry === 'benchmark');

if (!hasBenchmarks) {
continue;
}

const benchmarks = readdirSync(
pathjoin('packages', packageName, 'test', 'benchmark'),
pathjoin(monorepoDir, packageName, 'test', 'benchmark'),
{ withFileTypes: true }
)
.filter(
Expand All @@ -194,7 +199,12 @@ $ node test/benchmark/cli -n 20
* have yet to be published to NPM and skip.
**/
const pjson = await import(
pathjoin(process.cwd(), 'packages', packageName, 'package.json')
pathjoin(
process.cwd(),
monorepoDir,
packageName,
'package.json'
)
);
if (pjson.version === '0.0.1' && opts.compare !== 'none') {
// eslint-disable-next-line no-console
Expand All @@ -207,11 +217,12 @@ $ node test/benchmark/cli -n 20
if (opts.compare !== 'none') {
config.benchmarks.push({
name: `${packageName}:${benchmark}`,
url: `test/benchmark/bench-runner.html?bench=${benchmark}&package=${packageName}&start=${start}`,
url: `test/benchmark/bench-runner.html?bench=${benchmark}&package=${packageName}&start=${start}&dir=${monorepoDir}`,
packageVersions: {
label: 'remote',
dependencies: {
'@spectrum-web-components/bundle': opts.compare,
'@spectrum-web-components/grid': opts.compare,
lit: '^2.0.0',
},
},
Expand All @@ -228,7 +239,7 @@ $ node test/benchmark/cli -n 20
}
config.benchmarks.push({
name: `${packageName}:${benchmark}`,
url: `test/benchmark/bench-runner.html?bench=${benchmark}&package=${packageName}`,
url: `test/benchmark/bench-runner.html?bench=${benchmark}&package=${packageName}&dir=${monorepoDir}`,
measurement: 'global',
browser: {
name: opts.browser,
Expand Down
5 changes: 4 additions & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"outDir": "../",
"rootDir": "../"
},
"include": ["../packages/*/test/benchmark/**/*.ts"],
"include": [
"../packages/*/test/benchmark/**/*.ts",
"../tools/*/test/benchmark/**/*.ts"
],
"exclude": ["benchmark/cli.ts"]
}

0 comments on commit f66069f

Please sign in to comment.