Skip to content

Commit a9a8b14

Browse files
committed
QPixel JS API should not use 'this' in arrow function 'methods' - it actually points to globalThis
1 parent ebbc912 commit a9a8b14

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

app/assets/javascripts/qpixel_api.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ window.QPixel = {
9999
},
100100

101101
/**
102-
* @type {QPixelFilter[]|null}
102+
* @type {Record<string, QPixelFilter>|null}
103103
*/
104104
_filters: null,
105105

@@ -203,16 +203,16 @@ window.QPixel = {
203203
},
204204

205205
filters: async () => {
206-
if (this._filters == null) {
206+
if (QPixel._filters == null) {
207207
// If they're still absent after loading from storage, load from the API.
208208
const resp = await QPixel.getJSON('/users/me/filters');
209209
const data = await resp.json();
210210

211211
QPixel.Storage?.set('user_filters', data);
212-
this._filters = data;
212+
QPixel._filters = data;
213213
}
214214

215-
return this._filters;
215+
return QPixel._filters;
216216
},
217217

218218
defaultFilter: async (categoryId) => {
@@ -234,12 +234,12 @@ window.QPixel = {
234234
headers: { 'Accept': 'application/json' }
235235
});
236236

237-
/** @type {QPixelResponseJSON<{ filters: QPixelFilter[] }>} */
237+
/** @type {QPixelResponseJSON<{ filters: Record<string, QPixelFilter> }>} */
238238
const data = await QPixel.parseJSONResponse(resp, 'Failed to save filter');
239239

240240
QPixel.handleJSONResponse(data, (data) => {
241-
this._filters = data.filters;
242-
QPixel.Storage?.set('user_filters', this._filters);
241+
QPixel._filters = data.filters;
242+
QPixel.Storage?.set('user_filters', QPixel._filters);
243243
});
244244
},
245245

@@ -249,12 +249,12 @@ window.QPixel = {
249249
method: 'DELETE'
250250
});
251251

252-
/** @type {QPixelResponseJSON<{ filters: QPixelFilter[] }>} */
252+
/** @type {QPixelResponseJSON<{ filters: Record<string, QPixelFilter> }>} */
253253
const data = await QPixel.parseJSONResponse(resp, 'Failed to delete filter');
254254

255255
QPixel.handleJSONResponse(data, (data) => {
256-
this._filters = data.filters;
257-
QPixel.Storage?.set('user_filters', this._filters);
256+
QPixel._filters = data.filters;
257+
QPixel.Storage?.set('user_filters', QPixel._filters);
258258
});
259259
},
260260

global.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ interface QPixel {
383383
readonly ALLOWED_POST_ATTRS?: readonly string[]
384384

385385
// private properties
386-
_filters?: QPixelFilter[] | null;
386+
_filters?: Record<string, QPixelFilter> | null;
387387
_pendingUser?: Promise<QPixelUser> | null;
388388
_popups?: Record<string, QPixelPopup>;
389389
_preferences?: UserPreferences | null;

0 commit comments

Comments
 (0)