@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 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: Array<User<TPresence, TUserMeta>>;
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: <T>(options: {
58
+ declare const liveblocksEnhancer: <TState>(options: {
59
59
  client: Client;
60
- storageMapping?: Mapping<T> | undefined;
61
- presenceMapping?: Mapping<T> | undefined;
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: <T>(options: {
66
+ declare const enhancer: <TState>(options: {
67
67
  client: Client;
68
- storageMapping?: Mapping<T> | undefined;
69
- presenceMapping?: Mapping<T> | undefined;
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) => (reducer, initialState, enhancer2) => {
81
- let room = null;
82
- let isPatching = false;
83
- let storageRoot = null;
84
- let unsubscribeCallbacks = [];
85
- const newReducer = (state, action) => {
86
- switch (action.type) {
87
- case ACTION_TYPES.PATCH_REDUX_STATE:
88
- return __spreadValues(__spreadValues({}, state), action.state);
89
- case ACTION_TYPES.INIT_STORAGE:
90
- return __spreadProps(__spreadValues(__spreadValues({}, state), action.state), {
91
- liveblocks: __spreadProps(__spreadValues({}, state.liveblocks), {
92
- isStorageLoading: false
93
- })
94
- });
95
- case ACTION_TYPES.START_LOADING_STORAGE:
96
- return __spreadProps(__spreadValues({}, state), {
97
- liveblocks: __spreadProps(__spreadValues({}, state.liveblocks), {
98
- isStorageLoading: true
99
- })
100
- });
101
- case ACTION_TYPES.UPDATE_CONNECTION: {
102
- return __spreadProps(__spreadValues({}, state), {
103
- liveblocks: __spreadProps(__spreadValues({}, state.liveblocks), {
104
- connection: action.connection
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
- if (newState.liveblocks == null) {
133
- return __spreadProps(__spreadValues({}, newState), {
134
- liveblocks: {
135
- others: [],
136
- isStorageLoading: false,
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
- return newState;
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
- const store = createStore(newReducer, initialState, enhancer2);
146
- function enterRoom2(roomId) {
147
- if (storageRoot) {
148
- return;
149
- }
150
- const initialPresence = selectFields(
151
- store.getState(),
152
- presenceMapping
153
- );
154
- room = client.enter(roomId, { initialPresence });
155
- unsubscribeCallbacks.push(
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.PATCH_REDUX_STATE,
176
- state: selectFields(
177
- room.getPresence(),
178
- presenceMapping
179
- )
159
+ type: ACTION_TYPES.UPDATE_CONNECTION,
160
+ connection: room.getConnectionState()
180
161
  });
181
- }
182
- })
183
- );
184
- store.dispatch({
185
- type: ACTION_TYPES.START_LOADING_STORAGE
186
- });
187
- room.getStorage().then(({ root }) => {
188
- const updates = {};
189
- room.batch(() => {
190
- for (const key in mapping) {
191
- const liveblocksStatePart = root.get(key);
192
- if (liveblocksStatePart == null) {
193
- updates[key] = store.getState()[key];
194
- _core.patchLiveObjectKey.call(void 0, root, key, void 0, store.getState()[key]);
195
- } else {
196
- updates[key] = _core.lsonToJson.call(void 0, liveblocksStatePart);
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.INIT_STORAGE,
202
- state: updates
183
+ type: ACTION_TYPES.START_LOADING_STORAGE
203
184
  });
204
- storageRoot = root;
205
- unsubscribeCallbacks.push(
206
- room.subscribe(
207
- root,
208
- (updates2) => {
209
- if (isPatching === false) {
210
- store.dispatch({
211
- type: ACTION_TYPES.PATCH_REDUX_STATE,
212
- state: patchState(
213
- store.getState(),
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
- { isDeep: true }
221
- )
222
- );
223
- });
224
- }
225
- function leaveRoom2(roomId) {
226
- for (const unsubscribe of unsubscribeCallbacks) {
227
- unsubscribe();
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
- storageRoot = null;
230
- room = null;
231
- isPatching = false;
232
- unsubscribeCallbacks = [];
233
- client.leave(roomId);
234
- }
235
- function newDispatch(action, state) {
236
- if (action.type === ACTION_TYPES.ENTER) {
237
- enterRoom2(action.roomId);
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
- return __spreadProps(__spreadValues({}, store), {
245
- dispatch: newDispatch
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.0-beta0",
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 --onSuccess ../../scripts/build.sh",
22
- "build": "tsup && ../../scripts/build.sh",
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.0-beta0",
36
- "@liveblocks/core": "0.19.0-beta0"
35
+ "@liveblocks/client": "0.19.1-test1",
36
+ "@liveblocks/core": "0.19.1-test1"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "redux": "^4"
package/dist/index.mjs DELETED
@@ -1,6 +0,0 @@
1
- import mod from "./index.js";
2
-
3
- export default mod;
4
- export const actions = mod.actions;
5
- export const enhancer = mod.enhancer;
6
- export const liveblocksEnhancer = mod.liveblocksEnhancer;