- First, let's talk about variables (i.e.
let
andvar
) separately from constants (i.e.const
). - The following rules only apply to variables declared at the root level of a
createClass
factory function. That means any variable declared in a nested function,for
loop,if
statement, etc. won't be transformed by the compiler. - Variables are reactive. Referencing them in a
computed
orwatch
callback will cause the callback to rerun when the variable is re-assigned. - Variables are deeply reactive. Assigning an object literal, array literal,
new Map()
, ornew Set()
will make that data structure deeply reactive. - Variables are bound to the reactive instance when you return them. This means any assignments to the variable will be reflected in the reactive instance, and the variable can be subscribed to (e.g. by a React component). It's a one-way binding, so you can rest assured that the variable won't be mutated from outside the
createClass
factory function.
- Once again, the following rules only apply to variables declared at the root level of a
createClass
factory function. - Since constants cannot be re-assigned, they are not reactive, but their values may be. For example, initializing a constant with an object literal, array literal,
new Map()
, ornew Set()
will make that data structure deeply reactive.