Skip to content

Commit

Permalink
counter is alive now
Browse files Browse the repository at this point in the history
## [0.4.0] - 2021-11-02
### Added
- counter is alive now
  • Loading branch information
ArtemNikolaev committed Nov 2, 2021
1 parent e3ce326 commit ca22ca5
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 14 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.4.0] - 2021-11-02
### Added
- counter is alive now

## [0.3.0] - 2021-10-31
### Added
- themes
Expand All @@ -30,7 +34,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- initial

[Unreleased]: https://github.com/ArtemNikolaev/frame-rate-web-component/compare/v0.3.0...HEAD
[Unreleased]: https://github.com/ArtemNikolaev/frame-rate-web-component/compare/v0.4.0...HEAD
[0.4.0]: https://github.com/ArtemNikolaev/frame-rate-web-component/compare/v0.3.0...v0.4.0
[0.3.0]: https://github.com/ArtemNikolaev/frame-rate-web-component/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/ArtemNikolaev/frame-rate-web-component/compare/v0.1.1...v0.2.0
[0.1.1]: https://github.com/ArtemNikolaev/frame-rate-web-component/compare/v0.1.0...v0.1.1
Expand Down
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<title>Frame Rate Web Component Demo</title>
</head>
<body>
<h1>Frame Rate WebComponent Demo</h1>
<script src="/dist/frame-rate.bundle.js"></script>

<frame-rate></frame-rate>
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "frame-rate-web-component",
"version": "0.3.0",
"version": "0.4.0",
"description": "Frame Rate Web Component",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack"
"build": "webpack",
"start": "webpack --watch"
},
"keywords": [
"web-component",
Expand Down
67 changes: 63 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,74 @@ import generatePostLikeTheme from './themes/post-like';
class FrameRate extends HTMLElement {
constructor() {
super();
this.frameRate = 144;
this.isInactive = false;

this.frameAmount = [];
this.frameRate = 0;
this.frameRateOld = 0;

this.attachShadow({mode: 'open'});
this.shadowRoot.appendChild(styleEl);

this.theme = generatePostLikeTheme(this.frameRate);

const shadow = this.attachShadow({mode: 'open'});
this.render();
}

connectedCallback() {
this.on();
}

counter() {
if (this.isInactive) {
this.framesAmount.splice(0);

shadow.appendChild(styleEl);
return;
}

this.frameAmount = this.frameAmount.filter( dt => dt > Date.now() - 1000);
this.frameAmount.push(Date.now());

const frameRate = this.frameAmount.length;

if (frameRate !== this.frameRate) {
this.frameRateOld = this.frameRate;
this.frameRate = frameRate;

this.render();
}


requestAnimationFrame(() => this.counter());
}

this.theme.forEach(node => shadow.appendChild(node));
disconnectedCallback() {
this.isInactive = true;
}

attributeChangedCallback(key, prev, next) {

}

render() {
this.theme.style.remove();
this.theme.el.remove();

this.theme = generatePostLikeTheme(this.frameRate);

this.shadowRoot.appendChild(this.theme.style);
this.shadowRoot.appendChild(this.theme.el);
}

on() {
this.counter();
}

off() {
this.isInactive = true;
}

static get observedAttributes() {return ['hide'];}
}

customElements.define('frame-rate', FrameRate)
4 changes: 4 additions & 0 deletions src/style/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
top: 0;
right: 0;
}

.hide {
display: none;
}
8 changes: 4 additions & 4 deletions src/themes/post-like/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export default function generatePostLikeTheme(frames) {
}
);

return [
themeStyle,
div,
]
return {
style: themeStyle,
el: div,
};
}

0 comments on commit ca22ca5

Please sign in to comment.