@liveblocks/core 1.1.0-beta2 → 1.1.0-beta3

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.
Files changed (2) hide show
  1. package/dist/index.js +38 -34
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -157,7 +157,7 @@ var onMessageFromPanel = eventSource.observable;
157
157
  // src/devtools/index.ts
158
158
  var VERSION = true ? (
159
159
  /* istanbul ignore next */
160
- "1.1.0-beta2"
160
+ "1.1.0-beta3"
161
161
  ) : "dev";
162
162
  var _devtoolsSetupHasRun = false;
163
163
  function setupDevTools(getAllRooms) {
@@ -4340,10 +4340,10 @@ function createRoom(options, config) {
4340
4340
  )
4341
4341
  };
4342
4342
  context.idFactory = makeIdFactory(sessionInfo.id);
4343
- if (context.root) {
4344
- context.buffer.messages.push({ type: 200 /* FETCH_STORAGE */ });
4343
+ if (_getStorage$ !== null) {
4344
+ refreshStorage({ flush: false });
4345
4345
  }
4346
- tryFlushing();
4346
+ flushNowOrSoon();
4347
4347
  }
4348
4348
  function onDidDisconnect() {
4349
4349
  clearTimeout(context.buffer.flushTimerID);
@@ -4471,7 +4471,7 @@ function createRoom(options, config) {
4471
4471
  if (message.items.length === 0) {
4472
4472
  throw new Error("Internal error: cannot load storage without items");
4473
4473
  }
4474
- if (context.root) {
4474
+ if (context.root !== void 0) {
4475
4475
  updateRoot(message.items, batchedUpdatesWrapper);
4476
4476
  } else {
4477
4477
  context.root = LiveObject._fromItems(message.items, pool);
@@ -4483,7 +4483,7 @@ function createRoom(options, config) {
4483
4483
  }
4484
4484
  }
4485
4485
  function updateRoot(items, batchedUpdatesWrapper) {
4486
- if (!context.root) {
4486
+ if (context.root === void 0) {
4487
4487
  return;
4488
4488
  }
4489
4489
  const currentItems = /* @__PURE__ */ new Map();
@@ -4681,7 +4681,7 @@ function createRoom(options, config) {
4681
4681
  }
4682
4682
  context.activeBatch.updates.presence = true;
4683
4683
  } else {
4684
- tryFlushing();
4684
+ flushNowOrSoon();
4685
4685
  batchUpdates(() => {
4686
4686
  if (options2 == null ? void 0 : options2.addToHistory) {
4687
4687
  addToUndoStack(
@@ -4768,7 +4768,7 @@ function createRoom(options, config) {
4768
4768
  data: context.me.current,
4769
4769
  targetActor: message.actor
4770
4770
  });
4771
- tryFlushing();
4771
+ flushNowOrSoon();
4772
4772
  const user = context.others.getUser(message.actor);
4773
4773
  return user ? { type: "enter", user } : void 0;
4774
4774
  }
@@ -4854,9 +4854,7 @@ function createRoom(options, config) {
4854
4854
  const unacknowledgedOps = new Map(context.unacknowledgedOps);
4855
4855
  createOrUpdateRootFromMessage(message, doNotBatchUpdates);
4856
4856
  applyAndSendOps(unacknowledgedOps, doNotBatchUpdates);
4857
- if (_resolveInitialStatePromise !== null) {
4858
- _resolveInitialStatePromise();
4859
- }
4857
+ _resolveStoragePromise == null ? void 0 : _resolveStoragePromise();
4860
4858
  notifyStorageStatus();
4861
4859
  eventHub.storageDidLoad.notify();
4862
4860
  break;
@@ -4903,7 +4901,7 @@ ${Array.from(traces).join("\n\n")}`
4903
4901
  notify(updates, doNotBatchUpdates);
4904
4902
  });
4905
4903
  }
4906
- function tryFlushing() {
4904
+ function flushNowOrSoon() {
4907
4905
  const storageOps = context.buffer.storageOperations;
4908
4906
  if (storageOps.length > 0) {
4909
4907
  for (const op of storageOps) {
@@ -4933,7 +4931,7 @@ ${Array.from(traces).join("\n\n")}`
4933
4931
  } else {
4934
4932
  clearTimeout(context.buffer.flushTimerID);
4935
4933
  context.buffer.flushTimerID = setTimeout(
4936
- tryFlushing,
4934
+ flushNowOrSoon,
4937
4935
  config.throttleDelay - elapsedMillis
4938
4936
  );
4939
4937
  }
@@ -4976,24 +4974,32 @@ ${Array.from(traces).join("\n\n")}`
4976
4974
  type: 103 /* BROADCAST_EVENT */,
4977
4975
  event
4978
4976
  });
4979
- tryFlushing();
4977
+ flushNowOrSoon();
4980
4978
  }
4981
4979
  function dispatchOps(ops) {
4982
4980
  context.buffer.storageOperations.push(...ops);
4983
- tryFlushing();
4981
+ flushNowOrSoon();
4982
+ }
4983
+ let _getStorage$ = null;
4984
+ let _resolveStoragePromise = null;
4985
+ function refreshStorage(options2) {
4986
+ const messages = context.buffer.messages;
4987
+ if (!messages.some((msg) => msg.type === 200 /* FETCH_STORAGE */)) {
4988
+ messages.push({ type: 200 /* FETCH_STORAGE */ });
4989
+ }
4990
+ if (options2.flush) {
4991
+ flushNowOrSoon();
4992
+ }
4984
4993
  }
4985
- let _getInitialStatePromise = null;
4986
- let _resolveInitialStatePromise = null;
4987
4994
  function startLoadingStorage() {
4988
- if (_getInitialStatePromise === null) {
4989
- context.buffer.messages.push({ type: 200 /* FETCH_STORAGE */ });
4990
- tryFlushing();
4991
- _getInitialStatePromise = new Promise(
4992
- (resolve) => _resolveInitialStatePromise = resolve
4993
- );
4995
+ if (_getStorage$ === null) {
4996
+ refreshStorage({ flush: true });
4997
+ _getStorage$ = new Promise((resolve) => {
4998
+ _resolveStoragePromise = resolve;
4999
+ });
4994
5000
  notifyStorageStatus();
4995
5001
  }
4996
- return _getInitialStatePromise;
5002
+ return _getStorage$;
4997
5003
  }
4998
5004
  function getStorageSnapshot() {
4999
5005
  const root = context.root;
@@ -5006,7 +5012,7 @@ ${Array.from(traces).join("\n\n")}`
5006
5012
  }
5007
5013
  function getStorage() {
5008
5014
  return __async(this, null, function* () {
5009
- if (context.root) {
5015
+ if (context.root !== void 0) {
5010
5016
  return Promise.resolve({
5011
5017
  root: context.root
5012
5018
  });
@@ -5037,7 +5043,7 @@ ${Array.from(traces).join("\n\n")}`
5037
5043
  context.buffer.storageOperations.push(op);
5038
5044
  }
5039
5045
  }
5040
- tryFlushing();
5046
+ flushNowOrSoon();
5041
5047
  }
5042
5048
  function redo() {
5043
5049
  if (context.activeBatch) {
@@ -5059,7 +5065,7 @@ ${Array.from(traces).join("\n\n")}`
5059
5065
  context.buffer.storageOperations.push(op);
5060
5066
  }
5061
5067
  }
5062
- tryFlushing();
5068
+ flushNowOrSoon();
5063
5069
  }
5064
5070
  function batch(callback) {
5065
5071
  if (context.activeBatch) {
@@ -5091,7 +5097,7 @@ ${Array.from(traces).join("\n\n")}`
5091
5097
  dispatchOps(currentBatch.ops);
5092
5098
  }
5093
5099
  notify(currentBatch.updates, doNotBatchUpdates);
5094
- tryFlushing();
5100
+ flushNowOrSoon();
5095
5101
  }
5096
5102
  });
5097
5103
  return returnValue;
@@ -5107,13 +5113,11 @@ ${Array.from(traces).join("\n\n")}`
5107
5113
  }
5108
5114
  }
5109
5115
  function getStorageStatus() {
5110
- if (_getInitialStatePromise === null) {
5111
- return "not-loaded";
5112
- }
5113
5116
  if (context.root === void 0) {
5114
- return "loading";
5117
+ return _getStorage$ === null ? "not-loaded" : "loading";
5118
+ } else {
5119
+ return context.unacknowledgedOps.size === 0 ? "synchronized" : "synchronizing";
5115
5120
  }
5116
- return context.unacknowledgedOps.size === 0 ? "synchronized" : "synchronizing";
5117
5121
  }
5118
5122
  let _lastStorageStatus = getStorageStatus();
5119
5123
  function notifyStorageStatus() {
@@ -5301,7 +5305,7 @@ function makeCreateSocketDelegateForRoom(liveblocksServer, WebSocketPolyfill) {
5301
5305
  // @ts-ignore (__PACKAGE_VERSION__ will be injected by the build script)
5302
5306
  true ? (
5303
5307
  /* istanbul ignore next */
5304
- "1.1.0-beta2"
5308
+ "1.1.0-beta3"
5305
5309
  ) : "dev"}`
5306
5310
  );
5307
5311
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/core",
3
- "version": "1.1.0-beta2",
3
+ "version": "1.1.0-beta3",
4
4
  "description": "Shared code and foundational internals for Liveblocks",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",