Skip to content

Commit 477b000

Browse files
committed
move timestamp to payload from panel instance
1 parent 601bf70 commit 477b000

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

src/js/bundle/jsdiff-panel.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/jsdiff-devtools.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,14 @@ function jsdiff_devtools_extension_api() {
127127

128128
Object.assign(console, {
129129
diff: (left, right) =>
130-
post(right === undefined ? { push: left } : { left, right }),
131-
diffLeft: (left) => post({ left }),
132-
diffRight: (right) => post({ right }),
133-
diffPush: (push) => post({ push }),
130+
post(
131+
right === undefined
132+
? { push: left, timestamp: Date.now() }
133+
: { left, right, timestamp: Date.now() }
134+
),
135+
diffLeft: (left) => post({ left, timestamp: Date.now() }),
136+
diffRight: (right) => post({ right, timestamp: Date.now() }),
137+
diffPush: (push) => post({ push, timestamp: Date.now() }),
134138
});
135139

136140
console.debug(

src/js/view/panel.vue

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
</template>
5959

6060
<script setup lang="ts">
61-
import { computed, onMounted, reactive, ref } from 'vue';
61+
import { computed, onMounted, onUnmounted, reactive, ref } from 'vue';
6262
import packageJson from '../../../package.json';
6363
import * as jsondiffpatch from 'jsondiffpatch';
6464
import 'jsondiffpatch/dist/formatters-styles/html.css';
@@ -80,19 +80,19 @@ const state = reactive({
8080
now: appStartTimestamp,
8181
});
8282
interface CompareState {
83-
timestamp: number;
83+
timestamp?: number;
8484
left?: unknown;
8585
right?: unknown;
8686
}
8787
const compare = ref<CompareState>({
88-
timestamp: appStartTimestamp,
88+
timestamp: undefined,
8989
left: undefined,
9090
right: undefined,
9191
});
9292
let timer: number;
9393
9494
const lastUpdated = computed(() =>
95-
timeFromNow(compare.value.timestamp, state.now)
95+
compare.value.timestamp ? timeFromNow(compare.value.timestamp, state.now) : ''
9696
);
9797
9898
const hasBothSides = computed(
@@ -135,6 +135,10 @@ onMounted(() => {
135135
});
136136
});
137137
138+
onUnmounted(() => {
139+
window.clearInterval(timer);
140+
});
141+
138142
const onToggleUnchanged = () => {
139143
if (deltaEl.value) {
140144
state.showUnchanged = !state.showUnchanged;
@@ -164,8 +168,6 @@ const onCopyDelta = () => {
164168
};
165169
166170
function $_restartLastUpdated() {
167-
compare.value.timestamp = Date.now();
168-
169171
window.clearInterval(timer);
170172
timer = window.setInterval(() => {
171173
state.now = Date.now();
@@ -176,11 +178,15 @@ function $_onDiffRequest({
176178
left,
177179
right,
178180
push,
181+
timestamp,
179182
}: {
180183
left?: unknown;
181184
right?: unknown;
182185
push?: unknown;
186+
timestamp?: number;
183187
}) {
188+
compare.value.timestamp = timestamp || Date.now();
189+
184190
if (push) {
185191
compare.value.left = compare.value.right;
186192
compare.value.right = push;

0 commit comments

Comments
 (0)