Skip to content

Commit 8b56676

Browse files
authored
Merge pull request #1401 from OneSignal/fg/size-reduction-4
chore: more size reduction
2 parents 15ff947 + 853472e commit 8b56676

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1534
-1740
lines changed

__test__/support/helpers/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export const setupSubscriptionModel = async (
138138
export const setupLoadStylesheet = async () => {
139139
vi.spyOn(
140140
OneSignal._context._dynamicResourceLoader,
141-
'loadSdkStylesheet',
141+
'_loadSdkStylesheet',
142142
).mockResolvedValue(ResourceLoadState.Loaded);
143143
};
144144

__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
});

__test__/unit/pushSubscription/nativePermissionChange.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import { MockServiceWorker } from '__test__/support/mocks/MockServiceWorker';
1111
import { clearStore, db, getOptionsValue } from 'src/shared/database/client';
1212
import { setAppState as setDBAppState } from 'src/shared/database/config';
1313
import type { AppState } from 'src/shared/database/types';
14+
import { checkAndTriggerNotificationPermissionChanged } from 'src/shared/helpers/main';
1415
import * as PermissionUtils from 'src/shared/helpers/permissions';
1516
import Emitter from 'src/shared/libraries/Emitter';
1617
import { checkAndTriggerSubscriptionChanged } from 'src/shared/listeners';
17-
import MainHelper from '../../../src/shared/helpers/MainHelper';
1818

1919
vi.mock('src/shared/libraries/Log');
2020
const triggerNotificationSpy = vi.spyOn(
@@ -50,7 +50,7 @@ describe('Notification Types are set correctly on subscription change', () => {
5050
});
5151
await setDbPermission('granted');
5252

53-
await MainHelper._checkAndTriggerNotificationPermissionChanged();
53+
await checkAndTriggerNotificationPermissionChanged();
5454
expect(triggerNotificationSpy).not.toHaveBeenCalled();
5555
});
5656

