Sha256: 11f19449c66004d9d8df9f040034a7fb663a3f6ca0d982d7a5dbb151fe2431cd

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

class Trix.Watchdog.Recording
  @fromJSON: ({snapshots, frames}) ->
    new this snapshots, frames

  constructor: (@snapshots = [], @frames = []) ->

  recordSnapshot: (snapshot) ->
    snapshotJSON = JSON.stringify(snapshot)
    if snapshotJSON isnt @lastSnapshotJSON
      @lastSnapshotJSON = snapshotJSON
      @snapshots.push(snapshot)
      @recordEvent(type: "snapshot")

  recordEvent: (event) ->
    frame = [@getTimestamp(), @snapshots.length - 1, event]
    @frames.push(frame)

  getSnapshotAtIndex: (index) ->
    @snapshots[index] if index >= 0

  getSnapshotAtFrameIndex: (frameIndex) ->
    snapshotIndex = @getSnapshotIndexAtFrameIndex(frameIndex)
    @getSnapshotAtIndex(snapshotIndex)

  getTimestampAtFrameIndex: (index) ->
    @frames[index]?[0]

  getSnapshotIndexAtFrameIndex: (index) ->
    @frames[index]?[1]

  getEventAtFrameIndex: (index) ->
    @frames[index]?[2]

  getEventsUpToFrameIndex: (index) ->
    frame[2] for frame in @frames.slice(0, index + 1)

  getFrameCount: ->
    @frames.length

  getTimestamp: ->
    new Date().getTime()

  truncateToSnapshotCount: (snapshotCount) ->
    offset = @snapshots.length - snapshotCount
    return if offset < 0

    frames = @frames
    @frames = for [timestamp, index, event] in frames when index >= offset
      [timestamp, index - offset, event]

    @snapshots = @snapshots.slice(offset)

  toJSON: ->
    {@snapshots, @frames}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vapid-0.1.3 lib/vapid/vendor/trix/src/trix/inspector/watchdog/recording.coffee
vapid-0.1.2 lib/vapid/vendor/trix/src/trix/inspector/watchdog/recording.coffee
vapid-0.1.1 lib/vapid/vendor/trix/src/trix/inspector/watchdog/recording.coffee
vapid-0.1.0 lib/vapid/vendor/trix/src/trix/inspector/watchdog/recording.coffee