Skip to content

Commit c655d58

Browse files
committed
more prefixing of methods
1 parent 1e7ddbd commit c655d58

File tree

13 files changed

+170
-201
lines changed

13 files changed

+170
-201
lines changed

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": "47.44 kB",
8888
"gzip": true
8989
},
9090
{
9191
"path": "./build/releases/OneSignalSDK.sw.js",
92-
"limit": "13.624 kB",
92+
"limit": "13.58 kB",
9393
"gzip": true
9494
},
9595
{

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
}

src/core/modelStores/SingletonModelStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class SingletonModelStore<TModel extends Model>
3939
const existingModel = this.model;
4040
existingModel._initializeFromModel(existingModel._modelId, model);
4141
this.store._persist();
42-
this.changeSubscription.fire((handler) =>
42+
this.changeSubscription._fire((handler) =>
4343
handler._onModelReplaced(existingModel, tag),
4444
);
4545
}
@@ -65,7 +65,7 @@ export class SingletonModelStore<TModel extends Model>
6565
}
6666

6767
_onModelUpdated(args: ModelChangedArgs, tag: ModelChangeTagValue): void {
68-
this.changeSubscription.fire((handler) =>
68+
this.changeSubscription._fire((handler) =>
6969
handler._onModelUpdated(args, tag),
7070
);
7171
}

src/core/models/Model.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ export class Model<U extends object = object, T extends U & object = U & object>
182182
oldValue,
183183
newValue,
184184
};
185-
this._changeNotifier.fire((handler) => handler._onChanged(changeArgs, tag));
185+
this._changeNotifier._fire((handler) =>
186+
handler._onChanged(changeArgs, tag),
187+
);
186188
}
187189

