Skip to content

Commit 0ad86eb

Browse files
author
Timothy Johnson
committed
Support $capture_state. Closes #26
1 parent 924fbde commit 0ad86eb

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"rollup": "^1.27.4",
1919
"rollup-plugin-node-resolve": "^5.0.0",
2020
"rollup-plugin-svelte": "^5.1.1",
21-
"svelte": "^3.16.0",
21+
"svelte": "^3.20.1",
2222
"svelte-listener": "git+https://github.com/RedHatter/svelte-listener.git",
2323
"svgexport": "^0.3.2",
2424
"tiny-glob": "^0.2.6",

src/client/index.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import {
22
getNode,
33
addNodeListener,
44
startProfiler,
5-
stopProfiler
5+
stopProfiler,
6+
getSvelteVersion
67
} from 'svelte-listener'
78
import { highlight, startPicker, stopPicker } from './highlight.js'
89

@@ -72,6 +73,24 @@ function clone(value, seen = new Map()) {
7273
}
7374
}
7475

76+
function gte(major, minor, patch) {
77+
const version = (getSvelteVersion() || '0.0.0')
78+
.split('.')
79+
.map(n => parseInt(n))
80+
return (
81+
version[0] > major ||
82+
(version[0] == major &&
83+
(version[1] > minor || (version[1] == minor && version[2] >= patch)))
84+
)
85+
}
86+
87+
let _shouldUseCapture = null
88+
function shouldUseCapture() {
89+
return _shouldUseCapture == null
90+
? (_shouldUseCapture = gte(3, 19, 2))
91+
: _shouldUseCapture
92+
}
93+
7594
function serializeNode(node) {
7695
const serialized = {
7796
id: node.id,
@@ -89,7 +108,11 @@ function serializeNode(node) {
89108
const props = Array.isArray(internal.props)
90109
? internal.props // Svelte < 3.13.0 stored props names as an array
91110
: Object.keys(internal.props)
92-
const ctx = clone(internal.ctx)
111+
let ctx = clone(
112+
shouldUseCapture() ? node.detail.$capture_state() : internal.ctx
113+
)
114+
if (ctx === undefined) ctx = {}
115+
93116
serialized.detail = {
94117
attributes: props.flatMap(key => {
95118
delete ctx[key]

0 commit comments

Comments
 (0)