Skip to content

Commit 5afc438

Browse files
committed
Fixed snackbar force bug and updated build tools
1 parent cae73b6 commit 5afc438

File tree

5 files changed

+55
-20
lines changed

5 files changed

+55
-20
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [2.1.1] - 2021-01-21
11+
12+
### Fixed
13+
14+
- snackbar missing element bug
15+
1016
## [2.1.0] - 2020-11-09
1117

1218
### Added

build/cleanup.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
const cwd = process.cwd();
4+
5+
const files = [
6+
"notifier.js",
7+
"notifier.js.map",
8+
"notify.js",
9+
"notify.js.map",
10+
"notify.min.mjs",
11+
"snackbar-component.js",
12+
"snackbar-component.js.map",
13+
"toast-component.js",
14+
"toast-component.js.map",
15+
];
16+
17+
function normalizePath(file){
18+
return path.join(cwd, file);
19+
}
20+
21+
for (let i = 0; i < files.length; i++){
22+
const path = normalizePath(files[i]);
23+
if (fs.existsSync(path)){
24+
fs.unlinkSync(path);
25+
}
26+
}

package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codewithkyle/notifyjs",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "A simple JavaScript library for creating and managing toaster & snackbar notifications",
55
"main": "notify.js",
66
"files": [
@@ -15,9 +15,11 @@
1515
"notify.min.mjs"
1616
],
1717
"scripts": {
18+
"cleanup": "node ./build/cleanup.js",
1819
"compile": "tsc",
1920
"test": "npm run compile && npm run bundle && cp ./notify.min.mjs ./test/notify.min.mjs && serve ./test",
20-
"bundle": "rollup notify.js --file notify.mjs --format es --compact && terser notify.mjs -o notify.min.mjs -c && rm notify.mjs"
21+
"bundle": "rollup notify.js --file notify.mjs --format es --compact && terser notify.mjs -o notify.min.mjs -c && rm notify.mjs",
22+
"prerelease": "npm run cleanup && npm run compile && npm run bundle"
2123
},
2224
"keywords": [
2325
"snackbar",
@@ -29,10 +31,9 @@
2931
"author": "Kyle Andrews",
3032
"license": "MIT",
3133
"devDependencies": {
32-
"rollup": "^2.33.1",
34+
"rollup": "^2.37.1",
3335
"serve": "^11.3.2",
34-
"terser": "^5.3.8",
35-
"typescript": "^4.0.0"
36-
},
37-
"dependencies": {}
36+
"terser": "^5.5.1",
37+
"typescript": "^4.1.3"
38+
}
3839
}

src/notifier.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ export class Notifier {
4444
}
4545
}
4646
if (this.snackbarQueue.length) {
47-
if (!this.snackbarQueue[0].el) {
47+
if (!this.snackbarQueue?.[0]?.el) {
4848
this.snackbarQueue[0].el = new SnackbarComponent(this.snackbarQueue[0]);
4949
document.body.appendChild(this.snackbarQueue[0].el);
5050
}
51-
if (this.snackbarQueue[0]?.duration && this.snackbarQueue[0]?.duration !== Infinity) {
51+
if (this.snackbarQueue[0]?.duration && this.snackbarQueue[0]?.duration !== Infinity && this.snackbarQueue[0]?.el?.isConnected) {
5252
this.snackbarQueue[0].duration -= deltaTime;
5353
if (this.snackbarQueue[0].duration <= 0) {
5454
this.snackbarQueue[0].el.remove();
@@ -145,7 +145,9 @@ export class Notifier {
145145
}
146146

147147
if (snackbar.force && this.snackbarQueue.length) {
148-
this.snackbarQueue[0].el.remove();
148+
if (this.snackbarQueue[0]?.el?.isConnected){
149+
this.snackbarQueue[0].el.remove();
150+
}
149151
this.snackbarQueue.splice(0, 1, snackbar as SnackbarNotification);
150152
} else {
151153
this.snackbarQueue.push(snackbar as SnackbarNotification);

0 commit comments

Comments
 (0)