INNER CODE UNIT · TypeScript

bind

f5/unovis · packages/mcp/src/codegen/index.ts:304

  const bind = (p: Prop): string => {
    if (p.expr.startsWith("'")) return ` ${p.name}=${p.expr.replace(/'/g, '"')}`
    return framework === 'svelte' ? ` ${p.name}={${p.expr}}` : ` :${p.name}="${p.expr.replace(/"/g, "'")}"`
  }
  const dataBind = framework === 'svelte' ? ' {data}' : ' :data="data"'
  const heightBind = framework === 'svelte' ? `height={${spec.height}}` : `:height="${spec.height}"`

  const children = [
    ...components.map(c => `<${tag(c.type)}${dataBind}${c.props.map(bind).join('')} />`),
    ...(xAxis ? [`<${tag('Axis')}${xAxis.map(bind).join('')} />`] : []),
    ...(yAxis ? [`<${tag('Axis')}${yAxis.map(bind).join('')} />`] : []),
  ]

  const used = [`Vis${containerName(spec)}`, ...components.map(c => tag(c.type)), ...(xAxis || yAxis ? ['VisAxis'] : [])]
  const pkg = framework === 'svelte' ? '@unovis/svelte' : '@unovis/vue'
  const script = `import { ${[...new Set(used)].sort().join(', ')} } from '${pkg}'\n\n${preamble(emit, `const data = ${dataLiteralFor(spec.data)}`, true)}`

  if (framework === 'svelte') {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…