Skip to content

Commit 1e7ddbd

Browse files
authored
Merge pull request #1399 from OneSignal/fg/size-reduction-3
chore: more size reduction
2 parents 9673631 + 44113ff commit 1e7ddbd

File tree

62 files changed

+541
-583
lines changed

Some content is hidden

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

62 files changed

+541
-583
lines changed

.vscode/settings.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@
33
"source.fixAll.eslint": "explicit",
44
"source.organizeImports": "always"
55
},
6+
"editor.rename.enablePreview": false,
67

78
// a macro to rename a variable to _variable
89
"macros": {
910
"rename_": [
1011
{
1112
"javascript": [
12-
"const ed = vscode.window.activeTextEditor;",
13-
"if (!ed) return;",
13+
"const ed = vscode.window.activeTextEditor; if (!ed) return;",
1414
"const pos = ed.selection.active;",
15-
"const rng = ed.document.getWordRangeAtPosition(pos);",
16-
"if (!rng) return;",
17-
"const oldName = ed.document.getText(rng);",
18-
"// if it already starts with '_', do nothing (remove this guard if you always want to re-run)",
19-
"if (oldName.startsWith('_')) return;",
15+
"const rng = ed.document.getWordRangeAtPosition(pos); if (!rng) return;",
16+
"const oldName = ed.document.getText(rng); if (oldName.startsWith('_')) return;",
2017
"const newName = '_' + oldName;",
21-
"// Ask VS Code for a rename edit at this position",
22-
"const edit = await vscode.commands.executeCommand(",
23-
" 'vscode.executeDocumentRenameProvider',",
24-
" ed.document.uri,",
25-
" pos,",
26-
" newName",
27-
");",
28-
"if (edit) await vscode.workspace.applyEdit(edit);",
29-
"await new Promise(resolve => setTimeout(resolve, 100));",
30-
"await vscode.commands.executeCommand('workbench.action.files.saveAll');"
18+
"const edit = await vscode.commands.executeCommand('vscode.executeDocumentRenameProvider', ed.document.uri, pos, newName);",
19+
"if (!edit) return;",
20+
"await vscode.workspace.applyEdit(edit);",
21+
"(async () => {",
22+
" for (let attempt = 0; attempt < 5; attempt++) {",
23+
" let remaining = 0;",
24+
" for (const doc of vscode.workspace.textDocuments) {",
25+
" try { if (doc.isDirty) { remaining++; await doc.save(); } } catch (_) {}",
26+
" }",
27+
" if (remaining === 0) break;",
28+
" await new Promise(r => setTimeout(r, 80));",
29+
" }",
30+
"})();"
3131
]
3232
}
3333
]

__test__/support/environment/TestEnvironmentHelpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/executors.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ export class SomeOperation extends Operation {
55
super('some-operation');
66
}
77

8-
get applyToRecordId() {
8+
get _applyToRecordId() {
99
return '';
1010
}
1111

12-
get createComparisonKey() {
12+
get _createComparisonKey() {
1313
return '';
1414
}
1515

16-
get modifyComparisonKey() {
16+
get _modifyComparisonKey() {
1717
return '';
1818
}
1919

20-
get groupComparisonType() {
20+
get _groupComparisonType() {
2121
return GroupComparisonType.CREATE;
2222
}
2323

24-
get canStartExecute() {
24+
get _canStartExecute() {
2525
return true;
2626
}
2727
}

__test__/support/helpers/setup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const setupIdentityModel = async (
6363
onesignalID: string = ONESIGNAL_ID,
6464
) => {
6565
const newIdentityModel = new IdentityModel();
66-
newIdentityModel.onesignalId = onesignalID;
66+
newIdentityModel._onesignalId = onesignalID;
6767
OneSignal._coreDirector._identityModelStore.replace(
6868
newIdentityModel,
6969
ModelChangeTags.NO_PROPAGATE,
@@ -77,7 +77,7 @@ export const setupPropertiesModel = async (
7777
onesignalID: string = ONESIGNAL_ID,
7878
) => {
7979
const newPropertiesModel = new PropertiesModel();
80-
newPropertiesModel.onesignalId = onesignalID;
80+
newPropertiesModel._onesignalId = onesignalID;
8181
OneSignal._coreDirector._propertiesModelStore.replace(
8282
newPropertiesModel,
8383
ModelChangeTags.NO_PROPAGATE,
@@ -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
);

__test__/unit/user/user.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('User tests', () => {
2828

2929
const tagsSample = { key1: 'value1' };
3030
const propModel = OneSignal._coreDirector._getPropertiesModel();
31-
propModel.tags = tagsSample;
31+
propModel._tags = tagsSample;
3232

3333
const user = User._createOrGetInstance();
3434
const tags = user.getTags();
@@ -42,7 +42,7 @@ describe('User tests', () => {
4242
const languageSample = 'fr';
4343

4444
const propModel = OneSignal._coreDirector._getPropertiesModel();
45-
propModel.language = languageSample;
45+
propModel._language = languageSample;
4646

4747
const user = User._createOrGetInstance();
4848
const language = user.getLanguage();
@@ -59,6 +59,6 @@ describe('User tests', () => {
5959
user.setLanguage(languageSample);
6060

6161
const propModel = OneSignal._coreDirector._getPropertiesModel();
62-
expect(propModel.language).toBe(languageSample);
62+
expect(propModel._language).toBe(languageSample);
6363
});
6464
});

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

src/core/CoreModuleDirector.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import FuturePushSubscriptionRecord from 'src/page/userModel/FuturePushSubscriptionRecord';
22
import { getPushToken } from 'src/shared/database/subscription';
3+
import { isPushSubscriptionType } from 'src/shared/helpers/subscription';
34
import { IDManager } from 'src/shared/managers/IDManager';
45
import {
56
SubscriptionChannel,
67
SubscriptionType,
78
} from 'src/shared/subscriptions/constants';
89
import type { SubscriptionChannelValue } from 'src/shared/subscriptions/types';
910
import { logMethodCall } from 'src/shared/utils/utils';
10-
import SubscriptionHelper from '../../src/shared/helpers/SubscriptionHelper';
1111
import MainHelper from '../shared/helpers/MainHelper';
1212
import { RawPushSubscription } from '../shared/models/RawPushSubscription';
1313
import CoreModule from './CoreModule';
@@ -108,9 +108,7 @@ export class CoreModuleDirector {
108108
public _getAllPushSubscriptionModels(): SubscriptionModel[] {
109109
logMethodCall('CoreModuleDirector.getAllPushSubscriptionModels');
110110
const subscriptions = this._core._subscriptionModelStore.list();
111-
return subscriptions.filter((s) =>
112-
SubscriptionHelper.isPushSubscriptionType(s.type),
113-
);
111+
return subscriptions.filter((s) => isPushSubscriptionType(s.type));
114112
}
115113

116114
async _getPushSubscriptionModelByCurrentToken(): Promise<

src/core/controllers/CustomEventController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export class CustomEventController implements ICustomEventController {
2727

2828
const op = new TrackCustomEventOperation({
2929
appId,
30-
onesignalId: identityModel.onesignalId,
31-
externalId: identityModel.externalId,
30+
onesignalId: identityModel._onesignalId,
31+
externalId: identityModel._externalId,
3232
timestamp: new Date().toISOString(),
3333
event,
3434
});

src/core/executors/CustomEventOperationExecutor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ export class CustomEventsOperationExecutor implements IOperationExecutor {
5050
}
5151

5252
const response = await sendCustomEvent(
53-
{ appId: operation.appId },
53+
{ appId: operation._appId },
5454
{
5555
name: operation.event.name,
56-
onesignal_id: operation.onesignalId,
56+
onesignal_id: operation._onesignalId,
5757
external_id: operation.externalId,
5858
timestamp: operation.timestamp,
5959
payload: {

src/core/executors/IdentityOperationExecutor.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('IdentityOperationExecutor', () => {
6161
);
6262
getRebuildOpsSpy = vi.spyOn(
6363
rebuildUserService,
64-
'getRebuildOperationsIfCurrentUser',
64+
'_getRebuildOperationsIfCurrentUser',
6565
);
6666
});
6767

@@ -158,20 +158,20 @@ describe('IdentityOperationExecutor', () => {
158158
expect(res5.retryAfterSeconds).toBeUndefined();
159159

160160
// with rebuild ops
161-
identityModelStore.model.onesignalId = ONESIGNAL_ID;
161+
identityModelStore.model._onesignalId = ONESIGNAL_ID;
162162
const res7 = await executor._execute(ops);
163163
expect(res7.result).toBe(ExecutionResult.FAIL_RETRY);
164164
expect(res7.retryAfterSeconds).toBeUndefined();
165165
expect(res7.operations).toMatchObject([
166166
{
167-
name: 'login-user',
168-
appId: APP_ID,
169-
onesignalId: ONESIGNAL_ID,
167+
_name: 'login-user',
168+
_appId: APP_ID,
169+
_onesignalId: ONESIGNAL_ID,
170170
},
171171
{
172-
name: 'refresh-user',
173-
appId: APP_ID,
174-
onesignalId: ONESIGNAL_ID,
172+
_name: 'refresh-user',
173+
_appId: APP_ID,
174+
_onesignalId: ONESIGNAL_ID,
175175
},
176176
]);
177177

0 commit comments

Comments
 (0)