File size: 1,442 Bytes
4d70170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { onUnmounted } from 'vue'
import { BridgeEvents, getStorage } from '@vue-devtools/shared-utils'
import { getBridge } from '@front/features/bridge'
import {
  endTime,
  hiddenLayersPerApp,
  hoverLayerId,
  inspectedEvent,
  inspectedEventData,
  inspectedEventPendingId,
  layersPerApp,
  maxTime,
  minTime,
  screenshots,
  selectedEvent,
  selectedLayer,
  startTime,
  timelineIsEmpty,
  vScrollPerApp,
} from './store'
import { fetchLayers } from './layers'

type ResetCb = () => void

const resetCbs: ResetCb[] = []

export function resetTimeline(sync = true) {
  selectedLayer.value = null
  selectedEvent.value = null
  inspectedEvent.value = null
  inspectedEventData.value = null
  inspectedEventPendingId.value = null
  layersPerApp.value = {}
  vScrollPerApp.value = {}
  hoverLayerId.value = null
  timelineIsEmpty.value = true
  screenshots.value = []

  resetTime()

  if (sync) {
    getBridge().send(BridgeEvents.TO_BACK_TIMELINE_CLEAR)
  }

  // Layers
  fetchLayers()
  hiddenLayersPerApp.value = getStorage('hidden-layers', {})

  for (const cb of resetCbs) {
    cb()
  }
}

export function resetTime() {
  const now = 0
  minTime.value = startTime.value = now - 1_000_000
  maxTime.value = endTime.value = now
}

export function onTimelineReset(cb: ResetCb) {
  onUnmounted(() => {
    const index = resetCbs.indexOf(cb)
    if (index !== -1) {
      resetCbs.splice(index, 1)
    }
  })

  resetCbs.push(cb)
}