@player-tools/devtools-client 0.2.2--canary.19.409 → 0.2.2--canary.17.433

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.esm.js CHANGED
@@ -1,30 +1,10 @@
1
- import { createLogger, BACKGROUND_SOURCE, Runtime, playerTimelineAction, playerViewUpdateAction, playerFlowStartAction, playerRemoveAction, selectedPlayerAction, playerInitAction, clearStore, createRPCRequest, PANEL_SOURCE } from '@player-tools/devtools-common';
2
- export * from '@player-tools/devtools-common';
3
- import { createAsyncThunk } from '@reduxjs/toolkit';
1
+ import { createAction, createAsyncThunk, createListenerMiddleware, isAnyOf, createReducer, createSelector, configureStore } from '@reduxjs/toolkit';
2
+ import { Events, createLogger, BACKGROUND_SOURCE, Methods, RUNTIME_SOURCE } from '@player-tools/devtools-common';
4
3
 
5
- const GET_INFO_DETAILS = "GET_INFO_DETAILS";
6
- const GET_CONFIG_DETAILS = "GET_CONFIG_DETAILS";
7
- const GET_VIEW_DETAILS = "GET_VIEW_DETAILS";
8
- const GET_DATA_BINDING_DETAILS = "GET_DATA_BINDING_DETAILS";
9
- const GET_CONSOLE_EVAL = "GET_CONSOLE_EVAL";
10
- const START_PROFILER = "START_PROFILER";
11
- const STOP_PROFILER = "STOP_PROFILER";
12
- const _alias = (aliases) => () => (next) => (action) => {
13
- const alias = aliases[action.type];
14
- if (alias) {
15
- return next(alias(action));
16
- }
17
- return next(action);
18
- };
19
- const buildAliases = (actions) => _alias({
20
- GET_INFO_DETAILS: (action) => actions["player-runtime-info-request"](action.payload),
21
- GET_CONFIG_DETAILS: (action) => actions["player-config-request"](action.payload),
22
- GET_VIEW_DETAILS: (action) => actions["player-view-details-request"](action.payload),
23
- GET_DATA_BINDING_DETAILS: (action) => actions["player-data-binding-details"](action.payload),
24
- GET_CONSOLE_EVAL: (action) => actions["player-execute-expression"](action.payload),
25
- START_PROFILER: (action) => actions["player-start-profiler-request"](action.payload),
26
- STOP_PROFILER: (action) => actions["player-stop-profiler-request"](action.payload)
27
- });
4
+ const Actions$1 = Object.fromEntries(Events.EventTypes.map((event) => [
5
+ event,
6
+ createAction(event)
7
+ ]));
28
8
 
