Skip to content

Commit eaba3e6

Browse files
committed
more renames
1 parent 54e3784 commit eaba3e6

22 files changed

+97
-104
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/helpers/setup.ts

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

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

src/core/executors/LoginUserOperationExecutor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class LoginUserOperationExecutor implements IOperationExecutor {
106106
);
107107
}
108108

109-
if (this._propertiesModelStore.model.onesignalId === opOneSignalId) {
109+
if (this._propertiesModelStore.model._onesignalId === opOneSignalId) {
110110
this._propertiesModelStore.model._setProperty(
111111
'onesignalId',
112112
backendOneSignalId,
@@ -195,7 +195,7 @@ export class LoginUserOperationExecutor implements IOperationExecutor {
195195
);
196196
}
197197

198-
if (this._propertiesModelStore.model.onesignalId === opOneSignalId) {
198+
if (this._propertiesModelStore.model._onesignalId === opOneSignalId) {
199199
this._propertiesModelStore.model._setProperty(
200200
'onesignalId',
201201
backendOneSignalId,

src/core/executors/RefreshUserOperationExecutor.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('RefreshUserOperationExecutor', () => {
108108

109109
const result = await executor._execute([refreshOp]);
110110
expect(result.result).toBe(ExecutionResult.SUCCESS);
111-
expect(propertiesModelStore.model.language).not.toBe('fr');
111+
expect(propertiesModelStore.model._language).not.toBe('fr');
112112
});
113113

114114
test('should handle successful user retrieval and update models', async () => {
@@ -152,13 +152,13 @@ describe('RefreshUserOperationExecutor', () => {
152152
);
153153

154154
// Check properties model updates
155-
expect(propertiesModelStore.model.country).toBe('US');
156-
expect(propertiesModelStore.model.language).toBe('en');
157-
expect(propertiesModelStore.model.tags).toEqual({
155+
expect(propertiesModelStore.model._country).toBe('US');
156+
expect(propertiesModelStore.model._language).toBe('en');
157+
expect(propertiesModelStore.model._tags).toEqual({
158158
test_tag: 'test_value',
159159
test_tag_2: 'test_value_2',
160160
});
161-
expect(propertiesModelStore.model.timezone_id).toBe('America/New_York');
161+
expect(propertiesModelStore.model._timezone_id).toBe('America/New_York');
162162

163163
// Check subscription model updates
164164
const subscriptions = subscriptionModelStore.list();
@@ -181,7 +181,7 @@ describe('RefreshUserOperationExecutor', () => {
181181
pushSubModel.id = SUB_ID_2;
182182
pushSubModel.type = SubscriptionType.ChromePush;
183183
pushSubModel.token = PUSH_TOKEN;
184-
pushSubModel.notification_types = NotificationType.Subscribed;
184+
pushSubModel._notification_types = NotificationType.Subscribed;
185185

186186
subscriptionModelStore.add(pushSubModel, ModelChangeTags.NO_PROPAGATE);
187187
await setPushToken(PUSH_TOKEN);

src/core/executors/RefreshUserOperationExecutor.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class RefreshUserOperationExecutor implements IOperationExecutor {
8888
}
8989

9090
const propertiesModel = new PropertiesModel();
91-
propertiesModel.onesignalId = op._onesignalId;
91+
propertiesModel._onesignalId = op._onesignalId;
9292

9393
const { properties = {}, subscriptions = [] } = result;
9494

@@ -102,15 +102,15 @@ export class RefreshUserOperationExecutor implements IOperationExecutor {
102102
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
103103
model.id = sub.id!;
104104
model.token = sub.token ?? '';
105-
model.notification_types =
105+
model._notification_types =
106106
sub.notification_types ?? NotificationType.Subscribed;
107107
model.type = sub.type;
108108
model.enabled =
109-
model.notification_types !== NotificationType.UserOptedOut;
109+
model._notification_types !== NotificationType.UserOptedOut;
110110
model.sdk = sub.sdk;
111111
model.device_os = sub.device_os;
112112
model.device_model = sub.device_model;
113-
model.onesignalId = op._onesignalId;
113+
model._onesignalId = op._onesignalId;
114114

115115
// We only add a non-push subscriptions. For push, the device is the source of truth
116116
// so we don't want to cache these subscriptions from the backend.
@@ -122,7 +122,7 @@ export class RefreshUserOperationExecutor implements IOperationExecutor {
122122
const pushModel =
123123
await OneSignal._coreDirector._getPushSubscriptionModel();
124124
if (pushModel) {
125-
pushModel.onesignalId = op._onesignalId;
125+
pushModel._onesignalId = op._onesignalId;
126126
subscriptionModels.push(pushModel);
127127
}
128128

src/core/executors/UpdateUserOperationExecutor.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('UpdateUserOperationExecutor', () => {
9191

9292
const result = await executor._execute([setPropertyOp]);
9393
expect(result.result).toBe(ExecutionResult.SUCCESS);
94-
expect(propertiesModelStore.model.language).toBe('fr');
94+
expect(propertiesModelStore.model._language).toBe('fr');
9595
});
9696

9797
test('can set tags', async () => {
@@ -105,7 +105,7 @@ describe('UpdateUserOperationExecutor', () => {
105105

106106
const result = await executor._execute([setPropertyOp]);
107107
expect(result.result).toBe(ExecutionResult.SUCCESS);
108-
expect(propertiesModelStore.model.tags).toEqual({
108+
expect(propertiesModelStore.model._tags).toEqual({
109109
tagA: 'valueA',
110110
tagB: 'valueB',
111111
});

src/core/executors/UpdateUserOperationExecutor.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
getResponseStatusType,
33
ResponseStatusType,
44
} from 'src/shared/helpers/NetworkUtils';
5-
import { PropertyOperationHelper } from 'src/shared/helpers/PropertyOperationHelper';
65
import Log from 'src/shared/libraries/Log';
76
import { IdentityConstants, OPERATION_NAME } from '../constants';
87
import { type IPropertiesModelKeys } from '../models/PropertiesModel';
@@ -54,11 +53,10 @@ export class UpdateUserOperationExecutor implements IOperationExecutor {
5453
appId = operation._appId;
5554
onesignalId = operation._onesignalId;
5655
}
57-
propertiesObject =
58-
PropertyOperationHelper.createPropertiesFromOperation(
59-
operation,
60-
propertiesObject,
61-
);
56+
propertiesObject = createPropertiesFromOperation(
57+
operation,
58+
propertiesObject,
59+
);
6260
} else {
6361
throw new Error(`Unrecognized operation: ${operation}`);
6462
}
@@ -166,3 +164,22 @@ export class UpdateUserOperationExecutor implements IOperationExecutor {
166164
}
167165
}
168166
}
167+
168+
function createPropertiesFromOperation(
169+
operation: Operation,
170+
properties: PropertiesObject,
171+
): PropertiesObject {
172+
if (operation instanceof SetPropertyOperation) {
173+
const propertyKey = operation.property;
174+
const allowedKeys = Object.keys(properties);
175+
if (allowedKeys.includes(propertyKey)) {
176+
return new PropertiesObject({
177+
...properties,
178+
[propertyKey]: operation.value,
179+
});
180+
}
181+
return new PropertiesObject({ ...properties });
182+
}
183+
184+
throw new Error(`Unsupported operation type: ${operation._name}`);
185+
}

src/core/listeners/PropertiesModelStoreListener.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class PropertiesModelStoreListener extends SingletonModelStoreListener<Pr
3232

3333
return new SetPropertyOperation(
3434
appId,
35-
model.onesignalId,
35+
model._onesignalId,
3636
property,
3737
newValue as PropertyValue[string],
3838
);

0 commit comments

Comments
 (0)