188190
/**

src/onesignal/SessionNamespace.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ export class SessionNamespace {
2727
return;
2828
}
2929

30-
if (!(await outcomesHelper.beforeOutcomeSend())) {
30+
if (!(await outcomesHelper._beforeOutcomeSend())) {
3131
return;
3232
}
3333

34-
const outcomeAttribution = await outcomesHelper.getAttribution();
34+
const outcomeAttribution = await outcomesHelper._getAttribution();
3535

36-
await outcomesHelper.send({
36+
await outcomesHelper._send({
3737
type: outcomeAttribution.type,
3838
notificationIds: outcomeAttribution.notificationIds,
3939
weight: outcomeWeight,
@@ -54,10 +54,10 @@ export class SessionNamespace {
5454
true,
5555
);
5656

57-
if (!(await outcomesHelper.beforeOutcomeSend())) {
57+
if (!(await outcomesHelper._beforeOutcomeSend())) {
5858
return;
5959
}
60-
const outcomeAttribution = await outcomesHelper.getAttribution();
60+
const outcomeAttribution = await outcomesHelper._getAttribution();
6161

6262
if (outcomeAttribution.type === OutcomeAttributionType.NotSupported) {
6363
Log._warn(
@@ -70,12 +70,12 @@ export class SessionNamespace {
7070
const { notificationIds } = outcomeAttribution;
7171
// only new notifs that ought to be attributed
7272
const newNotifsToAttributeWithOutcome =
73-
await outcomesHelper.getNotifsToAttributeWithUniqueOutcome(
73+
await outcomesHelper._getNotifsToAttributeWithUniqueOutcome(
7474
notificationIds,
7575
);
7676

7777
if (
78-
!outcomesHelper.shouldSendUnique(
78+
!outcomesHelper._shouldSendUnique(
7979
outcomeAttribution,
8080
newNotifsToAttributeWithOutcome,
8181
)
@@ -84,7 +84,7 @@ export class SessionNamespace {
8484
return;
8585
}
8686

87-
await outcomesHelper.send({
87+
await outcomesHelper._send({
8888
type: outcomeAttribution.type,
8989
notificationIds: newNotifsToAttributeWithOutcome,
9090
});
Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,26 @@
11
import type { IEventNotifier } from 'src/core/types/models';
22

33
export class EventProducer<THandler> implements IEventNotifier<THandler> {
4-
private subscribers: THandler[] = [];
4+
private _subscribers: THandler[] = [];
55

66
get _hasSubscribers(): boolean {
7-
return this.subscribers.length > 0;
7+
return this._subscribers.length > 0;
88
}
99

1010
_subscribe(handler: THandler): void {
11-
this.subscribers.push(handler);
11+
this._subscribers.push(handler);
1212
}
1313

1414
_unsubscribe(handler: THandler): void {
15-
const index = this.subscribers.indexOf(handler);
15+
const index = this._subscribers.indexOf(handler);
1616
if (index !== -1) {
17-
this.subscribers.splice(index, 1);
17+
this._subscribers.splice(index, 1);
1818
}
1919
}
2020

21-
subscribeAll(from: EventProducer<THandler>): void {
22-
for (const handler of from.subscribers) {
23-
this._subscribe(handler);
24-
}
25-
}
26-
27-
fire(callback: (handler: THandler) => void): void {
28-
for (const handler of this.subscribers) {
21+
_fire(callback: (handler: THandler) => void): void {
22+
for (const handler of this._subscribers) {
2923
callback(handler);
3024
}
3125
}
32-
33-
async suspendingFire(
34-
callback: (handler: THandler) => Promise<void>,
35-
): Promise<void> {
36-
for (const handler of this.subscribers) {
37-
await callback(handler);
38-
}
39-
}
4026
}

src/shared/helpers/OutcomesHelper.ts

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ const SEND_OUTCOME = 'sendOutcome';
1919
const SEND_UNIQUE_OUTCOME = 'sendUniqueOutcome';
2020

2121
export default class OutcomesHelper {
22-
private outcomeName: string;
23-
private config: OutcomesConfig;
24-
private appId: string;
25-
private isUnique: boolean;
22+
private _outcomeName: string;
23+
private _config: OutcomesConfig;
24+
private _appId: string;
25+
private _isUnique: boolean;
2626

2727
/**
2828
* @param {string} appId
@@ -36,10 +36,10 @@ export default class OutcomesHelper {
3636
outcomeName: string,
3737
isUnique: boolean,
3838
) {
39-
this.outcomeName = outcomeName;
40-
this.config = config;
41-
this.appId = appId;
42-
this.isUnique = isUnique;
39+
this._outcomeName = outcomeName;
40+
this._config = config;
41+
this._appId = appId;
42+
this._isUnique = isUnique;
4343
}
4444
/**
4545
* Returns `OutcomeAttribution` object which includes
@@ -50,27 +50,27 @@ export default class OutcomesHelper {
5050
* does not check if they have been previously attributed (used in both sendOutcome & sendUniqueOutcome)
5151
* @returns Promise
5252
*/
53-
async getAttribution(): Promise<OutcomeAttribution> {
54-
return await getConfigAttribution(this.config);
53+
async _getAttribution(): Promise<OutcomeAttribution> {
54+
return await getConfigAttribution(this._config);
5555
}
5656

5757
/**
5858
* Performs logging of method call and returns whether Outcomes are supported
5959
* @param {boolean} isUnique
6060
* @returns Promise
6161
*/
62-
async beforeOutcomeSend(): Promise<boolean> {
63-
const outcomeMethodString = this.isUnique
62+
async _beforeOutcomeSend(): Promise<boolean> {
63+
const outcomeMethodString = this._isUnique
6464
? SEND_UNIQUE_OUTCOME
6565
: SEND_OUTCOME;
66-
logMethodCall(outcomeMethodString, this.outcomeName);
66+
logMethodCall(outcomeMethodString, this._outcomeName);
6767

68-
if (!this.config) {
68+
if (!this._config) {
6969
Log._debug('Outcomes feature not supported by main application yet.');
7070
return false;
7171
}
7272

73-
if (!this.outcomeName) {
73+
if (!this._outcomeName) {
7474
Log._error('Outcome name is required');
7575
return false;
7676
}
@@ -91,10 +91,10 @@ export default class OutcomesHelper {
9191
* @param {string} outcomeName
9292
* @returns Promise
9393
*/
94-
async getAttributedNotifsByUniqueOutcomeName(): Promise<string[]> {
94+
async _getAttributedNotifsByUniqueOutcomeName(): Promise<string[]> {
9595
const sentOutcomes = await db.getAll('SentUniqueOutcome');
9696
return sentOutcomes
97-
.filter((o) => o.outcomeName === this.outcomeName)
97+
.filter((o) => o.outcomeName === this._outcomeName)
9898
.reduce((acc: string[], curr: SentUniqueOutcome) => {
9999
const notificationIds = curr.notificationIds || [];
100100
return [...acc, ...notificationIds];
@@ -106,25 +106,28 @@ export default class OutcomesHelper {
106106
* @param {string} outcomeName
107107
* @param {string[]} notificationIds
108108
*/
109-
async getNotifsToAttributeWithUniqueOutcome(notificationIds: string[]) {
109+
async _getNotifsToAttributeWithUniqueOutcome(notificationIds: string[]) {
110110
const previouslyAttributedArr: string[] =
111-
await this.getAttributedNotifsByUniqueOutcomeName();
111+
await this._getAttributedNotifsByUniqueOutcomeName();
112112

113113
return notificationIds.filter(
114114
(id) => previouslyAttributedArr.indexOf(id) === -1,
115115
);
116116
}
117117

118-
shouldSendUnique(outcomeAttribution: OutcomeAttribution, notifArr: string[]) {
118+
_shouldSendUnique(
119+
outcomeAttribution: OutcomeAttribution,
120+
notifArr: string[],
121+
) {
119122
// we should only send if type is unattributed OR there are notifs to attribute
120123
if (outcomeAttribution.type === OutcomeAttributionType.Unattributed) {
121124
return true;
122125
}
123126
return notifArr.length > 0;
124127
}
125128

126-
async saveSentUniqueOutcome(newNotificationIds: string[]): Promise<void> {
127-
const outcomeName = this.outcomeName;
129+
async _saveSentUniqueOutcome(newNotificationIds: string[]): Promise<void> {
130+
const outcomeName = this._outcomeName;
128131
const existingSentOutcome = await db.get('SentUniqueOutcome', outcomeName);
129132
const currentSession = await getCurrentSession();
130133

@@ -141,8 +144,8 @@ export default class OutcomesHelper {
141144
});
142145
}
143146

144-
async wasSentDuringSession() {
145-
const sentOutcome = await db.get('SentUniqueOutcome', this.outcomeName);
147+
async _wasSentDuringSession() {
148+
const sentOutcome = await db.get('SentUniqueOutcome', this._outcomeName);
146149

147150
if (!sentOutcome) {
148151
return false;
@@ -160,45 +163,45 @@ export default class OutcomesHelper {
160163
);
161164
}
162165

163-
async send(outcomeProps: OutcomeProps): Promise<void> {
166+
async _send(outcomeProps: OutcomeProps): Promise<void> {
164167
const { type, notificationIds, weight } = outcomeProps;
165168

166169
switch (type) {
167170
case OutcomeAttributionType.Direct:
168-
if (this.isUnique) {
169-
await this.saveSentUniqueOutcome(notificationIds);
171+
if (this._isUnique) {
172+
await this._saveSentUniqueOutcome(notificationIds);
170173
}
171174
await OneSignal._context._updateManager._sendOutcomeDirect(
172-
this.appId,
175+
this._appId,
173176
notificationIds,
174-
this.outcomeName,
177+
this._outcomeName,
175178
weight,
176179
);
177180
return;
178181
case OutcomeAttributionType.Indirect:
179-
if (this.isUnique) {
180-
await this.saveSentUniqueOutcome(notificationIds);
182+
if (this._isUnique) {
183+
await this._saveSentUniqueOutcome(notificationIds);
181184
}
182185
await OneSignal._context._updateManager._sendOutcomeInfluenced(
183-
this.appId,
186+
this._appId,
184187
notificationIds,
185-
this.outcomeName,
188+
this._outcomeName,
186189
weight,
187190
);
188191
return;
189192
case OutcomeAttributionType.Unattributed:
190-
if (this.isUnique) {
191-
if (await this.wasSentDuringSession()) {
193+
if (this._isUnique) {
194+
if (await this._wasSentDuringSession()) {
192195
Log._warn(
193196
`(Unattributed) unique outcome was already sent during this session`,
194197
);
195198
return;
196199
}
197-
await this.saveSentUniqueOutcome([]);
200+
await this._saveSentUniqueOutcome([]);
198201
}
199202
await OneSignal._context._updateManager._sendOutcomeUnattributed(
200-
this.appId,
201-
this.outcomeName,
203+
this._appId,
204+
this._outcomeName,
202205
weight,
203206
);
204207
return;
@@ -209,8 +212,6 @@ export default class OutcomesHelper {
209212
return;
210213
}
211214
}
212-
213-
// statics
214215
}
215216

216217
/**

0 commit comments

Comments
 (0)