@@ -74,7 +74,7 @@ describe('Notification Types are set correctly on subscription change', () => {
7474
permChangeStringListener,
7575
);
7676

77-
await MainHelper._checkAndTriggerNotificationPermissionChanged();
77+
await checkAndTriggerNotificationPermissionChanged();
7878

7979
// should update the db
8080
const dbPermission = await getOptionsValue<NotificationPermission>(

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@
8484
},
8585
{
8686
"path": "./build/releases/OneSignalSDK.page.es6.js",
87-
"limit": "47.565 kB",
87+
"limit": "46.601 kB",
8888
"gzip": true
8989
},
9090
{
9191
"path": "./build/releases/OneSignalSDK.sw.js",
92-
"limit": "13.624 kB",
92+
"limit": "13.442 kB",
9393
"gzip": true
9494
},
9595
{

src/core/CoreModuleDirector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from 'src/shared/subscriptions/constants';
99
import type { SubscriptionChannelValue } from 'src/shared/subscriptions/types';
1010
import { logMethodCall } from 'src/shared/utils/utils';
11-
import MainHelper from '../shared/helpers/MainHelper';
11+
import { getCurrentPushToken } from '../shared/helpers/main';
1212
import { RawPushSubscription } from '../shared/models/RawPushSubscription';
1313
import CoreModule from './CoreModule';
1414
import { IdentityModel } from './models/IdentityModel';
@@ -115,7 +115,7 @@ export class CoreModuleDirector {
115115
SubscriptionModel | undefined
116116
> {
117117
logMethodCall('CoreModuleDirector.getPushSubscriptionModelByCurrentToken');
118-
const pushToken = await MainHelper._getCurrentPushToken();
118+
const pushToken = await getCurrentPushToken();
119119
if (pushToken) {
120120
return this._getSubscriptionOfTypeWithToken(
121121
SubscriptionChannel.Push,

src/core/controllers/CustomEventController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import MainHelper from '../../shared/helpers/MainHelper';
1+
import { getAppId } from '../../shared/helpers/main';
22
import { IdentityModelStore } from '../modelStores/IdentityModelStore';
33
import { TrackCustomEventOperation } from '../operations/TrackCustomEventOperation';
44
import type {
@@ -22,7 +22,7 @@ export class CustomEventController implements ICustomEventController {
2222
}
2323

2424
_sendCustomEvent(event: ICustomEvent): void {
25-
const appId = MainHelper._getAppId();
25+
const appId = getAppId();
2626
const identityModel = this._identityModelStore.model;
2727

2828
const op = new TrackCustomEventOperation({

src/core/listeners/IdentityModelStoreListener.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import MainHelper from 'src/shared/helpers/MainHelper';
1+
import { getAppId } from 'src/shared/helpers/main';
22
import { type IdentityModel } from '../models/IdentityModel';
33
import { type IdentityModelStore } from '../modelStores/IdentityModelStore';
44
import { DeleteAliasOperation } from '../operations/DeleteAliasOperation';
@@ -26,7 +26,7 @@ export class IdentityModelStoreListener extends SingletonModelStoreListener<Iden
2626
_oldValue: unknown,
2727
newValue: unknown,
2828
): Operation {
29-
const appId = MainHelper._getAppId();
29+
const appId = getAppId();
3030
if (newValue != null && typeof newValue === 'string') {
3131
return new SetAliasOperation(
3232
appId,

src/core/listeners/PropertiesModelStoreListener.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import MainHelper from 'src/shared/helpers/MainHelper';
1+
import { getAppId } from 'src/shared/helpers/main';
22
import { PropertiesModel } from '../models/PropertiesModel';
33
import { type PropertiesModelStore } from '../modelStores/PropertiesModelStore';
44
import { type Operation } from '../operations/Operation';
@@ -28,7 +28,7 @@ export class PropertiesModelStoreListener extends SingletonModelStoreListener<Pr
2828
_oldValue: unknown,
2929
newValue: unknown,
3030
): Operation | null {
31-
const appId = MainHelper._getAppId();
31+
const appId = getAppId();
3232

3333
return new SetPropertyOperation(
3434
appId,

src/core/listeners/SubscriptionModelStoreListener.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import MainHelper from 'src/shared/helpers/MainHelper';
1+
import { getAppId } from 'src/shared/helpers/main';
22
import { NotificationType } from 'src/shared/subscriptions/constants';
33
import type { NotificationTypeValue } from 'src/shared/subscriptions/types';
44
import { SubscriptionModel } from '../models/SubscriptionModel';
@@ -29,7 +29,7 @@ export class SubscriptionModelStoreListener extends ModelStoreListener<Subscript
2929
const { enabled, notification_types } =
3030
SubscriptionModelStoreListener._getSubscriptionEnabledAndStatus(model);
3131

32-
const appId = MainHelper._getAppId();
32+
const appId = getAppId();
3333
return new CreateSubscriptionOperation({
3434
appId,
3535
onesignalId: this._identityModelStore.model._onesignalId,
@@ -42,7 +42,7 @@ export class SubscriptionModelStoreListener extends ModelStoreListener<Subscript
4242
}
4343

4444
_getRemoveOperation(model: SubscriptionModel): Operation {
45-
const appId = MainHelper._getAppId();
45+
const appId = getAppId();
4646
return new DeleteSubscriptionOperation(
4747
appId,
4848
this._identityModelStore.model._onesignalId,
@@ -53,7 +53,7 @@ export class SubscriptionModelStoreListener extends ModelStoreListener<Subscript
5353
_getUpdateOperation(model: SubscriptionModel): Operation {
5454
const { enabled, notification_types } =
5555
SubscriptionModelStoreListener._getSubscriptionEnabledAndStatus(model);
56-
const appId = MainHelper._getAppId();
56+
const appId = getAppId();
5757

5858
return new UpdateSubscriptionOperation({
5959
appId,

src/core/modelRepo/ModelStore.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export abstract class ModelStore<
9696

9797
_onChanged(args: ModelChangedArgs, tag: string): void {
9898
this._persist();
99-
this._changeSubscription.fire((handler) =>
99+
this._changeSubscription._fire((handler) =>
100100
handler._onModelUpdated(args, tag),
101101
);
102102
}
@@ -116,7 +116,7 @@ export abstract class ModelStore<
116116
for (const item of this._models) {
117117
// no longer listen for changes to this model
118118
item._unsubscribe(this);
119-
this._changeSubscription.fire((handler) =>
119+
this._changeSubscription._fire((handler) =>
120120
handler._onModelRemoved(item, tag),
121121
);
122122
db.delete(this._modelName, item._modelId);
@@ -136,7 +136,7 @@ export abstract class ModelStore<
136136
model._subscribe(this);
137137
this._persist();
138138

139-
this._changeSubscription.fire((handler) =>
139+
this._changeSubscription._fire((handler) =>
140140
handler._onModelAdded(model, tag),
141141
);
142142
}
@@ -151,7 +151,7 @@ export abstract class ModelStore<
151151
await db.delete(this._modelName, model._modelId);
152152
this._persist();
153153

154-
this._changeSubscription.fire((handler) =>
154+
this._changeSubscription._fire((handler) =>
155155
handler._onModelRemoved(model, tag),
156156
);
157157
}

0 commit comments

Comments
 (0)