@vue/reactivity-transform
@vue/reactivity-transform
Last updated 3 years ago by yyx990803 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @vue/reactivity-transform 
SYNC missed versions from official npm registry.

@vue/reactivity-transform

⚠️ This is experimental and the proposal has been dropped. The feature is now marked as deprecated and will be removed from Vue core in 3.4.

See reason for deprecation here.

Basic Rules

  • Ref-creating APIs have $-prefixed versions that create reactive variables instead. They also do not need to be explicitly imported. These include:
    • ref
    • computed
    • shallowRef
    • customRef
    • toRef
  • $() can be used to destructure an object into reactive variables, or turn existing refs into reactive variables
  • $$() to "escape" the transform, which allows access to underlying refs
import { watchEffect } from 'vue'

// bind ref as a variable
let count = $ref(0)

watchEffect(() => {
  // no need for .value
  console.log(count)
})

// assignments are reactive
count++

// get the actual ref
console.log($$(count)) // { value: 1 }

Macros can be optionally imported to make it more explicit:

// not necessary, but also works
import { $, $ref } from 'vue/macros'

let count = $ref(0)
const { x, y } = $(useMouse())

Global Types

To enable types for the macros globally, include the following in a .d.ts file:

/// <reference types="vue/macros-global" />

API

This package is the lower-level transform that can be used standalone. Higher-level tooling (e.g. @vitejs/plugin-vue and vue-loader) will provide integration via options.

shouldTransform

Can be used to do a cheap check to determine whether full transform should be performed.

import { shouldTransform } from '@vue/reactivity-transform'

shouldTransform(`let a = ref(0)`) // false
shouldTransform(`let a = $ref(0)`) // true

transform

import { transform } from '@vue/reactivity-transform'

const src = `let a = $ref(0); a++`
const {
  code, // import { ref as _ref } from 'vue'; let a = (ref(0)); a.value++"
  map
} = transform(src, {
  filename: 'foo.ts',
  sourceMap: true,

  // @babel/parser plugins to enable.
  // 'typescript' and 'jsx' will be auto-inferred from filename if provided,
  // so in most cases explicit parserPlugins are not necessary
  parserPlugins: [
    /* ... */
  ]
})

Options

interface RefTransformOptions {
  filename?: string
  sourceMap?: boolean // default: false
  parserPlugins?: ParserPlugin[]
  importHelpersFrom?: string // default: "vue"
}

transformAST

Transform with an existing Babel AST + MagicString instance. This is used internally by @vue/compiler-sfc to avoid double parse/transform cost.

import { transformAST } from '@vue/reactivity-transform'
import { parse } from '@babel/parser'
import MagicString from 'magic-string'

const src = `let a = $ref(0); a++`
const ast = parse(src, { sourceType: 'module' })
const s = new MagicString(src)

const {
  rootRefs, // ['a']
  importedHelpers // ['ref']
} = transformAST(ast, s)

console.log(s.toString()) // let a = _ref(0); a.value++

Current Tags

  • 3.4.0-alpha.1                                ...           alpha (a year ago)
  • 3.3.0-beta.5                                ...           beta (2 years ago)
  • 3.3.13                                ...           latest (a year ago)

57 Versions

  • 3.3.13                                ...           a year ago
  • 3.3.12                                ...           a year ago
  • 3.3.11                                ...           a year ago
  • 3.3.10                                ...           a year ago
  • 3.3.9                                ...           a year ago
  • 3.3.8                                ...           a year ago
  • 3.4.0-alpha.1                                ...           a year ago
  • 3.3.7                                ...           a year ago
  • 3.3.6                                ...           a year ago
  • 3.3.5                                ...           a year ago
  • 3.3.4                                ...           2 years ago
  • 3.3.3                                ...           2 years ago
  • 3.3.2                                ...           2 years ago
  • 3.3.1                                ...           2 years ago
  • 3.3.0                                ...           2 years ago
  • 3.3.0-beta.5                                ...           2 years ago
  • 3.3.0-beta.4                                ...           2 years ago
  • 3.3.0-beta.3                                ...           2 years ago
  • 3.3.0-beta.2                                ...           2 years ago
  • 3.3.0-beta.1                                ...           2 years ago
  • 3.3.0-alpha.13                                ...           2 years ago
  • 3.3.0-alpha.12                                ...           2 years ago
  • 3.3.0-alpha.11                                ...           2 years ago
  • 3.3.0-alpha.10                                ...           2 years ago
  • 3.3.0-alpha.9                                ...           2 years ago
  • 3.3.0-alpha.8                                ...           2 years ago
  • 3.3.0-alpha.7                                ...           2 years ago
  • 3.3.0-alpha.6                                ...           2 years ago
  • 3.3.0-alpha.5                                ...           2 years ago
  • 3.3.0-alpha.4                                ...           2 years ago
  • 3.3.0-alpha.3                                ...           2 years ago
  • 3.3.0-alpha.2                                ...           2 years ago
  • 3.3.0-alpha.1                                ...           2 years ago
  • 3.2.47                                ...           2 years ago
  • 3.2.46                                ...           2 years ago
  • 3.2.45                                ...           2 years ago
  • 3.2.44                                ...           2 years ago
  • 3.2.43                                ...           2 years ago
  • 3.2.42                                ...           2 years ago
  • 3.2.41                                ...           2 years ago
  • 3.2.40                                ...           2 years ago
  • 3.2.39                                ...           2 years ago
  • 3.2.38                                ...           2 years ago
  • 3.2.37                                ...           3 years ago
  • 3.2.36                                ...           3 years ago
  • 3.2.35                                ...           3 years ago
  • 3.2.34                                ...           3 years ago
  • 3.2.34-beta.1                                ...           3 years ago
  • 3.2.33                                ...           3 years ago
  • 3.2.32                                ...           3 years ago
  • 3.2.31                                ...           3 years ago
  • 3.2.30                                ...           3 years ago
  • 3.2.29                                ...           3 years ago
  • 3.2.28                                ...           3 years ago
  • 3.2.27                                ...           3 years ago
  • 3.2.26                                ...           3 years ago
  • 3.2.25                                ...           3 years ago
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (5)
Dev Dependencies (2)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE