Skip to content

Commit e9bdc4b

Browse files
committed
more method renames
1 parent 8620cee commit e9bdc4b

File tree

9 files changed

+44
-65
lines changed

9 files changed

+44
-65
lines changed

__test__/unit/models/path.test.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,42 @@ import Path from '../../../src/shared/models/Path';
33
describe('Path tests', () => {
44
test(`should return correct components for a simple web path`, () => {
55
const path = new Path('/web-folder/assets/service-worker.js');
6-
expect(path.getFileName()).toBe('service-worker.js');
7-
expect(path.getFullPath()).toBe('/web-folder/assets/service-worker.js');
6+
expect(path._getFileName()).toBe('service-worker.js');
7+
expect(path._getFullPath()).toBe('/web-folder/assets/service-worker.js');
88
});
99

1010
test(`should return correct components for a file-based path`, () => {
1111
const path = new Path('file:///c:/web-folder/assets/service-worker.js');
12-
expect(path.getFileName()).toBe('service-worker.js');
13-
expect(path.getFullPath()).toBe(
12+
expect(path._getFileName()).toBe('service-worker.js');
13+
expect(path._getFullPath()).toBe(
1414
'file:///c:/web-folder/assets/service-worker.js',
1515
);
1616
});
1717

1818
test(`should return case-sensitive correct components for a file-based path`, () => {
1919
const path = new Path('/WeB-FoLdEr/AsSeTs/SeRvIcE-WoRkEr.js');
20-
expect(path.getFileName()).toBe('SeRvIcE-WoRkEr.js');
21-
expect(path.getFullPath()).toBe('/WeB-FoLdEr/AsSeTs/SeRvIcE-WoRkEr.js');
20+
expect(path._getFileName()).toBe('SeRvIcE-WoRkEr.js');
21+
expect(path._getFullPath()).toBe('/WeB-FoLdEr/AsSeTs/SeRvIcE-WoRkEr.js');
2222
});
2323

2424
test(`should return correct components for a double-extension path`, () => {
2525
const path = new Path('/web-folder/assets/service-worker.js.php');
26-
expect(path.getFileName()).toBe('service-worker.js.php');
27-
expect(path.getFullPath()).toBe('/web-folder/assets/service-worker.js.php');
26+
expect(path._getFileName()).toBe('service-worker.js.php');
27+
expect(path._getFullPath()).toBe(
28+
'/web-folder/assets/service-worker.js.php',
29+
);
2830
});
2931

3032
test(`should return correct components for a root-relative path`, () => {
3133
const path = new Path('/service-worker.js');
32-
expect(path.getFileName()).toBe('service-worker.js');
33-
expect(path.getFullPath()).toBe('/service-worker.js');
34+
expect(path._getFileName()).toBe('service-worker.js');
35+
expect(path._getFullPath()).toBe('/service-worker.js');
3436
});
3537

3638
test(`should return correct components for an absolute web path`, () => {
3739
const path = new Path('https://site.com/web-folder/service-worker.js');
38-
expect(path.getFileName()).toBe('service-worker.js');
39-
expect(path.getFullPath()).toBe(
40+
expect(path._getFileName()).toBe('service-worker.js');
41+
expect(path._getFullPath()).toBe(
4042
'https://site.com/web-folder/service-worker.js',
4143
);
4244
});
@@ -45,21 +47,15 @@ describe('Path tests', () => {
4547
const path = new Path(
4648
'https://site.com/web-folder/service-worker.js?appId=12345',
4749
);
48-
expect(path.getFullPath()).toBe(
49-
'https://site.com/web-folder/service-worker.js?appId=12345',
50-
);
51-
});
52-
test(`should include query string in path with query`, () => {
53-
const path = new Path(
50+
expect(path._getFullPath()).toBe(
5451
'https://site.com/web-folder/service-worker.js?appId=12345',
5552
);
56-
expect(path.getFileNameWithQuery()).toBe('service-worker.js?appId=12345');
5753
});
5854

5955
test(`should not include query string in path filename`, () => {
6056
const path = new Path(
6157
'https://site.com/web-folder/service-worker.js?appId=12345',
6258
);
63-
expect(path.getFileName()).toBe('service-worker.js');
59+
expect(path._getFileName()).toBe('service-worker.js');
6460
});
6561
});

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": "47.2 kB",
87+
"limit": "47.08 kB",
8888
"gzip": true
8989
},
9090
{

src/page/bell/Button.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
limitGetLast,
55
limitIsEmpty,
66
limitStorePut,
7-
} from 'src/shared/services/limitStore2';
7+
} from 'src/shared/services/limitStore';
88
import OneSignalEvent from 'src/shared/services/OneSignalEvent';
99
import AnimatedElement from './AnimatedElement';
1010
import type Bell from './Bell';

src/page/managers/LoginManager.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ import Log from '../../shared/libraries/Log';
1010

1111
export default class LoginManager {
1212
// Other internal classes should await on this if they access users
13-
static switchingUsersPromise: Promise<void> = Promise.resolve();
13+
static _switchingUsersPromise: Promise<void> = Promise.resolve();
1414

1515
// public api
1616
static async login(externalId: string, token?: string): Promise<void> {
17-
await (this.switchingUsersPromise = LoginManager._login(externalId, token));
17+
await (this._switchingUsersPromise = LoginManager._login(
18+
externalId,
19+
token,
20+
));
1821
}
1922

2023
private static async _login(
@@ -77,7 +80,7 @@ export default class LoginManager {
7780

7881
// public api
7982
static async logout(): Promise<void> {
80-
await (this.switchingUsersPromise = LoginManager._logout());
83+
await (this._switchingUsersPromise = LoginManager._logout());
8184
}
8285

8386
private static async _logout(): Promise<void> {

src/shared/helpers/service-worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function getServiceWorkerHref(
2727
sdkVersion: string,
2828
): string {
2929
return appendServiceWorkerParams(
30-
config.workerPath.getFullPath(),
30+
config.workerPath._getFullPath(),
3131
appId,
3232
sdkVersion,
3333
);

src/shared/managers/ServiceWorkerManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class ServiceWorkerManager {
8787
}
8888

8989
const workerScriptPath = new URL(serviceWorker.scriptURL).pathname;
90-
const swFileName = new Path(workerScriptPath).getFileName();
90+
const swFileName = new Path(workerScriptPath)._getFileName();
9191

9292
// If the current service worker is Akamai's
9393
if (swFileName == 'akam-sw.js') {
@@ -101,7 +101,7 @@ export class ServiceWorkerManager {
101101
"Found a ServiceWorker under Akamai's akam-sw.js?othersw=",
102102
importedSw,
103103
);
104-
return new Path(new URL(importedSw).pathname).getFileName();
104+
return new Path(new URL(importedSw).pathname)._getFileName();
105105
}
106106
}
107107
return swFileName;
@@ -115,7 +115,7 @@ export class ServiceWorkerManager {
115115
return ServiceWorkerActiveState.None;
116116
}
117117
const isValidOSWorker =
118-
fileName == this._config.workerPath.getFileName() ||
118+
fileName == this._config.workerPath._getFileName() ||
119119
fileName == 'OneSignalSDK.sw.js'; // For backwards compatibility with temporary v16 user model beta filename (remove after 5/5/24 deprecation)
120120

121121
if (isValidOSWorker) {

src/shared/managers/sessionManager/SessionManager.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class SessionManager implements ISessionManager {
112112
}
113113

114114
async _handleVisibilityChange(): Promise<void> {
115-
await LoginManager.switchingUsersPromise;
115+
await LoginManager._switchingUsersPromise;
116116

117117
if (!User._singletonInstance?.onesignalId) {
118118
return;
@@ -180,7 +180,7 @@ export class SessionManager implements ISessionManager {
180180
}
181181

182182
async _handleOnBeforeUnload(): Promise<void> {
183-
await LoginManager.switchingUsersPromise;
183+
await LoginManager._switchingUsersPromise;
184184

185185
if (!User._singletonInstance?.onesignalId) {
186186
return;
@@ -213,7 +213,7 @@ export class SessionManager implements ISessionManager {
213213
}
214214

215215
async _handleOnFocus(e: Event): Promise<void> {
216-
await LoginManager.switchingUsersPromise;
216+
await LoginManager._switchingUsersPromise;
217217

218218
Log._debug('handleOnFocus', e);
219219
if (!User._singletonInstance?.onesignalId) {
@@ -243,7 +243,7 @@ export class SessionManager implements ISessionManager {
243243
}
244244

245245
async _handleOnBlur(e: Event): Promise<void> {
246-
await LoginManager.switchingUsersPromise;
246+
await LoginManager._switchingUsersPromise;
247247

248248
Log._debug('handleOnBlur', e);
249249
if (!User._singletonInstance?.onesignalId) {
@@ -273,7 +273,7 @@ export class SessionManager implements ISessionManager {
273273
}
274274

275275
async _upsertSession(sessionOrigin: SessionOriginValue): Promise<void> {
276-
await LoginManager.switchingUsersPromise;
276+
await LoginManager._switchingUsersPromise;
277277

278278
if (User._singletonInstance?.onesignalId) {
279279
const { onesignalId, subscriptionId } =

src/shared/managers/subscription/page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const updatePushSubscriptionModelWithRawSubscription = async (
5353
) => {
5454
// incase a login op was called before user accepts the notifcations permissions, we need to wait for it to finish
5555
// otherwise there would be two login ops in the same bucket for LoginOperationExecutor which would error
56-
await LoginManager.switchingUsersPromise;
56+
await LoginManager._switchingUsersPromise;
5757

5858
let pushModel = await OneSignal._coreDirector._getPushSubscriptionModel();
5959
// for new users, we need to create a new push subscription model and also save its push id to IndexedDB

src/shared/models/Path.ts

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,30 @@
11
import { EmptyArgumentError } from '../errors/common';
22

3+
const QUERY_STRING = '?';
4+
35
/**
46
* Represents a normalized path.
57
*
68
* Paths spaces are trimmed.
79
* Paths without file names will never contain trailing slashes, except for empty paths.
810
*/
911
export default class Path {
10-
private static QUERY_STRING = '?';
11-
12-
private readonly path: string;
12+
private readonly _path: string;
1313

1414
constructor(path: string) {
1515
if (!path) throw EmptyArgumentError('path');
16-
this.path = path.trim();
17-
}
18-
19-
getQueryString(): string | null {
20-
// If there are no ? characters, return null
21-
// If there are multiple ?, return the substring starting after the first ? all the way to the end
22-
const indexOfDelimiter = this.path.indexOf('?');
23-
if (indexOfDelimiter === -1) {
24-
return null;
25-
}
26-
if (this.path.length > indexOfDelimiter) {
27-
// Return the substring *after the first ? to the end
28-
return this.path.substring(indexOfDelimiter + 1);
29-
} else {
30-
// The last character is ?
31-
return null;
32-
}
33-
}
34-
35-
getWithoutQueryString(): string {
36-
return this.path.split(Path.QUERY_STRING)[0];
16+
this._path = path.trim();
3717
}
3818

39-
getFileName(): string | undefined {
40-
return this.getWithoutQueryString().split('\\').pop()?.split('/').pop();
19+
_getWithoutQueryString(): string {
20+
return this._path.split(QUERY_STRING)[0];
4121
}
4222

43-
getFileNameWithQuery(): string | undefined {
44-
return this.path.split('\\').pop()?.split('/').pop();
23+
_getFileName(): string | undefined {
24+
return this._getWithoutQueryString().split('\\').pop()?.split('/').pop();
4525
}
4626

47-
getFullPath() {
48-
return this.path;
27+
_getFullPath() {
28+
return this._path;
4929
}
5030
}

0 commit comments

Comments
 (0)