@liveblocks/redux 0.19.0-beta0 → 0.19.1-test1
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/dist/index.d.ts +7 -7
- package/dist/index.js +153 -154
- package/package.json +7 -7
- package/dist/index.mjs +0 -6
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ declare type LiveblocksContext<TPresence extends JsonObject, TUserMeta extends B
|
|
|
8
8
|
/**
|
|
9
9
|
* Other users in the room. Empty no room is currently synced
|
|
10
10
|
*/
|
|
11
|
-
readonly others:
|
|
11
|
+
readonly others: readonly User<TPresence, TUserMeta>[];
|
|
12
12
|
/**
|
|
13
13
|
* Whether or not the room storage is currently loading
|
|
14
14
|
*/
|
|
@@ -55,18 +55,18 @@ declare function leaveRoom(roomId: string): {
|
|
|
55
55
|
* Redux store enhancer that will make the `liveblocks` key available on your
|
|
56
56
|
* Redux store.
|
|
57
57
|
*/
|
|
58
|
-
declare const liveblocksEnhancer: <
|
|
58
|
+
declare const liveblocksEnhancer: <TState>(options: {
|
|
59
59
|
client: Client;
|
|
60
|
-
storageMapping?: Mapping<
|
|
61
|
-
presenceMapping?: Mapping<
|
|
60
|
+
storageMapping?: Mapping<TState> | undefined;
|
|
61
|
+
presenceMapping?: Mapping<TState> | undefined;
|
|
62
62
|
}) => StoreEnhancer;
|
|
63
63
|
/**
|
|
64
64
|
* @deprecated Renamed to `liveblocksEnhancer`.
|
|
65
65
|
*/
|
|
66
|
-
declare const enhancer: <
|
|
66
|
+
declare const enhancer: <TState>(options: {
|
|
67
67
|
client: Client;
|
|
68
|
-
storageMapping?: Mapping<
|
|
69
|
-
presenceMapping?: Mapping<
|
|
68
|
+
storageMapping?: Mapping<TState> | undefined;
|
|
69
|
+
presenceMapping?: Mapping<TState> | undefined;
|
|
70
70
|
}) => StoreEnhancer;
|
|
71
71
|
|
|
72
72
|
export { LiveblocksState, Mapping, WithLiveblocks, actions, enhancer, liveblocksEnhancer };
|
package/dist/index.js
CHANGED
|
@@ -77,173 +77,172 @@ var internalEnhancer = (options) => {
|
|
|
77
77
|
if (process.env.NODE_ENV !== "production") {
|
|
78
78
|
validateNoDuplicateKeys(mapping, presenceMapping);
|
|
79
79
|
}
|
|
80
|
-
return (createStore) =>
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
case ACTION_TYPES.UPDATE_OTHERS: {
|
|
109
|
-
return __spreadProps(__spreadValues({}, state), {
|
|
110
|
-
liveblocks: __spreadProps(__spreadValues({}, state.liveblocks), {
|
|
111
|
-
others: action.others
|
|
112
|
-
})
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
default: {
|
|
116
|
-
const newState = reducer(state, action);
|
|
117
|
-
if (room) {
|
|
118
|
-
isPatching = true;
|
|
119
|
-
updatePresence(room, state, newState, presenceMapping);
|
|
120
|
-
room.batch(() => {
|
|
121
|
-
if (storageRoot) {
|
|
122
|
-
patchLiveblocksStorage(
|
|
123
|
-
storageRoot,
|
|
124
|
-
state,
|
|
125
|
-
newState,
|
|
126
|
-
mapping
|
|
127
|
-
);
|
|
128
|
-
}
|
|
80
|
+
return (createStore) => {
|
|
81
|
+
return (reducer, initialState, enhancer2) => {
|
|
82
|
+
let room = null;
|
|
83
|
+
let isPatching = false;
|
|
84
|
+
let storageRoot = null;
|
|
85
|
+
let unsubscribeCallbacks = [];
|
|
86
|
+
const newReducer = (state, action) => {
|
|
87
|
+
switch (action.type) {
|
|
88
|
+
case ACTION_TYPES.PATCH_REDUX_STATE:
|
|
89
|
+
return __spreadValues(__spreadValues({}, state), action.state);
|
|
90
|
+
case ACTION_TYPES.INIT_STORAGE:
|
|
91
|
+
return __spreadProps(__spreadValues(__spreadValues({}, state), action.state), {
|
|
92
|
+
liveblocks: __spreadProps(__spreadValues({}, state.liveblocks), {
|
|
93
|
+
isStorageLoading: false
|
|
94
|
+
})
|
|
95
|
+
});
|
|
96
|
+
case ACTION_TYPES.START_LOADING_STORAGE:
|
|
97
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
98
|
+
liveblocks: __spreadProps(__spreadValues({}, state.liveblocks), {
|
|
99
|
+
isStorageLoading: true
|
|
100
|
+
})
|
|
101
|
+
});
|
|
102
|
+
case ACTION_TYPES.UPDATE_CONNECTION: {
|
|
103
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
104
|
+
liveblocks: __spreadProps(__spreadValues({}, state.liveblocks), {
|
|
105
|
+
connection: action.connection
|
|
106
|
+
})
|
|
129
107
|
});
|
|
130
|
-
isPatching = false;
|
|
131
108
|
}
|
|
132
|
-
|
|
133
|
-
return __spreadProps(__spreadValues({},
|
|
134
|
-
liveblocks: {
|
|
135
|
-
others:
|
|
136
|
-
|
|
137
|
-
connection: "closed"
|
|
138
|
-
}
|
|
109
|
+
case ACTION_TYPES.UPDATE_OTHERS: {
|
|
110
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
111
|
+
liveblocks: __spreadProps(__spreadValues({}, state.liveblocks), {
|
|
112
|
+
others: action.others
|
|
113
|
+
})
|
|
139
114
|
});
|
|
140
115
|
}
|
|
141
|
-
|
|
116
|
+
default: {
|
|
117
|
+
const newState = reducer(state, action);
|
|
118
|
+
if (room) {
|
|
119
|
+
isPatching = true;
|
|
120
|
+
updatePresence(room, state, newState, presenceMapping);
|
|
121
|
+
room.batch(() => {
|
|
122
|
+
if (storageRoot) {
|
|
123
|
+
patchLiveblocksStorage(
|
|
124
|
+
storageRoot,
|
|
125
|
+
state,
|
|
126
|
+
newState,
|
|
127
|
+
mapping
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
isPatching = false;
|
|
132
|
+
}
|
|
133
|
+
if (newState.liveblocks == null) {
|
|
134
|
+
return __spreadProps(__spreadValues({}, newState), {
|
|
135
|
+
liveblocks: {
|
|
136
|
+
others: [],
|
|
137
|
+
isStorageLoading: false,
|
|
138
|
+
connection: "closed"
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return newState;
|
|
143
|
+
}
|
|
142
144
|
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
room.events.connection.subscribe(() => {
|
|
157
|
-
store.dispatch({
|
|
158
|
-
type: ACTION_TYPES.UPDATE_CONNECTION,
|
|
159
|
-
connection: room.getConnectionState()
|
|
160
|
-
});
|
|
161
|
-
})
|
|
162
|
-
);
|
|
163
|
-
unsubscribeCallbacks.push(
|
|
164
|
-
room.events.others.subscribe(({ others }) => {
|
|
165
|
-
store.dispatch({
|
|
166
|
-
type: ACTION_TYPES.UPDATE_OTHERS,
|
|
167
|
-
others: others.toArray()
|
|
168
|
-
});
|
|
169
|
-
})
|
|
170
|
-
);
|
|
171
|
-
unsubscribeCallbacks.push(
|
|
172
|
-
room.events.me.subscribe(() => {
|
|
173
|
-
if (isPatching === false) {
|
|
145
|
+
};
|
|
146
|
+
const store = createStore(newReducer, initialState, enhancer2);
|
|
147
|
+
function enterRoom2(roomId) {
|
|
148
|
+
if (storageRoot) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const initialPresence = selectFields(
|
|
152
|
+
store.getState(),
|
|
153
|
+
presenceMapping
|
|
154
|
+
);
|
|
155
|
+
room = client.enter(roomId, { initialPresence });
|
|
156
|
+
unsubscribeCallbacks.push(
|
|
157
|
+
room.events.connection.subscribe(() => {
|
|
174
158
|
store.dispatch({
|
|
175
|
-
type: ACTION_TYPES.
|
|
176
|
-
|
|
177
|
-
room.getPresence(),
|
|
178
|
-
presenceMapping
|
|
179
|
-
)
|
|
159
|
+
type: ACTION_TYPES.UPDATE_CONNECTION,
|
|
160
|
+
connection: room.getConnectionState()
|
|
180
161
|
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
162
|
+
})
|
|
163
|
+
);
|
|
164
|
+
unsubscribeCallbacks.push(
|
|
165
|
+
room.events.others.subscribe(({ others }) => {
|
|
166
|
+
store.dispatch({
|
|
167
|
+
type: ACTION_TYPES.UPDATE_OTHERS,
|
|
168
|
+
others
|
|
169
|
+
});
|
|
170
|
+
})
|
|
171
|
+
);
|
|
172
|
+
unsubscribeCallbacks.push(
|
|
173
|
+
room.events.me.subscribe(() => {
|
|
174
|
+
if (isPatching === false) {
|
|
175
|
+
store.dispatch({
|
|
176
|
+
type: ACTION_TYPES.PATCH_REDUX_STATE,
|
|
177
|
+
state: selectFields(room.getPresence(), presenceMapping)
|
|
178
|
+
});
|
|
197
179
|
}
|
|
198
|
-
}
|
|
199
|
-
|
|
180
|
+
})
|
|
181
|
+
);
|
|
200
182
|
store.dispatch({
|
|
201
|
-
type: ACTION_TYPES.
|
|
202
|
-
state: updates
|
|
183
|
+
type: ACTION_TYPES.START_LOADING_STORAGE
|
|
203
184
|
});
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
room.
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (
|
|
210
|
-
store.
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
updates2,
|
|
215
|
-
mapping
|
|
216
|
-
)
|
|
217
|
-
});
|
|
185
|
+
room.getStorage().then(({ root }) => {
|
|
186
|
+
const updates = {};
|
|
187
|
+
room.batch(() => {
|
|
188
|
+
for (const key in mapping) {
|
|
189
|
+
const liveblocksStatePart = root.get(key);
|
|
190
|
+
if (liveblocksStatePart == null) {
|
|
191
|
+
updates[key] = store.getState()[key];
|
|
192
|
+
_core.patchLiveObjectKey.call(void 0, root, key, void 0, store.getState()[key]);
|
|
193
|
+
} else {
|
|
194
|
+
updates[key] = _core.lsonToJson.call(void 0, liveblocksStatePart);
|
|
218
195
|
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
store.dispatch({
|
|
199
|
+
type: ACTION_TYPES.INIT_STORAGE,
|
|
200
|
+
state: updates
|
|
201
|
+
});
|
|
202
|
+
storageRoot = root;
|
|
203
|
+
unsubscribeCallbacks.push(
|
|
204
|
+
room.subscribe(
|
|
205
|
+
root,
|
|
206
|
+
(updates2) => {
|
|
207
|
+
if (isPatching === false) {
|
|
208
|
+
store.dispatch({
|
|
209
|
+
type: ACTION_TYPES.PATCH_REDUX_STATE,
|
|
210
|
+
state: patchState(
|
|
211
|
+
store.getState(),
|
|
212
|
+
updates2,
|
|
213
|
+
mapping
|
|
214
|
+
)
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
{ isDeep: true }
|
|
219
|
+
)
|
|
220
|
+
);
|
|
221
|
+
});
|
|
228
222
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
} else if (action.type === ACTION_TYPES.LEAVE) {
|
|
239
|
-
leaveRoom2(action.roomId);
|
|
240
|
-
} else {
|
|
241
|
-
store.dispatch(action, state);
|
|
223
|
+
function leaveRoom2(roomId) {
|
|
224
|
+
for (const unsubscribe of unsubscribeCallbacks) {
|
|
225
|
+
unsubscribe();
|
|
226
|
+
}
|
|
227
|
+
storageRoot = null;
|
|
228
|
+
room = null;
|
|
229
|
+
isPatching = false;
|
|
230
|
+
unsubscribeCallbacks = [];
|
|
231
|
+
client.leave(roomId);
|
|
242
232
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
233
|
+
function newDispatch(action) {
|
|
234
|
+
if (action.type === ACTION_TYPES.ENTER) {
|
|
235
|
+
enterRoom2(action.roomId);
|
|
236
|
+
} else if (action.type === ACTION_TYPES.LEAVE) {
|
|
237
|
+
leaveRoom2(action.roomId);
|
|
238
|
+
} else {
|
|
239
|
+
store.dispatch(action);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return __spreadProps(__spreadValues({}, store), {
|
|
243
|
+
dispatch: newDispatch
|
|
244
|
+
});
|
|
245
|
+
};
|
|
247
246
|
};
|
|
248
247
|
};
|
|
249
248
|
var actions = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liveblocks/redux",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.1-test1",
|
|
4
4
|
"description": "A store enhancer to integrate Liveblocks into Redux stores.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
"collaborative"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
|
-
"dev": "tsup --watch
|
|
22
|
-
"build": "tsup
|
|
21
|
+
"dev": "tsup --watch",
|
|
22
|
+
"build": "tsup",
|
|
23
23
|
"format": "eslint --fix src/ && prettier --write src/",
|
|
24
24
|
"lint": "eslint src/",
|
|
25
|
-
"test": "jest --silent --verbose",
|
|
26
|
-
"test:watch": "jest --silent --verbose --watch"
|
|
25
|
+
"test": "jest --silent --verbose --color=always",
|
|
26
|
+
"test:watch": "jest --silent --verbose --color=always --watch"
|
|
27
27
|
},
|
|
28
28
|
"license": "Apache-2.0",
|
|
29
29
|
"repository": {
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"directory": "packages/liveblocks-redux"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@liveblocks/client": "0.19.
|
|
36
|
-
"@liveblocks/core": "0.19.
|
|
35
|
+
"@liveblocks/client": "0.19.1-test1",
|
|
36
|
+
"@liveblocks/core": "0.19.1-test1"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"redux": "^4"
|