Skip to content

Commit 835aa5e

Browse files
committed
rename slidedown methods
1 parent cb491b3 commit 835aa5e

File tree

16 files changed

+265
-213
lines changed

16 files changed

+265
-213
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ngrok.log
1313
.vscode/**
1414
!.vscode/launch.json
1515
!.vscode/settings.json
16+
!.vscode/keybindings.json
1617
.cursor/
1718

1819
coverage

.vscode/keybindings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{
3+
"key": "shift+cmd+y",
4+
"command": "macros.rename_"
5+
}
6+
]

.vscode/settings.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,33 @@
22
"editor.codeActionsOnSave": {
33
"source.fixAll.eslint": "explicit",
44
"source.organizeImports": "always"
5+
},
6+
// a macro to rename a variable to _variable
7+
"macros": {
8+
"rename_": [
9+
{
10+
"javascript": [
11+
"const ed = vscode.window.activeTextEditor;",
12+
"if (!ed) return;",
13+
"const pos = ed.selection.active;",
14+
"const rng = ed.document.getWordRangeAtPosition(pos);",
15+
"if (!rng) return;",
16+
"const oldName = ed.document.getText(rng);",
17+
"// if it already starts with '_', do nothing (remove this guard if you always want to re-run)",
18+
"if (oldName.startsWith('_')) return;",
19+
"const newName = '_' + oldName;",
20+
"// Ask VS Code for a rename edit at this position",
21+
"const edit = await vscode.commands.executeCommand(",
22+
" 'vscode.executeDocumentRenameProvider',",
23+
" ed.document.uri,",
24+
" pos,",
25+
" newName",
26+
");",
27+
"if (edit) {",
28+
" await vscode.workspace.applyEdit(edit);",
29+
"}"
30+
]
31+
}
32+
]
533
}
634
}

__test__/support/environment/TestContext.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export default class TestContext {
9595
slidedown: {
9696
prompts: [
9797
{
98-
type: DelayedPromptType.Push,
98+
type: DelayedPromptType._Push,
9999
autoPrompt: false,
100100
text: {
101101
acceptButton: 'Allow',
@@ -238,7 +238,7 @@ export default class TestContext {
238238
slidedown: {
239239
prompts: [
240240
{
241-
type: DelayedPromptType.Push,
241+
type: DelayedPromptType._Push,
242242
autoPrompt: false,
243243
text: {
244244
acceptButton: 'Allow',
@@ -364,7 +364,7 @@ export default class TestContext {
364364
slidedown: {
365365
prompts: [
366366
{
367-
type: DelayedPromptType.Push,
367+
type: DelayedPromptType._Push,
368368
autoPrompt: false,
369369
text: {
370370
acceptButton: 'Allow',

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

src/onesignal/SlidedownNamespace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class SlidedownNamespace extends EventListenerBase {
1616
if (isConsentRequiredButNotGiven()) return;
1717
await awaitOneSignalInitAndSupported();
1818
await OneSignal._context.promptsManager.internalShowParticularSlidedown(
19-
DelayedPromptType.Push,
19+
DelayedPromptType._Push,
2020
options,
2121
);
2222
}

src/page/managers/PromptsManager.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class PromptsManager {
7474
// show native prompt
7575
const nativePromptOptions = this.getDelayedPromptOptions(
7676
userPromptOptions,
77-
DelayedPromptType.Native,
77+
DelayedPromptType._Native,
7878
);
7979
const isPageViewConditionMetForNative: boolean =
8080
this.isPageViewConditionMet(nativePromptOptions);
@@ -85,7 +85,7 @@ export class PromptsManager {
8585

8686
if (conditionMetWithNativeOptions && !forceSlidedownWithNativeOptions) {
8787
this.internalShowDelayedPrompt(
88-
DelayedPromptType.Native,
88+
DelayedPromptType._Native,
8989
nativePromptOptions.timeDelay || 0,
9090
);
9191
return;
@@ -94,12 +94,12 @@ export class PromptsManager {
9494
// if slidedown not configured, condition met with native options, & should force slidedown over native:
9595
const isPushSlidedownConfigured = !!getFirstSlidedownPromptOptionsWithType(
9696
userPromptOptions?.slidedown?.prompts,
97-
DelayedPromptType.Push,
97+
DelayedPromptType._Push,
9898
);
9999

100100
if (forceSlidedownWithNativeOptions && !isPushSlidedownConfigured) {
101101
this.internalShowDelayedPrompt(
102-
DelayedPromptType.Push,
102+
DelayedPromptType._Push,
103103
nativePromptOptions.timeDelay || 0,
104104
);
105105
}
@@ -145,31 +145,31 @@ export class PromptsManager {
145145
return;
146146
}
147147

148-
if (requiresUserInteraction() && type === DelayedPromptType.Native) {
149-
type = DelayedPromptType.Push; // Push Slidedown for cases where user interaction is needed
148+
if (requiresUserInteraction() && type === DelayedPromptType._Native) {
149+
type = DelayedPromptType._Push; // Push Slidedown for cases where user interaction is needed
150150
}
151151

152152
if (timeDelaySeconds > 0) {
153153
await delay(timeDelaySeconds * 1_000);
154154
}
155155

156156
switch (type) {
157-
case DelayedPromptType.Native:
157+
case DelayedPromptType._Native:
158158
await this.internalShowNativePrompt();
159159
break;
160-
case DelayedPromptType.Push:
160+
case DelayedPromptType._Push:
161161
await this.internalShowSlidedownPrompt(options);
162162
break;
163-
case DelayedPromptType.Category:
163+
case DelayedPromptType._Category:
164164
await this.internalShowCategorySlidedown(options);
165165
break;
166-
case DelayedPromptType.Sms:
166+
case DelayedPromptType._Sms:
167167
await this.internalShowSmsSlidedown(options);
168168
break;
169-
case DelayedPromptType.Email:
169+
case DelayedPromptType._Email:
170170
await this.internalShowEmailSlidedown(options);
171171
break;
172-
case DelayedPromptType.SmsAndEmail:
172+
case DelayedPromptType._SmsAndEmail:
173173
await this.internalShowSmsAndEmailSlidedown(options);
174174
break;
175175
default:
@@ -222,7 +222,7 @@ export class PromptsManager {
222222
): Promise<void> {
223223
logMethodCall('internalShowCategorySlidedown');
224224
await this.internalShowParticularSlidedown(
225-
DelayedPromptType.Category,
225+
DelayedPromptType._Category,
226226
options,
227227
);
228228
}
@@ -231,15 +231,15 @@ export class PromptsManager {
231231
options?: AutoPromptOptions,
232232
): Promise<void> {
233233
logMethodCall('internalShowSmsSlidedown');
234-
await this.internalShowParticularSlidedown(DelayedPromptType.Sms, options);
234+
await this.internalShowParticularSlidedown(DelayedPromptType._Sms, options);
235235
}
236236

237237
public async internalShowEmailSlidedown(
238238
options?: AutoPromptOptions,
239239
): Promise<void> {
240240
logMethodCall('internalShowEmailSlidedown');
241241
await this.internalShowParticularSlidedown(
242-
DelayedPromptType.Email,
242+
DelayedPromptType._Email,
243243
options,
244244
);
245245
}
@@ -249,7 +249,7 @@ export class PromptsManager {
249249
): Promise<void> {
250250
logMethodCall('internalShowSmsAndEmailSlidedown');
251251
await this.internalShowParticularSlidedown(
252-
DelayedPromptType.SmsAndEmail,
252+
DelayedPromptType._SmsAndEmail,
253253
options,
254254
);
255255
}
@@ -272,7 +272,7 @@ export class PromptsManager {
272272
getFirstSlidedownPromptOptionsWithType(prompts, typeToPullFromConfig);
273273

274274
if (!slidedownPromptOptions) {
275-
if (typeToPullFromConfig !== DelayedPromptType.Push) {
275+
if (typeToPullFromConfig !== DelayedPromptType._Push) {
276276
Log._error(
277277
`OneSignal: slidedown of type '${typeToPullFromConfig}' couldn't be shown. Check your configuration` +
278278
` on the OneSignal dashboard or your custom code initialization.`,
@@ -313,10 +313,10 @@ export class PromptsManager {
313313
return;
314314
}
315315

316-
const type = this.context._slidedownManager._slidedown?.options.type;
316+
const type = this.context._slidedownManager._slidedown?._options.type;
317317
switch (type) {
318-
case DelayedPromptType.Push:
319-
case DelayedPromptType.Category:
318+
case DelayedPromptType._Push:
319+
case DelayedPromptType._Category:
320320
Log._debug(
321321
'Setting flag to not show the slidedown to the user again.',
322322
);
@@ -362,7 +362,7 @@ export class PromptsManager {
362362
}
363363

364364
switch (type) {
365-
case DelayedPromptType.Native: {
365+
case DelayedPromptType._Native: {
366366
const nativePromptOptions = promptOptions.native;
367367
return {
368368
enabled: nativePromptOptions?.enabled,
@@ -371,11 +371,11 @@ export class PromptsManager {
371371
pageViews: nativePromptOptions?.pageViews,
372372
};
373373
}
374-
case DelayedPromptType.Push:
375-
case DelayedPromptType.Category:
376-
case DelayedPromptType.Email:
377-
case DelayedPromptType.Sms:
378-
case DelayedPromptType.SmsAndEmail: {
374+
case DelayedPromptType._Push:
375+
case DelayedPromptType._Category:
376+
case DelayedPromptType._Email:
377+
case DelayedPromptType._Sms:
378+
case DelayedPromptType._SmsAndEmail: {
379379
const { userConfig } = this.context._appConfig;
380380
const options = getFirstSlidedownPromptOptionsWithType(
381381
userConfig.promptOptions?.slidedown?.prompts || [],

src/page/managers/slidedownManager/SlidedownManager.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ const config = {
244244
cancelButton: 'No Thanks',
245245
actionMessage: message,
246246
},
247-
type: DelayedPromptType.Category,
247+
type: DelayedPromptType._Category,
248248
},
249249
{
250250
autoPrompt: true,
@@ -254,7 +254,7 @@ const config = {
254254
actionMessage: message,
255255
emailLabel: 'Email',
256256
},
257-
type: DelayedPromptType.Email,
257+
type: DelayedPromptType._Email,
258258
},
259259
{
260260
autoPrompt: true,
@@ -264,7 +264,7 @@ const config = {
264264
actionMessage: message,
265265
smsLabel: 'Phone Number',
266266
},
267-
type: DelayedPromptType.Sms,
267+
type: DelayedPromptType._Sms,
268268
},
269269
{
270270
autoPrompt: true,
@@ -275,7 +275,7 @@ const config = {
275275
emailLabel: 'Email',
276276
smsLabel: 'Phone Number',
277277
},
278-
type: DelayedPromptType.SmsAndEmail,
278+
type: DelayedPromptType._SmsAndEmail,
279279
},
280280
],
281281
},

0 commit comments

Comments
 (0)