pxt-core 7.3.10 → 7.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/built/pxt.js CHANGED
@@ -97876,14 +97876,15 @@ var pxt;
97876
97876
  let _client;
97877
97877
  function client() { return _client; }
97878
97878
  auth.client = client;
97879
- const PREFERENCES_DEBOUNCE_MS = 5 * 1000;
97880
- const PREFERENCES_DEBOUNCE_MAX_MS = 30 * 1000;
97879
+ const PREFERENCES_DEBOUNCE_MS = 1 * 1000;
97880
+ const PREFERENCES_DEBOUNCE_MAX_MS = 10 * 1000;
97881
97881
  let debouncePreferencesChangedTimeout = 0;
97882
97882
  let debouncePreferencesChangedStarted = 0;
97883
97883
  class AuthClient {
97884
97884
  constructor() {
97885
97885
  this.initialUserPreferences_ = undefined;
97886
97886
  this.initialAuthCheck_ = undefined;
97887
+ this.prefPatchOps = [];
97887
97888
  pxt.Util.assert(!_client);
97888
97889
  // Set global instance.
97889
97890
  _client = this;
@@ -98073,7 +98074,7 @@ var pxt;
98073
98074
  }
98074
98075
  return result.success;
98075
98076
  }
98076
- async patchUserPreferencesAsync(ops) {
98077
+ async patchUserPreferencesAsync(ops, immediate = false) {
98077
98078
  ops = Array.isArray(ops) ? ops : [ops];
98078
98079
  if (!ops.length) {
98079
98080
  return;
@@ -98086,10 +98087,15 @@ var pxt;
98086
98087
  return;
98087
98088
  }
98088
98089
  // If the user is logged in, save to cloud, but debounce the api call as this can be called frequently from skillmaps
98090
+ // Accumulate the ops and send to cloud in batch.
98091
+ this.prefPatchOps.push(...ops);
98089
98092
  clearTimeout(debouncePreferencesChangedTimeout);
98090
98093
  const savePrefs = async () => {
98091
98094
  debouncePreferencesChangedStarted = 0;
98092
- const result = await this.apiAsync('/api/user/preferences', ops, 'PATCH');
98095
+ // Clear queued patch ops before send.
98096
+ const prefPatchOps = this.prefPatchOps;
98097
+ this.prefPatchOps = [];
98098
+ const result = await this.apiAsync('/api/user/preferences', prefPatchOps, 'PATCH');
98093
98099
  if (result.success) {
98094
98100
  pxt.debug("Updating local user preferences w/ cloud data after result of POST");
98095
98101
  // Set user profile from returned value so we stay in-sync
@@ -98099,14 +98105,19 @@ var pxt;
98099
98105
  pxt.reportError("identity", "update preferences failed", result);
98100
98106
  }
98101
98107
  };
98102
- if (!debouncePreferencesChangedStarted) {
98103
- debouncePreferencesChangedStarted = pxt.U.now();
98104
- }
98105
- if (PREFERENCES_DEBOUNCE_MAX_MS < pxt.U.now() - debouncePreferencesChangedStarted) {
98108
+ if (immediate) {
98106
98109
  await savePrefs();
98107
98110
  }
98108
98111
  else {
98109
- debouncePreferencesChangedTimeout = setTimeout(savePrefs, PREFERENCES_DEBOUNCE_MS);
98112
+ if (!debouncePreferencesChangedStarted) {
98113
+ debouncePreferencesChangedStarted = pxt.U.now();
98114
+ }
98115
+ if (PREFERENCES_DEBOUNCE_MAX_MS < pxt.U.now() - debouncePreferencesChangedStarted) {
98116
+ await savePrefs();
98117
+ }
98118
+ else {
98119
+ debouncePreferencesChangedTimeout = setTimeout(savePrefs, PREFERENCES_DEBOUNCE_MS);
98120
+ }
98110
98121
  }
98111
98122
  }
98112
98123
  /*protected*/ hasUserId() {
@@ -543,7 +543,7 @@ declare namespace pxt.editor {
543
543
  message?: string;
544
544
  data?: Map<string | number>;
545
545
  }
546
- type EditorMessageTutorialEventRequest = EditorMessageTutorialProgressEventRequest | EditorMessageTutorialCompletedEventRequest | EditorMessageTutorialLoadedEventRequest;
546
+ type EditorMessageTutorialEventRequest = EditorMessageTutorialProgressEventRequest | EditorMessageTutorialCompletedEventRequest | EditorMessageTutorialLoadedEventRequest | EditorMessageTutorialExitEventRequest;
547
547
  interface EditorMessageTutorialProgressEventRequest extends EditorMessageRequest {
548
548
  action: "tutorialevent";
549
549
  tutorialEvent: "progress";
package/built/pxtlib.d.ts CHANGED
@@ -124,7 +124,8 @@ declare namespace pxt.auth {
124
124
  username?: string;
125
125
  avatarUrl?: string;
126
126
  }): Promise<boolean>;
127
- patchUserPreferencesAsync(ops: ts.pxtc.jsonPatch.PatchOperation | ts.pxtc.jsonPatch.PatchOperation[]): Promise<void>;
127
+ private prefPatchOps;
128
+ patchUserPreferencesAsync(ops: ts.pxtc.jsonPatch.PatchOperation | ts.pxtc.jsonPatch.PatchOperation[], immediate?: boolean): Promise<void>;
128
129
  hasUserId(): boolean;
129
130
  private fetchUserAsync;
130
131
  private setUserProfileAsync;
package/built/pxtlib.js CHANGED
@@ -190,14 +190,15 @@ var pxt;
190
190
  let _client;
191
191
  function client() { return _client; }
192
192
  auth.client = client;
193
- const PREFERENCES_DEBOUNCE_MS = 5 * 1000;
194
- const PREFERENCES_DEBOUNCE_MAX_MS = 30 * 1000;
193
+ const PREFERENCES_DEBOUNCE_MS = 1 * 1000;
194
+ const PREFERENCES_DEBOUNCE_MAX_MS = 10 * 1000;
195
195
  let debouncePreferencesChangedTimeout = 0;
196
196
  let debouncePreferencesChangedStarted = 0;
197
197
  class AuthClient {
198
198
  constructor() {
199
199
  this.initialUserPreferences_ = undefined;
200
200
  this.initialAuthCheck_ = undefined;
201
+ this.prefPatchOps = [];
201
202
  pxt.Util.assert(!_client);
202
203
  // Set global instance.
203
204
  _client = this;
@@ -387,7 +388,7 @@ var pxt;
387
388
  }
388
389
  return result.success;
389
390
  }
390
- async patchUserPreferencesAsync(ops) {
391
+ async patchUserPreferencesAsync(ops, immediate = false) {
391
392
  ops = Array.isArray(ops) ? ops : [ops];
392
393
  if (!ops.length) {
393
394
  return;
@@ -400,10 +401,15 @@ var pxt;
400
401
  return;
401
402
  }
402
403
  // If the user is logged in, save to cloud, but debounce the api call as this can be called frequently from skillmaps
404
+ // Accumulate the ops and send to cloud in batch.
405
+ this.prefPatchOps.push(...ops);
403
406
  clearTimeout(debouncePreferencesChangedTimeout);
404
407
  const savePrefs = async () => {
405
408
  debouncePreferencesChangedStarted = 0;
406
- const result = await this.apiAsync('/api/user/preferences', ops, 'PATCH');
409
+ // Clear queued patch ops before send.
410
+ const prefPatchOps = this.prefPatchOps;
411
+ this.prefPatchOps = [];
412
+ const result = await this.apiAsync('/api/user/preferences', prefPatchOps, 'PATCH');
407
413
  if (result.success) {
408
414
  pxt.debug("Updating local user preferences w/ cloud data after result of POST");
409
415
  // Set user profile from returned value so we stay in-sync
@@ -413,14 +419,19 @@ var pxt;
413
419
  pxt.reportError("identity", "update preferences failed", result);
414
420
  }
415
421
  };
416
- if (!debouncePreferencesChangedStarted) {
417
- debouncePreferencesChangedStarted = pxt.U.now();
418
- }
419
- if (PREFERENCES_DEBOUNCE_MAX_MS < pxt.U.now() - debouncePreferencesChangedStarted) {
422
+ if (immediate) {
420
423
  await savePrefs();
421
424
  }
422
425
  else {
423
- debouncePreferencesChangedTimeout = setTimeout(savePrefs, PREFERENCES_DEBOUNCE_MS);
426
+ if (!debouncePreferencesChangedStarted) {
427
+ debouncePreferencesChangedStarted = pxt.U.now();
428
+ }
429
+ if (PREFERENCES_DEBOUNCE_MAX_MS < pxt.U.now() - debouncePreferencesChangedStarted) {
430
+ await savePrefs();
431
+ }
432
+ else {
433
+ debouncePreferencesChangedTimeout = setTimeout(savePrefs, PREFERENCES_DEBOUNCE_MS);
434
+ }
424
435
  }
425
436
  }
426
437
  /*protected*/ hasUserId() {