@liveblocks/redux
Advanced tools
Comparing version 0.15.0-alpha.3 to 0.15.0-alpha.4
@@ -1,2 +0,2 @@ | ||
import { patchLiveObjectKey, liveNodeToJson, patchImmutableObject } from '@liveblocks/client'; | ||
import { internals } from '@liveblocks/client'; | ||
@@ -42,2 +42,3 @@ const ERROR_PREFIX = "Invalid @liveblocks/redux middleware config."; | ||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
const { patchImmutableObject, patchLiveObjectKey, liveNodeToJson } = internals; | ||
const ACTION_TYPES = { | ||
@@ -52,3 +53,3 @@ ENTER: "@@LIVEBLOCKS/ENTER", | ||
}; | ||
const internalPlugin = (options) => { | ||
const internalEnhancer = (options) => { | ||
if (process.env.NODE_ENV !== "production" && options.client == null) { | ||
@@ -197,2 +198,6 @@ throw missingClient(); | ||
}; | ||
const actions = { | ||
enterRoom, | ||
leaveRoom | ||
}; | ||
function enterRoom(roomId, initialState) { | ||
@@ -211,3 +216,3 @@ return { | ||
} | ||
const enhancer = internalPlugin; | ||
const enhancer = internalEnhancer; | ||
function patchLiveblocksStorage(root, oldState, newState, mapping) { | ||
@@ -281,2 +286,2 @@ for (const key in mapping) { | ||
export { enhancer, enterRoom, leaveRoom }; | ||
export { actions, enhancer }; |
@@ -8,3 +8,3 @@ import { Client, User } from "@liveblocks/client"; | ||
/** | ||
* Liveblocks extra state attached by the middleware | ||
* Liveblocks extra state attached by the enhancer | ||
*/ | ||
@@ -26,3 +26,19 @@ readonly liveblocks: { | ||
}; | ||
export declare function enterRoom(roomId: string, initialState?: any): { | ||
/** | ||
* Actions used to interact with Liveblocks | ||
*/ | ||
export declare const actions: { | ||
/** | ||
* Enters a room and starts sync it with zustand state | ||
* @param roomId The id of the room | ||
* @param initialState The initial state of the room storage. If a key does not exist if your room storage root, initialState[key] will be used. | ||
*/ | ||
enterRoom: typeof enterRoom; | ||
/** | ||
* Leaves a room and stops sync it with zustand state. | ||
* @param roomId The id of the room | ||
*/ | ||
leaveRoom: typeof leaveRoom; | ||
}; | ||
declare function enterRoom(roomId: string, initialState?: any): { | ||
type: string; | ||
@@ -32,3 +48,3 @@ roomId: string; | ||
}; | ||
export declare function leaveRoom(roomId: string): { | ||
declare function leaveRoom(roomId: string): { | ||
type: string; | ||
@@ -42,1 +58,2 @@ roomId: string; | ||
}) => StoreEnhancer; | ||
export {}; |
@@ -83,2 +83,5 @@ 'use strict'; | ||
var patchImmutableObject = client.internals.patchImmutableObject, | ||
patchLiveObjectKey = client.internals.patchLiveObjectKey, | ||
liveNodeToJson = client.internals.liveNodeToJson; | ||
var ACTION_TYPES = { | ||
@@ -94,3 +97,3 @@ ENTER: "@@LIVEBLOCKS/ENTER", | ||
var internalPlugin = function internalPlugin(options) { | ||
var internalEnhancer = function internalEnhancer(options) { | ||
if (process.env.NODE_ENV !== "production" && options.client == null) { | ||
@@ -100,3 +103,3 @@ throw missingClient(); | ||
var client$1 = options.client; | ||
var client = options.client; | ||
var mapping = validateMapping(options.storageMapping, "storageMapping"); | ||
@@ -194,3 +197,3 @@ var presenceMapping = validateMapping(options.presenceMapping || {}, "presenceMapping"); | ||
room = client$1.enter(roomId); | ||
room = client.enter(roomId); | ||
broadcastInitialPresence(room, reduxState, presenceMapping); | ||
@@ -216,10 +219,10 @@ unsubscribeCallbacks.push(room.subscribe("connection", function () { | ||
room.batch(function () { | ||
for (var key in mapping) { | ||
var liveblocksStatePart = root.get(key); | ||
for (var _key in mapping) { | ||
var liveblocksStatePart = root.get(_key); | ||
if (liveblocksStatePart == null) { | ||
updates[key] = storageInitialState[key]; | ||
client.patchLiveObjectKey(root, key, undefined, storageInitialState[key]); | ||
updates[_key] = storageInitialState[_key]; | ||
patchLiveObjectKey(root, _key, undefined, storageInitialState[_key]); | ||
} else { | ||
updates[key] = client.liveNodeToJson(liveblocksStatePart); | ||
updates[_key] = liveNodeToJson(liveblocksStatePart); | ||
} | ||
@@ -256,3 +259,3 @@ } | ||
unsubscribeCallbacks = []; | ||
client$1.leave(roomId); | ||
client.leave(roomId); | ||
} | ||
@@ -277,2 +280,7 @@ | ||
var actions = { | ||
enterRoom: enterRoom, | ||
leaveRoom: leaveRoom | ||
}; | ||
function enterRoom(roomId, initialState) { | ||
@@ -285,2 +293,3 @@ return { | ||
} | ||
function leaveRoom(roomId) { | ||
@@ -292,12 +301,13 @@ return { | ||
} | ||
var enhancer = internalPlugin; | ||
var enhancer = internalEnhancer; | ||
function patchLiveblocksStorage(root, oldState, newState, mapping) { | ||
for (var key in mapping) { | ||
if (process.env.NODE_ENV !== "production" && typeof newState[key] === "function") { | ||
for (var _key2 in mapping) { | ||
if (process.env.NODE_ENV !== "production" && typeof newState[_key2] === "function") { | ||
throw mappingToFunctionIsNotAllowed("value"); | ||
} | ||
if (oldState[key] !== newState[key]) { | ||
client.patchLiveObjectKey(root, key, oldState[key], newState[key]); | ||
if (oldState[_key2] !== newState[_key2]) { | ||
patchLiveObjectKey(root, _key2, oldState[_key2], newState[_key2]); | ||
} | ||
@@ -308,6 +318,6 @@ } | ||
function broadcastInitialPresence(room, state, mapping) { | ||
for (var key in mapping) { | ||
for (var _key3 in mapping) { | ||
var _room$updatePresence; | ||
room == null ? void 0 : room.updatePresence((_room$updatePresence = {}, _room$updatePresence[key] = state[key], _room$updatePresence)); | ||
room == null ? void 0 : room.updatePresence((_room$updatePresence = {}, _room$updatePresence[_key3] = state[_key3], _room$updatePresence)); | ||
} | ||
@@ -317,11 +327,11 @@ } | ||
function updatePresence(room, oldState, newState, presenceMapping) { | ||
for (var key in presenceMapping) { | ||
if (typeof newState[key] === "function") { | ||
for (var _key4 in presenceMapping) { | ||
if (typeof newState[_key4] === "function") { | ||
throw mappingToFunctionIsNotAllowed("value"); | ||
} | ||
if (oldState[key] !== newState[key]) { | ||
if (oldState[_key4] !== newState[_key4]) { | ||
var _room$updatePresence2; | ||
room.updatePresence((_room$updatePresence2 = {}, _room$updatePresence2[key] = newState[key], _room$updatePresence2)); | ||
room.updatePresence((_room$updatePresence2 = {}, _room$updatePresence2[_key4] = newState[_key4], _room$updatePresence2)); | ||
} | ||
@@ -336,5 +346,5 @@ } | ||
function validateNoDuplicateKeys(storageMapping, presenceMapping) { | ||
for (var key in storageMapping) { | ||
if (presenceMapping[key] !== undefined) { | ||
throw mappingShouldNotHaveTheSameKeys(key); | ||
for (var _key5 in storageMapping) { | ||
if (presenceMapping[_key5] !== undefined) { | ||
throw mappingShouldNotHaveTheSameKeys(_key5); | ||
} | ||
@@ -347,11 +357,11 @@ } | ||
for (var key in mapping) { | ||
partialState[key] = state[key]; | ||
for (var _key6 in mapping) { | ||
partialState[_key6] = state[_key6]; | ||
} | ||
var patched = client.patchImmutableObject(partialState, updates); | ||
var patched = patchImmutableObject(partialState, updates); | ||
var result = {}; | ||
for (var _key in mapping) { | ||
result[_key] = patched[_key]; | ||
for (var _key7 in mapping) { | ||
result[_key7] = patched[_key7]; | ||
} | ||
@@ -375,9 +385,9 @@ | ||
for (var key in mapping) { | ||
if (process.env.NODE_ENV !== "production" && typeof mapping[key] !== "boolean") { | ||
throw mappingValueShouldBeABoolean(mappingType, key); | ||
for (var _key8 in mapping) { | ||
if (process.env.NODE_ENV !== "production" && typeof mapping[_key8] !== "boolean") { | ||
throw mappingValueShouldBeABoolean(mappingType, _key8); | ||
} | ||
if (mapping[key] === true) { | ||
result[key] = true; | ||
if (mapping[_key8] === true) { | ||
result[_key8] = true; | ||
} | ||
@@ -389,4 +399,3 @@ } | ||
exports.actions = actions; | ||
exports.enhancer = enhancer; | ||
exports.enterRoom = enterRoom; | ||
exports.leaveRoom = leaveRoom; |
{ | ||
"name": "@liveblocks/redux", | ||
"version": "0.15.0-alpha.3", | ||
"version": "0.15.0-alpha.4", | ||
"sideEffects": false, | ||
@@ -39,3 +39,3 @@ "description": "", | ||
"peerDependencies": { | ||
"@liveblocks/client": "0.15.0-alpha.3", | ||
"@liveblocks/client": "0.15.0-alpha.4", | ||
"redux": "^4" | ||
@@ -56,2 +56,3 @@ }, | ||
"@types/jest": "^27.4.1", | ||
"@types/regenerator-runtime": "^0.13.1", | ||
"esbuild": "0.14.11", | ||
@@ -65,2 +66,2 @@ "jest": "^27.4.7", | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
34198
937
20
1