29
9
  var __async = (__this, __arguments, generator) => {
30
10
  return new Promise((resolve, reject) => {
@@ -47,18 +27,121 @@ var __async = (__this, __arguments, generator) => {
47
27
  });
48
28
  };
49
29
  const logger = createLogger(BACKGROUND_SOURCE);
50
- const buildRPCActions = (handlers) => Runtime.RuntimeRPCTypes.reduce((acc, rpcType) => {
51
- acc[rpcType] = createAsyncThunk(rpcType, (params) => __async(undefined, null, function* () {
52
- logger.log(`Requesting ${rpcType}`, params);
53
- const data = yield handlers[rpcType].call(params);
54
- logger.log(`Response from ${rpcType}`, data);
30
+ const buildMethodThunks = (onMethodRequest) => Object.fromEntries(Methods.MethodTypes.map((method) => [
31
+ method,
32
+ createAsyncThunk(method, (method2) => __async(undefined, null, function* () {
33
+ logger.log(`Requesting ${method2.type}`, method2.params);
34
+ const data = yield onMethodRequest(method2);
35
+ logger.log(`Response from ${method2.type}`, data);
55
36
  return data;
56
- }));
57
- return acc;
58
- }, {});
37
+ }))
38
+ ]));
39
+
40
+ const Actions = {
41
+ "selected-player": createAction("selected-player"),
42
+ "player-timeline-event": createAction("player-timeline-event"),
43
+ "clear-selected-data-details": createAction("clear-selected-data-details"),
44
+ "clear-console": createAction("clear-console"),
45
+ "clear-logs": createAction("clear-logs"),
46
+ "clear-store": createAction("clear-store")
47
+ };
48
+
49
+ const GET_INFO_DETAILS = "GET_INFO_DETAILS";
50
+ const GET_CONFIG_DETAILS = "GET_CONFIG_DETAILS";
51
+ const GET_VIEW_DETAILS = "GET_VIEW_DETAILS";
52
+ const GET_DATA_BINDING_DETAILS = "GET_DATA_BINDING_DETAILS";
53
+ const GET_CONSOLE_EVAL = "GET_CONSOLE_EVAL";
54
+ const START_PROFILER = "START_PROFILER";
55
+ const STOP_PROFILER = "STOP_PROFILER";
56
+ const _alias = (aliases) => () => (next) => (action) => {
57
+ const alias2 = aliases[action.type];
58
+ if (alias2) {
59
+ return next(alias2(action));
60
+ }
61
+ return next(action);
62
+ };
63
+ const alias = (type, methods) => (action) => methods[type]({
64
+ type,
65
+ params: action.payload,
66
+ source: RUNTIME_SOURCE
67
+ });
68
+ const buildAliases = (methods) => _alias({
69
+ GET_INFO_DETAILS: alias("player-runtime-info-request", methods),
70
+ GET_CONFIG_DETAILS: alias("player-config-request", methods),
71
+ GET_VIEW_DETAILS: alias("player-view-details-request", methods),
72
+ GET_DATA_BINDING_DETAILS: alias("player-data-binding-details", methods),
73
+ GET_CONSOLE_EVAL: alias("player-execute-expression", methods),
74
+ START_PROFILER: alias("player-start-profiler-request", methods),
75
+ STOP_PROFILER: alias("player-stop-profiler-request", methods)
76
+ });
77
+
78
+ const dispatchEvents = (dispatch) => (message) => {
79
+ if (Events.isEvent(message))
80
+ dispatch(Actions$1[message.type](message));
81
+ };
59
82
 
60
- const buildPlayerReducerCallback = (actions) => (builder) => {
61
- builder.addCase(actions["player-runtime-info-request"].fulfilled, (state, action) => {
83
+ const listenerMiddleware = createListenerMiddleware();
84
+ listenerMiddleware.startListening({
85
+ matcher: isAnyOf(Actions$1["player-data-change-event"], Actions$1["player-log-event"], Actions$1["player-flow-start"]),
86
+ effect: (action, api) => {
87
+ api.dispatch(Actions["player-timeline-event"](action.payload));
88
+ }
89
+ });
90
+ listenerMiddleware.startListening({
91
+ actionCreator: Actions$1["runtime-init"],
92
+ effect: (_, api) => {
93
+ api.dispatch(Actions["clear-store"]());
94
+ }
95
+ });
96
+ listenerMiddleware.startListening({
97
+ matcher: isAnyOf(Actions$1["player-init"], Actions$1["player-removed"]),
98
+ effect: (_, api) => {
99
+ api.dispatch(Actions["selected-player"]());
100
+ }
101
+ });
102
+ listenerMiddleware.startListening({
103
+ matcher: isAnyOf(Actions$1["player-flow-start"], Actions$1["player-data-change-event"]),
104
+ effect: (action, api) => {
105
+ const { players } = api.getState();
106
+ const { playerID } = action.payload;
107
+ if (players.activePlayers[playerID] && players.activePlayers[playerID].dataState.selectedBinding) {
108
+ api.dispatch({
109
+ type: GET_DATA_BINDING_DETAILS,
110
+ payload: { playerID, binding: players.activePlayers[playerID].dataState.selectedBinding }
111
+ });
112
+ }
113
+ api.dispatch({
114
+ type: GET_DATA_BINDING_DETAILS,
115
+ payload: { playerID, binding: "" }
116
+ });
117
+ }
118
+ });
119
+
120
+ var __defProp$1 = Object.defineProperty;
121
+ var __defProps = Object.defineProperties;
122
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
123
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
124
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
125
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
126
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
127
+ var __spreadValues$1 = (a, b) => {
128
+ for (var prop in b || (b = {}))
129
+ if (__hasOwnProp$1.call(b, prop))
130
+ __defNormalProp$1(a, prop, b[prop]);
131
+ if (__getOwnPropSymbols$1)
132
+ for (var prop of __getOwnPropSymbols$1(b)) {
133
+ if (__propIsEnum$1.call(b, prop))
134
+ __defNormalProp$1(a, prop, b[prop]);
135
+ }
136
+ return a;
137
+ };
138
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
139
+ const initialState = {
140
+ selectedPlayerId: null,
141
+ activePlayers: {}
142
+ };
143
+ const methodsReducer = (methods) => (builder) => {
144
+ builder.addCase(methods["player-runtime-info-request"].fulfilled, (state, action) => {
62
145
  const { activePlayers, selectedPlayerId } = state;
63
146
  if (!selectedPlayerId) {
64
147
  return;
@@ -66,14 +149,14 @@ const buildPlayerReducerCallback = (actions) => (builder) => {
66
149
  const data = action.payload && Object.keys(action.payload).length > 0 ? action.payload : null;
67
150
  activePlayers[selectedPlayerId].flowInfo = data;
68
151
  });
69
- builder.addCase(actions["player-config-request"].fulfilled, (state, action) => {
152
+ builder.addCase(methods["player-config-request"].fulfilled, (state, action) => {
70
153
  const { activePlayers, selectedPlayerId } = state;
71
154
  if (!selectedPlayerId) {
72
155
  return;
73
156
  }
74
157
  activePlayers[selectedPlayerId].configState = action.payload;
75
158
  });
76
- builder.addCase(actions["player-view-details-request"].fulfilled, (state, action) => {
159
+ builder.addCase(methods["player-view-details-request"].fulfilled, (state, action) => {
77
160
  var _a;
78
161
  const { activePlayers, selectedPlayerId } = state;
79
162
  if (!selectedPlayerId) {
@@ -81,10 +164,10 @@ const buildPlayerReducerCallback = (actions) => (builder) => {
81
164
  }
82
165
  activePlayers[selectedPlayerId].view = (_a = action.payload) == null ? void 0 : _a.lastViewUpdate;
83
166
  });
84
- builder.addCase(actions["player-data-binding-details"].fulfilled, (state, action) => {
167
+ builder.addCase(methods["player-data-binding-details"].fulfilled, (state, action) => {
85
168
  const {
86
169
  meta: {
87
- arg: { binding, playerID }
170
+ arg: { params: { binding, playerID } }
88
171
  },
89
172
  payload
90
173
  } = action;
@@ -98,7 +181,7 @@ const buildPlayerReducerCallback = (actions) => (builder) => {
98
181
  }
99
182
  activePlayers[playerID].dataState.selectedBinding = payload;
100
183
  });
101
- builder.addCase(actions["player-execute-expression"].fulfilled, (state, action) => {
184
+ builder.addCase(methods["player-execute-expression"].fulfilled, (state, action) => {
102
185
  var _a, _b, _c, _d;
103
186
  const { activePlayers, selectedPlayerId } = state;
104
187
  if (!selectedPlayerId) {
@@ -110,14 +193,14 @@ const buildPlayerReducerCallback = (actions) => (builder) => {
110
193
  expression: (_c = (_b = action.payload) == null ? void 0 : _b.exp) != null ? _c : ""
111
194
  });
112
195
  });
113
- builder.addCase(actions["player-start-profiler-request"].fulfilled, (state, action) => {
196
+ builder.addCase(methods["player-start-profiler-request"].fulfilled, (state, action) => {
114
197
  var _a;
115
198
  const { activePlayers, selectedPlayerId } = state;
116
199
  if (!selectedPlayerId)
117
200
  return;
118
201
  activePlayers[selectedPlayerId].profilerInfo = (_a = action.payload) == null ? void 0 : _a.data;
119
202
  });
120
- builder.addCase(actions["player-stop-profiler-request"].fulfilled, (state, action) => {
203
+ builder.addCase(methods["player-stop-profiler-request"].fulfilled, (state, action) => {
121
204
  var _a;
122
205
  const { activePlayers, selectedPlayerId } = state;
123
206
  if (!selectedPlayerId)
@@ -125,59 +208,200 @@ const buildPlayerReducerCallback = (actions) => (builder) => {
125
208
  activePlayers[selectedPlayerId].profilerInfo = (_a = action.payload) == null ? void 0 : _a.data;
126
209
  });
127
210
  };
128
-
129
- function handleMessage(store, message) {
130
- switch (message.type) {
131
- case "runtime-init":
132
- store.dispatch(clearStore());
133
- break;
134
- case "player-init":
135
- store.dispatch(playerInitAction(message));
136
- store.dispatch(selectedPlayerAction());
137
- break;
138
- case "player-removed":
139
- store.dispatch(playerRemoveAction(message.playerID));
140
- store.dispatch(selectedPlayerAction());
141
- break;
142
- case "player-flow-start":
143
- store.dispatch(playerFlowStartAction(message));
144
- store.dispatch(playerTimelineAction(message));
145
- store.dispatch({
146
- type: GET_DATA_BINDING_DETAILS,
147
- payload: { playerID: message.playerID, binding: "" }
148
- });
149
- break;
150
- case "player-log-event":
151
- store.dispatch(playerTimelineAction(message));
152
- break;
153
- case "player-view-update-event":
154
- store.dispatch(playerViewUpdateAction(message));
155
- break;
156
- case "player-data-change-event": {
157
- const { players } = store.getState();
158
- if (players.activePlayers[message.playerID] && players.activePlayers[message.playerID].dataState.selectedBinding) {
159
- store.dispatch({
160
- type: GET_DATA_BINDING_DETAILS,
161
- payload: message
162
- });
163
- }
164
- store.dispatch({
165
- type: GET_DATA_BINDING_DETAILS,
166
- payload: { playerID: message.playerID, binding: "" }
167
- });
168
- store.dispatch(playerTimelineAction(message));
169
- break;
211
+ const eventsReducer = (builder) => {
212
+ builder.addCase(Actions$1["player-init"], (state, action) => {
213
+ const {
214
+ payload: { version, playerID }
215
+ } = action;
216
+ state.activePlayers[playerID] = {
217
+ timelineEvents: [],
218
+ dataState: {},
219
+ consoleState: { history: [] }
220
+ };
221
+ state.version = version;
222
+ });
223
+ builder.addCase(Actions$1["player-removed"], (state, action) => {
224
+ delete state.activePlayers[action.payload.playerID];
225
+ });
226
+ builder.addCase(Actions$1["player-flow-start"], (state, action) => {
227
+ const {
228
+ payload: { flow, playerID }
229
+ } = action;
230
+ if (!state.activePlayers[playerID]) {
231
+ state.activePlayers[playerID] = {
232
+ flowInfo: { currentFlow: flow },
233
+ timelineEvents: [],
234
+ dataState: {},
235
+ consoleState: { history: [] }
236
+ };
237
+ state.selectedPlayerId = playerID;
238
+ return;
239
+ }
240
+ state.activePlayers[playerID].flowInfo = __spreadProps(__spreadValues$1({}, state.activePlayers[playerID].flowInfo), {
241
+ currentFlow: flow
242
+ });
243
+ });
244
+ builder.addCase(Actions$1["player-view-update-event"], (state, action) => {
245
+ const {
246
+ payload: { playerID, update }
247
+ } = action;
248
+ if (!state.activePlayers[playerID]) {
249
+ state.activePlayers[playerID] = {
250
+ view: update,
251
+ timelineEvents: [],
252
+ dataState: {},
253
+ consoleState: { history: [] }
254
+ };
255
+ state.selectedPlayerId = playerID;
256
+ return;
257
+ }
258
+ state.activePlayers[playerID].view = update;
259
+ });
260
+ };
261
+ const actionsReducer = (builder) => {
262
+ builder.addCase(Actions["selected-player"], (state, action) => {
263
+ if (action.payload) {
264
+ state.selectedPlayerId = action.payload;
265
+ return;
266
+ }
267
+ state.selectedPlayerId = Object.keys(state.activePlayers)[0] || null;
268
+ });
269
+ builder.addCase(Actions["player-timeline-event"], (state, action) => {
270
+ const {
271
+ payload: { playerID }
272
+ } = action;
273
+ if (!state.activePlayers[playerID]) {
274
+ state.activePlayers[playerID] = {
275
+ timelineEvents: [action.payload],
276
+ dataState: {},
277
+ consoleState: { history: [] }
278
+ };
279
+ state.selectedPlayerId = playerID;
280
+ return;
281
+ }
282
+ state.activePlayers[playerID].timelineEvents.push(action.payload);
283
+ });
284
+ builder.addCase(Actions["clear-selected-data-details"], (state) => {
285
+ const { activePlayers, selectedPlayerId } = state;
286
+ if (!selectedPlayerId || !activePlayers[selectedPlayerId]) {
287
+ return;
288
+ }
289
+ activePlayers[selectedPlayerId].dataState.selectedBinding = void 0;
290
+ });
291
+ builder.addCase(Actions["clear-console"], (state) => {
292
+ const { activePlayers, selectedPlayerId } = state;
293
+ if (!selectedPlayerId) {
294
+ return;
295
+ }
296
+ activePlayers[selectedPlayerId].consoleState = {
297
+ history: []
298
+ };
299
+ });
300
+ builder.addCase(Actions["clear-logs"], (state) => {
301
+ const { activePlayers, selectedPlayerId } = state;
302
+ if (!selectedPlayerId) {
303
+ return;
170
304
  }
171
- default:
172
- console.warn(`Unhandled event: ${JSON.stringify(message)}`);
173
- break;
305
+ activePlayers[selectedPlayerId].timelineEvents = [];
306
+ });
307
+ builder.addCase(Actions["clear-store"], () => {
308
+ return initialState;
309
+ });
310
+ };
311
+ const playersReducer = (methods) => createReducer(initialState, (builder) => {
312
+ actionsReducer(builder);
313
+ eventsReducer(builder);
314
+ methodsReducer(methods)(builder);
315
+ });
316
+
317
+ const selectPlayers = (state) => {
318
+ return state.players;
319
+ };
320
+ const selectActivePlayers = createSelector(selectPlayers, (players) => players.activePlayers);
321
+ const selectPlayerVersion = createSelector(selectPlayers, (players) => players.version);
322
+ const selectPlayerIds = createSelector(selectActivePlayers, (activePlayers) => Object.keys(activePlayers) || []);
323
+ const selectSelectedPlayerId = createSelector(selectPlayers, (players) => players.selectedPlayerId);
324
+ const selectCurrentPlayer = createSelector(selectActivePlayers, selectSelectedPlayerId, (activePlayers, selectedPlayerId) => {
325
+ if (!selectedPlayerId) {
326
+ return null;
174
327
  }
175
- }
328
+ return activePlayers[selectedPlayerId];
329
+ });
330
+ const selectConfig = createSelector(selectCurrentPlayer, (currentPlayer) => {
331
+ var _a;
332
+ return (_a = currentPlayer == null ? void 0 : currentPlayer.configState) != null ? _a : null;
333
+ });
334
+ const selectData = createSelector(selectCurrentPlayer, (currentPlayer) => {
335
+ return currentPlayer == null ? void 0 : currentPlayer.dataState;
336
+ });
337
+ const selectFlowInfo = createSelector(selectCurrentPlayer, (currentPlayer) => {
338
+ if (!currentPlayer) {
339
+ return null;
340
+ }
341
+ return currentPlayer == null ? void 0 : currentPlayer.flowInfo;
342
+ });
343
+ const selectCurrentFlow = createSelector(selectFlowInfo, (flowInfo) => {
344
+ return flowInfo == null ? void 0 : flowInfo.currentFlow;
345
+ });
346
+ const selectCurrentTopic = createSelector(selectCurrentFlow, (currentFlow) => {
347
+ return currentFlow == null ? void 0 : currentFlow.topic;
348
+ });
349
+ const selectEvents = createSelector(selectCurrentPlayer, (currentPlayer) => {
350
+ if (!currentPlayer) {
351
+ return [];
352
+ }
353
+ return currentPlayer == null ? void 0 : currentPlayer.timelineEvents;
354
+ });
355
+ const selectView = createSelector(selectCurrentPlayer, (currentPlayer) => {
356
+ if (!currentPlayer) {
357
+ return null;
358
+ }
359
+ return currentPlayer == null ? void 0 : currentPlayer.view;
360
+ });
361
+ const selectAllBindings = createSelector(selectData, (data) => {
362
+ return data == null ? void 0 : data.allBindings;
363
+ });
364
+ const selectSelectedBinding = createSelector(selectData, (data) => {
365
+ return data == null ? void 0 : data.selectedBinding;
366
+ });
367
+ const selectConsole = createSelector(selectCurrentPlayer, (currentPlayer) => {
368
+ if (!currentPlayer) {
369
+ return { history: [] };
370
+ }
371
+ return currentPlayer.consoleState;
372
+ });
373
+ const selectProfiler = createSelector(selectCurrentPlayer, (currentPlayer) => {
374
+ return currentPlayer == null ? void 0 : currentPlayer.profilerInfo;
375
+ });
176
376
 
177
- const buildRPCRequests = (onRequestMessage) => Runtime.RuntimeRPCTypes.reduce((acc, rpcType) => {
178
- acc[rpcType] = createRPCRequest(rpcType, PANEL_SOURCE, onRequestMessage);
179
- return acc;
180
- }, {});
377
+ var __defProp = Object.defineProperty;
378
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
379
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
380
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
381
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
382
+ var __spreadValues = (a, b) => {
383
+ for (var prop in b || (b = {}))
384
+ if (__hasOwnProp.call(b, prop))
385
+ __defNormalProp(a, prop, b[prop]);
386
+ if (__getOwnPropSymbols)
387
+ for (var prop of __getOwnPropSymbols(b)) {
388
+ if (__propIsEnum.call(b, prop))
389
+ __defNormalProp(a, prop, b[prop]);
390
+ }
391
+ return a;
392
+ };
393
+ const createStore = (methodThunks, middleware, reducers) => configureStore({
394
+ reducer: __spreadValues({
395
+ players: playersReducer(methodThunks)
396
+ }, reducers),
397
+ middleware: (getDefaultMiddleware) => {
398
+ const m = getDefaultMiddleware().prepend(buildAliases(methodThunks)).concat(listenerMiddleware.middleware);
399
+ if (middleware)
400
+ m.concat(middleware);
401
+ return m;
402
+ }
403
+ });
404
+ const createDevtoolsStore = (onMethodRequest, middleware, additionalReducers) => createStore(buildMethodThunks(onMethodRequest), middleware, additionalReducers);
181
405
 
182
- export { GET_CONFIG_DETAILS, GET_CONSOLE_EVAL, GET_DATA_BINDING_DETAILS, GET_INFO_DETAILS, GET_VIEW_DETAILS, START_PROFILER, STOP_PROFILER, buildAliases, buildPlayerReducerCallback, buildRPCActions, buildRPCRequests, handleMessage };
406
+ export { Actions, Actions$1 as EventActions, GET_CONFIG_DETAILS, GET_CONSOLE_EVAL, GET_DATA_BINDING_DETAILS, GET_INFO_DETAILS, GET_VIEW_DETAILS, START_PROFILER, STOP_PROFILER, buildAliases, buildMethodThunks, createDevtoolsStore, dispatchEvents, listenerMiddleware, playersReducer, selectAllBindings, selectConfig, selectConsole, selectCurrentFlow, selectCurrentPlayer, selectCurrentTopic, selectEvents, selectFlowInfo, selectPlayerIds, selectPlayerVersion, selectProfiler, selectSelectedBinding, selectSelectedPlayerId, selectView };
183
407
  //# sourceMappingURL=index.esm.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@player-tools/devtools-client",
3
- "version": "0.2.2--canary.19.409",
3
+ "version": "0.2.2--canary.17.433",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org"
@@ -8,7 +8,7 @@
8
8
  "peerDependencies": {},
9
9
  "dependencies": {
10
10
  "@reduxjs/toolkit": "^1.6.1",
11
- "@player-tools/devtools-common": "0.2.2--canary.19.409",
11
+ "@player-tools/devtools-common": "0.2.2--canary.17.433",
12
12
  "@babel/runtime": "7.15.4"
13
13
  },
14
14
  "main": "dist/index.cjs.js",
package/src/index.ts CHANGED
@@ -1,3 +1 @@
1
1
  export * from './redux';
2
- export * from './rpc';
3
- export * from '@player-tools/devtools-common';
@@ -0,0 +1,16 @@
1
+ import { Events } from '@player-tools/devtools-common';
2
+ import { ActionCreatorWithPayload, createAction } from '@reduxjs/toolkit';
3
+ import { AnyAction } from 'redux';
4
+
5
+ /** Redux actions associated against all possible event types */
6
+ type EventActions = {
7
+ [key in Events.EventTypes]: ActionCreatorWithPayload<Events.ByType<key>, key>;
8
+ };
9
+
10
+ /** Redux actions associated against all defined event types */
11
+ export const Actions: EventActions = Object.fromEntries(
12
+ Events.EventTypes.map((event) => [
13
+ event,
14
+ createAction<Events.ByType<typeof event>>(event),
15
+ ])
16
+ ) as EventActions;
@@ -0,0 +1,20 @@
1
+ import { createAction } from '@reduxjs/toolkit';
2
+ import type { Events } from '@player-tools/devtools-common';
3
+
4
+ export { Actions as EventActions } from './events';
5
+ export * from './methods';
6
+
7
+ /** Explicit actions that don't correspond to a specific event or method */
8
+ export const Actions = {
9
+ // Explicit actions TODO: Is this level of redundancy okay?
10
+ 'selected-player': createAction<string | undefined>('selected-player'),
11
+ 'player-timeline-event': createAction<Events.TimelineEvents>(
12
+ 'player-timeline-event'
13
+ ),
14
+
15
+ // Reset actions
16
+ 'clear-selected-data-details': createAction('clear-selected-data-details'),
17
+ 'clear-console': createAction('clear-console'),
18
+ 'clear-logs': createAction('clear-logs'),
19
+ 'clear-store': createAction('clear-store'),
20
+ };
@@ -0,0 +1,43 @@
1
+ import {
2
+ BACKGROUND_SOURCE,
3
+ createLogger,
4
+ Methods,
5
+ } from '@player-tools/devtools-common';
6
+ import { createAsyncThunk, type AsyncThunk } from '@reduxjs/toolkit';
7
+
8
+ const logger = createLogger(BACKGROUND_SOURCE);
9
+
10
+ /** Type describing an object containing async thunks for each Method defined */
11
+ export type MethodThunks = {
12
+ [key in Methods.Method['type']]: AsyncThunk<
13
+ Methods.ByType<key>['result'],
14
+ Methods.ByType<key>,
15
+ any
16
+ >;
17
+ };
18
+
19
+ /** Signature for handling method requests */
20
+ export type MethodHandler = <T extends Methods.MethodTypes>(
21
+ method: Methods.ByType<T>
22
+ ) => Promise<Methods.ByType<T>['result']>;
23
+
24
+ /** Utility for building async thunks for all known method types */
25
+ export const buildMethodThunks = (
26
+ onMethodRequest: MethodHandler
27
+ ): MethodThunks =>
28
+ Object.fromEntries(
29
+ Methods.MethodTypes.map((method) => [
30
+ method,
31
+ createAsyncThunk<
32
+ Methods.ByType<typeof method>['result'],
33
+ Methods.ByType<typeof method>
34
+ >(method, async (method) => {
35
+ logger.log(`Requesting ${method.type}`, method.params);
36
+ const data = (await onMethodRequest(method)) as Methods.ByType<
37
+ typeof method.type
38
+ >['result'];
39
+ logger.log(`Response from ${method.type}`, data);
40
+ return data;
41
+ }),
42
+ ])
43
+ ) as MethodThunks;
@@ -1,12 +1,5 @@
1
- import type {
2
- AliasAction,
3
- ConfigAction,
4
- DataBindingAction,
5
- ExpressionAction,
6
- StartProfilerAction,
7
- StopProfilerAction,
8
- } from '@player-tools/devtools-common';
9
- import type { AsyncRPCActions } from './actions';
1
+ import { Methods as Methods, RUNTIME_SOURCE } from '@player-tools/devtools-common';
2
+ import { MethodThunks } from './actions/methods';
10
3
 
11
4
  export const GET_INFO_DETAILS = 'GET_INFO_DETAILS';
12
5
  export const GET_CONFIG_DETAILS = 'GET_CONFIG_DETAILS';
@@ -16,6 +9,12 @@ export const GET_CONSOLE_EVAL = 'GET_CONSOLE_EVAL';
16
9
  export const START_PROFILER = 'START_PROFILER';
17
10
  export const STOP_PROFILER = 'STOP_PROFILER';
18
11
 
12
+
13
+ interface MethodAction<T extends Methods.MethodTypes> {
14
+ payload: Methods.ByType<T>['params'];
15
+ }
16
+
17
+ // Copied from webext redux library not allowed in flipper
19
18
  const _alias = (aliases: any) => () => (next: any) => (action: any) => {
20
19
  const alias = aliases[action.type];
21
20
 
@@ -26,20 +25,20 @@ const _alias = (aliases: any) => () => (next: any) => (action: any) => {
26
25
  return next(action);
27
26
  };
28
27
 
29
- export const buildAliases = (actions: AsyncRPCActions) =>
28
+ /** Helper for building corresponding method action via supplied thunks */
29
+ const alias = <T extends Methods.MethodTypes>(type: T, methods: MethodThunks) => (action: MethodAction<T>) => methods[type]({
30
+ type,
31
+ params: action.payload,
32
+ source: RUNTIME_SOURCE,
33
+ } as Methods.ByType<T>)
34
+
35
+ export const buildAliases = (methods: MethodThunks) =>
30
36
  _alias({
31
- GET_INFO_DETAILS: (action: AliasAction) =>
32
- actions['player-runtime-info-request'](action.payload),
33
- GET_CONFIG_DETAILS: (action: ConfigAction) =>
34
- actions['player-config-request'](action.payload),
35
- GET_VIEW_DETAILS: (action: AliasAction) =>
36
- actions['player-view-details-request'](action.payload),
37
- GET_DATA_BINDING_DETAILS: (action: DataBindingAction) =>
38
- actions['player-data-binding-details'](action.payload),
39
- GET_CONSOLE_EVAL: (action: ExpressionAction) =>
40
- actions['player-execute-expression'](action.payload),
41
- START_PROFILER: (action: StartProfilerAction) =>
42
- actions['player-start-profiler-request'](action.payload),
43
- STOP_PROFILER: (action: StopProfilerAction) =>
44
- actions['player-stop-profiler-request'](action.payload),
37
+ GET_INFO_DETAILS: alias('player-runtime-info-request', methods),
38
+ GET_CONFIG_DETAILS: alias('player-config-request', methods),
39
+ GET_VIEW_DETAILS: alias('player-view-details-request', methods),
40
+ GET_DATA_BINDING_DETAILS: alias('player-data-binding-details', methods),
41
+ GET_CONSOLE_EVAL: alias('player-execute-expression', methods),
42
+ START_PROFILER: alias('player-start-profiler-request', methods),
43
+ STOP_PROFILER: alias('player-stop-profiler-request', methods),
45
44
  });