Skip to content

Commit f501b6e

Browse files
authored
Merge pull request #1396 from OneSignal/fg/reduce-size-2
refactor: more size reduction
2 parents 43ee036 + 6d45c45 commit f501b6e

File tree

97 files changed

+986
-1002
lines changed

Some content is hidden

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

97 files changed

+986
-1002
lines changed

__test__/setupTests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ beforeEach(async () => {
1919
afterEach(() => {
2020
server.resetHandlers();
2121
if (typeof OneSignal !== 'undefined') {
22-
OneSignal._coreDirector?.operationRepo._clear();
23-
OneSignal.emitter?.removeAllListeners();
22+
OneSignal._coreDirector?._operationRepo._clear();
23+
OneSignal._emitter?.removeAllListeners();
2424
}
2525
});
2626

__test__/support/environment/TestEnvironment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class TestEnvironment {
3232
) {
3333
mockJsonp();
3434
const oneSignal = initOSGlobals(config);
35-
OneSignal._coreDirector.operationRepo.queue = [];
35+
OneSignal._coreDirector._operationRepo.queue = [];
3636

3737
if (config.initOneSignalId) {
3838
updateIdentityModel('onesignal_id', ONESIGNAL_ID);

__test__/support/environment/TestEnvironmentHelpers.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ export function initOSGlobals(config: TestEnvironmentConfig = {}) {
2525
global.OneSignal = OneSignal;
2626
global.OneSignal.EVENTS = ONESIGNAL_EVENTS;
2727
global.OneSignal.config = TestContext.getFakeMergedConfig(config);
28-
global.OneSignal.context = new Context(global.OneSignal.config);
29-
global.OneSignal.initialized = true;
30-
global.OneSignal.emitter = new Emitter();
28+
global.OneSignal._context = new Context(global.OneSignal.config);
29+
global.OneSignal._initialized = true;
30+
global.OneSignal._emitter = new Emitter();
3131
const core = new CoreModule();
3232
global.OneSignal._coreDirector = new CoreModuleDirector(core);
3333

3434
// Clear the User singleton before creating new instance
35-
User.singletonInstance = undefined;
35+
User._singletonInstance = undefined;
3636

3737
const userNamespace = new UserNamespace(!!config.initUserAndPushSubscription); // TO DO: pass in subscription, and permission
3838
global.OneSignal.User = userNamespace;
@@ -60,7 +60,7 @@ export const createPushSub = ({
6060
onesignalId?: string;
6161
} = {}) => {
6262
const pushSubscription = new SubscriptionModel();
63-
pushSubscription.initializeFromJson({
63+
pushSubscription._initializeFromJson({
6464
...BASE_SUB,
6565
id,
6666
onesignalId,
@@ -95,7 +95,7 @@ export const setupSubModelStore = async ({
9595
pushModel.web_p256 = web_p256;
9696
}
9797
await setPushToken(pushModel.token);
98-
OneSignal._coreDirector.subscriptionModelStore.replaceAll(
98+
OneSignal._coreDirector._subscriptionModelStore.replaceAll(
9999
[pushModel],
100100
ModelChangeTags.NO_PROPAGATE,
101101
);

__test__/support/helpers/core.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { CoreModuleDirector } from '../../../src/core/CoreModuleDirector';
55

66
export function generateNewSubscription(modelId = '0000000000') {
77
const model = new SubscriptionModel();
8-
model.modelId = modelId;
9-
model.mergeData({
8+
model._modelId = modelId;
9+
model._mergeData({
1010
type: SubscriptionType.Email,
1111
id: '123', // subscription id
1212
token: 'myToken',
@@ -18,6 +18,6 @@ export function generateNewSubscription(modelId = '0000000000') {
1818
// Requirement: Test must also call TestEnvironment.initialize();
1919
export async function getCoreModuleDirector(): Promise<CoreModuleDirector> {
2020
const coreModule = new CoreModule();
21-
await coreModule.init();
21+
await coreModule._init();
2222
return new CoreModuleDirector(coreModule);
2323
}

__test__/support/helpers/setup.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const setupIdentityModel = async (
6464
) => {
6565
const newIdentityModel = new IdentityModel();
6666
newIdentityModel.onesignalId = onesignalID;
67-
OneSignal._coreDirector.identityModelStore.replace(
67+
OneSignal._coreDirector._identityModelStore.replace(
6868
newIdentityModel,
6969
ModelChangeTags.NO_PROPAGATE,
7070
);
@@ -78,7 +78,7 @@ export const setupPropertiesModel = async (
7878
) => {
7979
const newPropertiesModel = new PropertiesModel();
8080
newPropertiesModel.onesignalId = onesignalID;
81-
OneSignal._coreDirector.propertiesModelStore.replace(
81+
OneSignal._coreDirector._propertiesModelStore.replace(
8282
newPropertiesModel,
8383
ModelChangeTags.NO_PROPAGATE,
8484
);
@@ -97,7 +97,7 @@ export const updateIdentityModel = async <
9797
value?: IdentitySchema[T],
9898
) => {
9999
const identityModel = OneSignal._coreDirector._getIdentityModel();
100-
identityModel.setProperty(property, value, ModelChangeTags.NO_PROPAGATE);
100+
identityModel._setProperty(property, value, ModelChangeTags.NO_PROPAGATE);
101101
};
102102

103103
/**
@@ -113,7 +113,7 @@ export const updatePropertiesModel = async <
113113
value?: PropertiesSchema[T],
114114
) => {
115115
const propertiesModel = OneSignal._coreDirector._getPropertiesModel();
116-
propertiesModel.setProperty(property, value, ModelChangeTags.NO_PROPAGATE);
116+
propertiesModel._setProperty(property, value, ModelChangeTags.NO_PROPAGATE);
117117
};
118118

119119
/**
@@ -126,7 +126,7 @@ export const setupSubscriptionModel = async (
126126
const subscriptionModel = new SubscriptionModel();
127127
subscriptionModel.id = id || '';
128128
subscriptionModel.token = token || '';
129-
OneSignal._coreDirector.subscriptionModelStore.replaceAll(
129+
OneSignal._coreDirector._subscriptionModelStore.replaceAll(
130130
[subscriptionModel],
131131
ModelChangeTags.NO_PROPAGATE,
132132
);
@@ -137,7 +137,7 @@ export const setupSubscriptionModel = async (
137137
*/
138138
export const setupLoadStylesheet = async () => {
139139
vi.spyOn(
140-
OneSignal.context._dynamicResourceLoader,
140+
OneSignal._context._dynamicResourceLoader,
141141
'loadSdkStylesheet',
142142
).mockResolvedValue(ResourceLoadState.Loaded);
143143
};

__test__/unit/core/coreModuleDirector.test.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('CoreModuleDirector tests', () => {
1212

1313
describe('getPushSubscriptionModel', () => {
1414
async function getPushSubscriptionModel() {
15-
return (await getCoreModuleDirector()).getPushSubscriptionModel();
15+
return (await getCoreModuleDirector())._getPushSubscriptionModel();
1616
}
1717

1818
test('returns undefined when it find no push records', async () => {
@@ -23,9 +23,7 @@ describe('CoreModuleDirector tests', () => {
2323
const pushModelCurrent = generateNewSubscription();
2424
vi.spyOn(
2525
CoreModuleDirector.prototype,
26-
// @ts-expect-error - private method
27-
'getPushSubscriptionModelByCurrentToken',
28-
// @ts-expect-error - private method
26+
'_getPushSubscriptionModelByCurrentToken',
2927
).mockResolvedValue(pushModelCurrent);
3028
expect(await getPushSubscriptionModel()).toBe(pushModelCurrent);
3129
});
@@ -34,9 +32,7 @@ describe('CoreModuleDirector tests', () => {
3432
const pushModelLastKnown = generateNewSubscription();
3533
vi.spyOn(
3634
CoreModuleDirector.prototype,
37-
// @ts-expect-error - private method
38-
'getPushSubscriptionModelByLastKnownToken',
39-
// @ts-expect-error - private method
35+
'_getPushSubscriptionModelByLastKnownToken',
4036
).mockResolvedValue(pushModelLastKnown);
4137
expect(await getPushSubscriptionModel()).toEqual(pushModelLastKnown);
4238
});
@@ -45,17 +41,13 @@ describe('CoreModuleDirector tests', () => {
4541
const pushModelCurrent = generateNewSubscription();
4642
vi.spyOn(
4743
CoreModuleDirector.prototype,
48-
// @ts-expect-error - private method
49-
'getPushSubscriptionModelByCurrentToken',
50-
// @ts-expect-error - private method
44+
'_getPushSubscriptionModelByCurrentToken',
5145
).mockResolvedValue(pushModelCurrent);
5246

5347
const pushModelLastKnown = generateNewSubscription();
5448
vi.spyOn(
5549
CoreModuleDirector.prototype,
56-
// @ts-expect-error - private method
57-
'getPushSubscriptionModelByLastKnownToken',
58-
// @ts-expect-error - private method
50+
'_getPushSubscriptionModelByLastKnownToken',
5951
).mockResolvedValue(pushModelLastKnown);
6052

6153
expect(await getPushSubscriptionModel()).toBe(pushModelCurrent);

__test__/unit/http/sdkVersion.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe('Sdk Version Header Tests', () => {
9797
},
9898
{
9999
// @ts-expect-error - partial identity object
100-
subscription: generateNewSubscription().data,
100+
subscription: generateNewSubscription()._data,
101101
},
102102
);
103103
expectHeaderToBeSent();

__test__/unit/push/registerForPush.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ describe('Register for push', () => {
2626
});
2727

2828
test('registerForPushNotifications: before OneSignal.initialized', async () => {
29-
global.OneSignal.initialized = false;
29+
global.OneSignal._initialized = false;
3030
global.OneSignal._initCalled = false;
3131

3232
const promise = OneSignal.User.PushSubscription.optIn();
3333

3434
expect(spy).not.toHaveBeenCalled();
3535
OneSignalEvent.trigger(OneSignal.EVENTS.SDK_INITIALIZED);
3636
await promise;
37-
expect(OneSignal.initialized).toBe(true);
37+
expect(OneSignal._initialized).toBe(true);
3838
expect(spy).toHaveBeenCalledTimes(1);
3939
});
4040

4141
// Revisit with Vitest change
4242
test('registerForPushNotifications: after OneSignal.initialized', async () => {
43-
global.OneSignal.initialized = true;
43+
global.OneSignal._initialized = true;
4444
global.OneSignal._initCalled = false;
4545

4646
await expect(InitHelper.registerForPushNotifications()).resolves.toBe(

__test__/unit/pushSubscription/nativePermissionChange.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ vi.useFakeTimers();
2727
describe('Notification Types are set correctly on subscription change', () => {
2828
beforeEach(() => {
2929
TestEnvironment.initialize();
30-
OneSignal.emitter = new Emitter();
30+
OneSignal._emitter = new Emitter();
3131
});
3232

3333
afterEach(async () => {
@@ -112,7 +112,7 @@ describe('Notification Types are set correctly on subscription change', () => {
112112
lastKnownPushToken: PUSH_TOKEN,
113113
lastKnownPushId: SUB_ID,
114114
});
115-
OneSignal._coreDirector.addSubscriptionModel(pushModel);
115+
OneSignal._coreDirector._addSubscriptionModel(pushModel);
116116

117117
await checkAndTriggerSubscriptionChanged();
118118
expect(changeListener).not.toHaveBeenCalled();
@@ -130,7 +130,7 @@ describe('Notification Types are set correctly on subscription change', () => {
130130
lastKnownPushToken: PUSH_TOKEN_2,
131131
lastKnownPushId: SUB_ID_3,
132132
});
133-
OneSignal._coreDirector.subscriptionModelStore.add(pushModel);
133+
OneSignal._coreDirector._subscriptionModelStore.add(pushModel);
134134

135135
await checkAndTriggerSubscriptionChanged();
136136
expect(changeListener).toHaveBeenCalledWith({

__test__/unit/user/user.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('User tests', () => {
88
test('getTags called with unset tags should return empty tags', () => {
99
TestEnvironment.initialize();
1010

11-
const user = User.createOrGetInstance();
11+
const user = User._createOrGetInstance();
1212
const tags = user.getTags();
1313

1414
expect(tags).toStrictEqual({});
@@ -17,7 +17,7 @@ describe('User tests', () => {
1717
test('getTags called with empty tags in properties model should return empty tags', () => {
1818
TestEnvironment.initialize();
1919

20-
const user = User.createOrGetInstance();
20+
const user = User._createOrGetInstance();
2121
const tags = user.getTags();
2222

2323
expect(tags).toStrictEqual({});
@@ -30,7 +30,7 @@ describe('User tests', () => {
3030
const propModel = OneSignal._coreDirector._getPropertiesModel();
3131
propModel.tags = tagsSample;
3232

33-
const user = User.createOrGetInstance();
33+
const user = User._createOrGetInstance();
3434
const tags = user.getTags();
3535

3636
expect(tags).toBe(tagsSample);
@@ -44,7 +44,7 @@ describe('User tests', () => {
4444
const propModel = OneSignal._coreDirector._getPropertiesModel();
4545
propModel.language = languageSample;
4646

47-
const user = User.createOrGetInstance();
47+
const user = User._createOrGetInstance();
4848
const language = user.getLanguage();
4949

5050
expect(language).toBe(languageSample);
@@ -55,7 +55,7 @@ describe('User tests', () => {
5555

5656
const languageSample = 'fr';
5757

58-
const user = User.createOrGetInstance();
58+
const user = User._createOrGetInstance();
5959
user.setLanguage(languageSample);
6060

6161
const propModel = OneSignal._coreDirector._getPropertiesModel();

0 commit comments

Comments
 (0)