Skip to content

Commit b2638aa

Browse files
authored
Merge pull request #1397 from OneSignal/fg/bell-fixes
chore: improve typings for bell elements
2 parents f501b6e + 24abd6d commit b2638aa

File tree

9 files changed

+236
-219
lines changed

9 files changed

+236
-219
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
},
8585
{
8686
"path": "./build/releases/OneSignalSDK.page.es6.js",
87-
"limit": "49.631 kB",
87+
"limit": "49.421 kB",
8888
"gzip": true
8989
},
9090
{

src/page/bell/AnimatedElement.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,44 +25,42 @@ export default class AnimatedElement {
2525
/**
2626
* Show element using CSS classes and wait for animations to complete
2727
*/
28-
async show(): Promise<AnimatedElement> {
28+
async show(): Promise<void> {
2929
const element = this.element;
3030
if (!element || this.shown) {
31-
return this;
31+
return;
3232
}
3333

3434
if (this.showClass) {
3535
element.classList.add(this.showClass);
3636
}
3737

3838
await this.waitForAnimations();
39-
return this;
4039
}
4140

4241
/**
4342
* Hide element using CSS classes and wait for animations to complete
4443
*/
45-
async hide(): Promise<AnimatedElement> {
44+
async hide(): Promise<void> {
4645
const element = this.element;
4746
if (!element || !this.shown) {
48-
return this;
47+
return;
4948
}
5049

5150
if (this.showClass) {
5251
element.classList.remove(this.showClass);
5352
}
5453

5554
await this.waitForAnimations();
56-
return this;
5755
}
5856

5957
/**
6058
* Activate element using CSS classes
6159
*/
62-
async activate(): Promise<AnimatedElement> {
60+
async activate(): Promise<void> {
6361
const element = this.element;
6462
if (!element || this.active) {
65-
return this;
63+
return;
6664
}
6765

6866
if (this.inactiveClass) {
@@ -73,16 +71,15 @@ export default class AnimatedElement {
7371
}
7472

7573
await this.waitForAnimations();
76-
return this;
7774
}
7875

7976
/**
8077
* Inactivate element using CSS classes
8178
*/
82-
async inactivate(): Promise<AnimatedElement> {
79+
async inactivate(): Promise<void> {
8380
const element = this.element;
8481
if (!element || !this.active) {
85-
return this;
82+
return;
8683
}
8784

8885
if (this.activeClass) {
@@ -93,7 +90,6 @@ export default class AnimatedElement {
9390
}
9491

9592
await this.waitForAnimations();
96-
return this;
9793
}
9894

9995
/**

src/page/bell/Badge.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,25 @@ export default class Badge extends AnimatedElement {
99
);
1010
}
1111

12-
increment(): void {
13-
// If it IS a number (is not not a number)
14-
if (!isNaN(this.content as any)) {
15-
let badgeNumber = +this.content; // Coerce to int
16-
badgeNumber += 1;
17-
this.content = badgeNumber.toString();
12+
_updateCount(delta: number): void {
13+
const num = Number(this.content);
14+
if (!Number.isNaN(num)) {
15+
const newNum = num + delta;
16+
this.content = newNum > 0 ? newNum.toString() : '';
1817
}
1918
}
2019

21-
show(): Promise<AnimatedElement> {
20+
increment(): void {
21+
this._updateCount(1);
22+
}
23+
24+
decrement(): void {
25+
this._updateCount(-1);
26+
}
27+
28+
show(): Promise<void> {
2229
const promise = super.show();
2330
OneSignal._notifyButton?.setCustomColorsIfSpecified();
2431
return promise;
2532
}
26-
27-
decrement() {
28-
// If it IS a number (is not not a number)
29-
if (!isNaN(this.content as any)) {
30-
let badgeNumber = +this.content; // Coerce to int
31-
badgeNumber -= 1;
32-
if (badgeNumber > 0) this.content = badgeNumber.toString();
33-
else this.content = '';
34-
}
35-
}
3633
}

0 commit comments

Comments
 (0)