@liveblocks/client
Advanced tools
Comparing version 0.13.0 to 0.13.1
@@ -57,2 +57,7 @@ import { AbstractCrdt, Doc, ApplyResult } from "./AbstractCrdt"; | ||
/** | ||
* Deletes a key from the LiveObject | ||
* @param key The key of the property to delete | ||
*/ | ||
delete(key: keyof T): void; | ||
/** | ||
* Adds or updates multiple properties at once with an object. | ||
@@ -59,0 +64,0 @@ * @param overrides The object used to overrides properties |
@@ -190,2 +190,36 @@ "use strict"; | ||
/** | ||
* Deletes a key from the LiveObject | ||
* @param key The key of the property to delete | ||
*/ | ||
delete(key) { | ||
const keyAsString = key; | ||
const oldValue = __classPrivateFieldGet(this, _LiveObject_map, "f").get(keyAsString); | ||
if (oldValue === undefined) { | ||
return; | ||
} | ||
if (this._doc == null || this._id == null) { | ||
if (oldValue instanceof AbstractCrdt_1.AbstractCrdt) { | ||
oldValue._detach(); | ||
} | ||
__classPrivateFieldGet(this, _LiveObject_map, "f").delete(keyAsString); | ||
return; | ||
} | ||
let reverse; | ||
if (oldValue instanceof AbstractCrdt_1.AbstractCrdt) { | ||
oldValue._detach(); | ||
reverse = oldValue._serialize(this._id, keyAsString); | ||
} | ||
else { | ||
reverse = [ | ||
{ | ||
type: live_1.OpType.UpdateObject, | ||
data: { [keyAsString]: oldValue }, | ||
id: this._id, | ||
}, | ||
]; | ||
} | ||
__classPrivateFieldGet(this, _LiveObject_map, "f").delete(keyAsString); | ||
this._doc.dispatch([{ type: live_1.OpType.DeleteObjectKey, key: keyAsString, id: this._id }], reverse, [this]); | ||
} | ||
/** | ||
* Adds or updates multiple properties at once with an object. | ||
@@ -314,2 +348,6 @@ * @param overrides The object used to overrides properties | ||
const key = op.key; | ||
// If property does not exist, exit without notifying | ||
if (__classPrivateFieldGet(this, _LiveObject_map, "f").has(key) === false) { | ||
return { modified: false }; | ||
} | ||
const oldValue = __classPrivateFieldGet(this, _LiveObject_map, "f").get(key); | ||
@@ -316,0 +354,0 @@ let reverse = []; |
@@ -280,3 +280,3 @@ import type { LiveList } from "./LiveList"; | ||
/** | ||
* Room's history contains function that let you undo and redo operation made on by the current client on the presence and storage. | ||
* Room's history contains functions that let you undo and redo operation made on by the current client on the presence and storage. | ||
*/ | ||
@@ -287,2 +287,8 @@ history: { | ||
* It does not impact operations made by other clients. | ||
* | ||
* @example | ||
* room.updatePresence({ selectedId: "xxx" }, { addToHistory: true }); | ||
* room.updatePresence({ selectedId: "yyy" }, { addToHistory: true }); | ||
* room.history.undo(); | ||
* // room.getPresence() equals { selectedId: "xxx" } | ||
*/ | ||
@@ -293,2 +299,10 @@ undo: () => void; | ||
* It does not impact operations made by other clients. | ||
* | ||
* @example | ||
* room.updatePresence({ selectedId: "xxx" }, { addToHistory: true }); | ||
* room.updatePresence({ selectedId: "yyy" }, { addToHistory: true }); | ||
* room.history.undo(); | ||
* // room.getPresence() equals { selectedId: "xxx" } | ||
* room.history.redo(); | ||
* // room.getPresence() equals { selectedId: "yyy" } | ||
*/ | ||
@@ -298,2 +312,11 @@ redo: () => void; | ||
* All future modifications made on the Room will be merged together to create a single history item until resume is called. | ||
* | ||
* @example | ||
* room.updatePresence({ cursor: { x: 0, y: 0 } }, { addToHistory: true }); | ||
* room.history.pause(); | ||
* room.updatePresence({ cursor: { x: 1, y: 1 } }, { addToHistory: true }); | ||
* room.updatePresence({ cursor: { x: 2, y: 2 } }, { addToHistory: true }); | ||
* room.history.resume(); | ||
* room.history.undo(); | ||
* // room.getPresence() equals { cursor: { x: 0, y: 0 } } | ||
*/ | ||
@@ -303,2 +326,11 @@ pause: () => void; | ||
* Resumes history. Modifications made on the Room are not merged into a single history item anymore. | ||
* | ||
* @example | ||
* room.updatePresence({ cursor: { x: 0, y: 0 } }, { addToHistory: true }); | ||
* room.history.pause(); | ||
* room.updatePresence({ cursor: { x: 1, y: 1 } }, { addToHistory: true }); | ||
* room.updatePresence({ cursor: { x: 2, y: 2 } }, { addToHistory: true }); | ||
* room.history.resume(); | ||
* room.history.undo(); | ||
* // room.getPresence() equals { cursor: { x: 0, y: 0 } } | ||
*/ | ||
@@ -400,2 +432,9 @@ resume: () => void; | ||
broadcastEvent: (event: any) => void; | ||
/** | ||
* Get the room's storage asynchronously. | ||
* The storage's root is a {@link LiveObject}. | ||
* | ||
* @example | ||
* const { root } = await room.getStorage(); | ||
*/ | ||
getStorage: <TRoot>() => Promise<{ | ||
@@ -409,2 +448,9 @@ root: LiveObject<TRoot>; | ||
* All the modifications are merged in a single history item (undo/redo). | ||
* | ||
* @example | ||
* const { root } = await room.getStorage(); | ||
* room.batch(() => { | ||
* root.set("x", 0); | ||
* room.updatePresence({ cursor: { x: 100, y: 100 }}); | ||
* }); | ||
*/ | ||
@@ -411,0 +457,0 @@ batch: (fn: () => void) => void; |
@@ -57,2 +57,7 @@ import { AbstractCrdt, Doc, ApplyResult } from "./AbstractCrdt"; | ||
/** | ||
* Deletes a key from the LiveObject | ||
* @param key The key of the property to delete | ||
*/ | ||
delete(key: keyof T): void; | ||
/** | ||
* Adds or updates multiple properties at once with an object. | ||
@@ -59,0 +64,0 @@ * @param overrides The object used to overrides properties |
@@ -187,2 +187,36 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
/** | ||
* Deletes a key from the LiveObject | ||
* @param key The key of the property to delete | ||
*/ | ||
delete(key) { | ||
const keyAsString = key; | ||
const oldValue = __classPrivateFieldGet(this, _LiveObject_map, "f").get(keyAsString); | ||
if (oldValue === undefined) { | ||
return; | ||
} | ||
if (this._doc == null || this._id == null) { | ||
if (oldValue instanceof AbstractCrdt) { | ||
oldValue._detach(); | ||
} | ||
__classPrivateFieldGet(this, _LiveObject_map, "f").delete(keyAsString); | ||
return; | ||
} | ||
let reverse; | ||
if (oldValue instanceof AbstractCrdt) { | ||
oldValue._detach(); | ||
reverse = oldValue._serialize(this._id, keyAsString); | ||
} | ||
else { | ||
reverse = [ | ||
{ | ||
type: OpType.UpdateObject, | ||
data: { [keyAsString]: oldValue }, | ||
id: this._id, | ||
}, | ||
]; | ||
} | ||
__classPrivateFieldGet(this, _LiveObject_map, "f").delete(keyAsString); | ||
this._doc.dispatch([{ type: OpType.DeleteObjectKey, key: keyAsString, id: this._id }], reverse, [this]); | ||
} | ||
/** | ||
* Adds or updates multiple properties at once with an object. | ||
@@ -310,2 +344,6 @@ * @param overrides The object used to overrides properties | ||
const key = op.key; | ||
// If property does not exist, exit without notifying | ||
if (__classPrivateFieldGet(this, _LiveObject_map, "f").has(key) === false) { | ||
return { modified: false }; | ||
} | ||
const oldValue = __classPrivateFieldGet(this, _LiveObject_map, "f").get(key); | ||
@@ -312,0 +350,0 @@ let reverse = []; |
@@ -280,3 +280,3 @@ import type { LiveList } from "./LiveList"; | ||
/** | ||
* Room's history contains function that let you undo and redo operation made on by the current client on the presence and storage. | ||
* Room's history contains functions that let you undo and redo operation made on by the current client on the presence and storage. | ||
*/ | ||
@@ -287,2 +287,8 @@ history: { | ||
* It does not impact operations made by other clients. | ||
* | ||
* @example | ||
* room.updatePresence({ selectedId: "xxx" }, { addToHistory: true }); | ||
* room.updatePresence({ selectedId: "yyy" }, { addToHistory: true }); | ||
* room.history.undo(); | ||
* // room.getPresence() equals { selectedId: "xxx" } | ||
*/ | ||
@@ -293,2 +299,10 @@ undo: () => void; | ||
* It does not impact operations made by other clients. | ||
* | ||
* @example | ||
* room.updatePresence({ selectedId: "xxx" }, { addToHistory: true }); | ||
* room.updatePresence({ selectedId: "yyy" }, { addToHistory: true }); | ||
* room.history.undo(); | ||
* // room.getPresence() equals { selectedId: "xxx" } | ||
* room.history.redo(); | ||
* // room.getPresence() equals { selectedId: "yyy" } | ||
*/ | ||
@@ -298,2 +312,11 @@ redo: () => void; | ||
* All future modifications made on the Room will be merged together to create a single history item until resume is called. | ||
* | ||
* @example | ||
* room.updatePresence({ cursor: { x: 0, y: 0 } }, { addToHistory: true }); | ||
* room.history.pause(); | ||
* room.updatePresence({ cursor: { x: 1, y: 1 } }, { addToHistory: true }); | ||
* room.updatePresence({ cursor: { x: 2, y: 2 } }, { addToHistory: true }); | ||
* room.history.resume(); | ||
* room.history.undo(); | ||
* // room.getPresence() equals { cursor: { x: 0, y: 0 } } | ||
*/ | ||
@@ -303,2 +326,11 @@ pause: () => void; | ||
* Resumes history. Modifications made on the Room are not merged into a single history item anymore. | ||
* | ||
* @example | ||
* room.updatePresence({ cursor: { x: 0, y: 0 } }, { addToHistory: true }); | ||
* room.history.pause(); | ||
* room.updatePresence({ cursor: { x: 1, y: 1 } }, { addToHistory: true }); | ||
* room.updatePresence({ cursor: { x: 2, y: 2 } }, { addToHistory: true }); | ||
* room.history.resume(); | ||
* room.history.undo(); | ||
* // room.getPresence() equals { cursor: { x: 0, y: 0 } } | ||
*/ | ||
@@ -400,2 +432,9 @@ resume: () => void; | ||
broadcastEvent: (event: any) => void; | ||
/** | ||
* Get the room's storage asynchronously. | ||
* The storage's root is a {@link LiveObject}. | ||
* | ||
* @example | ||
* const { root } = await room.getStorage(); | ||
*/ | ||
getStorage: <TRoot>() => Promise<{ | ||
@@ -409,2 +448,9 @@ root: LiveObject<TRoot>; | ||
* All the modifications are merged in a single history item (undo/redo). | ||
* | ||
* @example | ||
* const { root } = await room.getStorage(); | ||
* room.batch(() => { | ||
* root.set("x", 0); | ||
* room.updatePresence({ cursor: { x: 100, y: 100 }}); | ||
* }); | ||
*/ | ||
@@ -411,0 +457,0 @@ batch: (fn: () => void) => void; |
{ | ||
"name": "@liveblocks/client", | ||
"version": "0.13.0", | ||
"version": "0.13.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./lib/cjs/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
281724
7501