AUR0506

Error Message

AUR0506: Invalid callback for @watch decorator: <callback>

Where <callback> represents the value that was provided as the callback but is not a function.

Description

This error occurs when using the @watch decorator in a view model, but the provided callback (the function that should execute when the watched property changes) is not actually a function type at runtime. The @watch decorator requires a valid function to call when changes are detected.

Cause

  1. Incorrect Callback Type: The most common cause is providing a value that is not a function as the callback argument to @watch. This could be a typo in a function name (string), a property that isn't a function, null, undefined, etc.

  2. Callback Not Defined: The function specified as the callback might not be defined on the view model class, or it might be misspelled.

  3. Conditional Assignment: The property intended to hold the callback function might be conditionally assigned, and @watch is evaluated when the property holds a non-function value.

The @watch decorator can be used in several ways:

  • @watch(expression): Decorating a method directly. The method itself is the callback.

  • @watch(expression, callbackFn): Decorating the class. callbackFn must be a function.

  • @watch(callbackFn): Decorating the class. Watches the class instance, callbackFn must be a function.

  • @watch(objectProperty): Decorating a callback method. objectProperty expression is watched.

This error typically relates to the forms where an explicit callback function is provided or expected.

Solution

  1. Verify Callback is a Function: Ensure that the value passed as the callback to @watch is indeed a function defined on your view model class or a valid imported function.

  2. Check Spelling: Double-check the spelling of the callback function name provided to @watch or the name of the decorated method.

  3. Ensure Definition: Confirm that the callback function is correctly defined within the view model class.

  4. Use Correct Decorator Syntax: Ensure you are using the @watch decorator syntax correctly for your intended use case (decorating a method vs. decorating a class).

Example

Debugging Tips

  • Identify the component (<ControllerName>) and the specific @watch decorator causing the issue.

  • Examine the arguments passed to the @watch decorator.

  • If a callback name (string) is provided, verify that a method with that exact name exists on the class.

  • If a function reference is provided directly, ensure it's correctly defined and imported if necessary.

  • Use console.log(typeof this.callbackMethodName) in the constructor or binding lifecycle hook to check the type of the intended callback just before @watch is likely processed.

  • Temporarily remove the problematic @watch decorator to confirm it's the source of the error.

Last updated

Was this helpful?