@player-tools/devtools-client 0.2.1 → 0.2.2--canary.17.363

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