Skip to content

Commit f9a3b45

Browse files
author
Eduard Aksamitov
committed
feat: events title, subtitle and grouping
1 parent 4706d93 commit f9a3b45

File tree

1 file changed

+53
-63
lines changed

1 file changed

+53
-63
lines changed

index.js

Lines changed: 53 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ export const devtools = {
102102

103103
if (layers.state !== false) {
104104
client.on('state', () => {
105-
let details
105+
let data = {}
106106
let time = Date.now()
107107

108108
if (client.state === 'connecting' && node.connection.url) {
109-
details = {
109+
data = {
110110
nodeId: node.localNodeId,
111111
server: node.connection.url
112112
}
@@ -116,24 +116,17 @@ export const devtools = {
116116
node.remoteNodeId
117117
) {
118118
prevConnected = true
119-
details = {
119+
data = {
120120
server: node.remoteNodeId
121121
}
122122
} else if (!client.connected) {
123123
prevConnected = false
124124
}
125125

126-
let data = {
127-
state: client.state
128-
}
129-
130-
if (details) {
131-
data.details = details
132-
}
133-
134126
api.addTimelineEvent({
135127
layerId: stateLayerId,
136128
event: {
129+
title: client.state,
137130
time,
138131
data
139132
}
@@ -146,6 +139,8 @@ export const devtools = {
146139
api.addTimelineEvent({
147140
layerId: roleLayerId,
148141
event: {
142+
title: 'Changed',
143+
subtitle: client.role,
149144
time: Date.now(),
150145
data: {
151146
role: client.role
@@ -173,32 +168,25 @@ export const devtools = {
173168
let time = Date.now()
174169

175170
if (action.type === 'logux/subscribe') {
176-
let data = {
177-
type: 'subscribing',
178-
channel: action.channel
179-
}
180-
181-
if (Object.keys(action).length === 2) {
182-
data.action = action
183-
}
184-
185171
api.addTimelineEvent({
186172
layerId: subscriptionLayerId,
187-
event: { time, data }
173+
event: {
174+
title: 'Subscribing',
175+
subtitle: action.channel,
176+
groupId: meta.id,
177+
time,
178+
data: { action, meta }
179+
}
188180
})
189181
} else if (action.type === 'logux/unsubscribe') {
190-
let data = {
191-
type: 'unsubscribed',
192-
channel: action.channel
193-
}
194-
195-
if (Object.keys(action).length === 2) {
196-
data.action = action
197-
}
198-
199182
api.addTimelineEvent({
200183
layerId: subscriptionLayerId,
201-
event: { time, data }
184+
event: {
185+
title: 'Unsubscribed',
186+
subtitle: action.channel,
187+
time,
188+
data: { action, meta }
189+
}
202190
})
203191
} else if (action.type === 'logux/processed') {
204192
if (subscribing[action.id]) {
@@ -207,10 +195,11 @@ export const devtools = {
207195
api.addTimelineEvent({
208196
layerId: subscriptionLayerId,
209197
event: {
198+
title: 'Subscribed',
199+
subtitle: processed.channel,
200+
groupId: action.id,
210201
time,
211202
data: {
212-
type: 'subscribed',
213-
channel: processed.channel,
214203
action: processed
215204
}
216205
}
@@ -225,11 +214,10 @@ export const devtools = {
225214
api.addTimelineEvent({
226215
layerId: subscriptionLayerId,
227216
event: {
217+
title: 'Subscribed by server',
218+
subtitle: action.channel,
228219
time,
229-
data: {
230-
type: 'subscribed by server',
231-
channel: action.channel
232-
}
220+
data: { action, meta }
233221
}
234222
})
235223
}
@@ -255,11 +243,10 @@ export const devtools = {
255243
api.addTimelineEvent({
256244
layerId: actionLayerId,
257245
event: {
246+
title: 'Processed',
247+
subtitle: processed.type,
258248
time,
259-
data: {
260-
type: 'processed',
261-
action: processed
262-
}
249+
data: { processed, action, meta }
263250
}
264251
})
265252
}
@@ -268,57 +255,57 @@ export const devtools = {
268255
api.addTimelineEvent({
269256
layerId: actionLayerId,
270257
event: {
258+
title: 'Processed',
271259
time,
272-
data: {
273-
type: 'processed',
274-
action
275-
}
260+
data: { action, meta }
276261
}
277262
})
278263
}
279264
} else if (action.type === 'logux/undo') {
280265
let data = {
281-
type: 'undid',
282-
actionId: action.id,
283-
reason: action.reason
266+
reason: action.reason,
267+
action,
268+
meta
284269
}
285270

286271
if (sent[action.id]) {
287-
data.details = {
272+
data.undone = {
288273
action: sent[action.id]
289274
}
290275
delete sent[action.id]
291276
}
292277

293-
if (Object.keys(action).length > 3) {
294-
if (!data.details) data.details = {}
295-
data.details.undo = action
296-
}
297-
298278
api.addTimelineEvent({
299279
layerId: actionLayerId,
300-
event: { time, data }
280+
event: {
281+
title: 'Undid',
282+
subtitle: data.undone.type || '',
283+
time,
284+
data
285+
}
301286
})
302287
} else {
303-
let data = {
304-
type: 'added',
305-
action,
306-
meta
307-
}
288+
let title = 'Added'
289+
let data = { action, meta }
308290

309291
if (meta.reasons.length === 0) {
310292
cleaned[meta.id] = true
311-
data.type += ' and cleaned'
293+
title += ' and cleaned'
312294
}
313295

314296
let { nodeId } = parseId(meta.id)
315297
if (nodeId !== node.localNodeId) {
316-
data.from = nodeId
298+
data.by = nodeId
317299
}
318300

319301
api.addTimelineEvent({
320302
layerId: actionLayerId,
321-
event: { time, data }
303+
event: {
304+
title,
305+
subtitle: action.type,
306+
time,
307+
data
308+
}
322309
})
323310
}
324311
}
@@ -330,6 +317,7 @@ export const devtools = {
330317
api.addTimelineEvent({
331318
layerId: userLayerId,
332319
event: {
320+
title: 'Changed',
333321
time: Date.now(),
334322
data: {
335323
userId,
@@ -353,6 +341,8 @@ export const devtools = {
353341
api.addTimelineEvent({
354342
layerId: cleanLayerId,
355343
event: {
344+
title: 'Cleaned',
345+
subtitle: action.type,
356346
time: Date.now(),
357347
data: { action, meta }
358348
}

0 commit comments

Comments
 (0)