Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

The interceptor is just a record in advanced configuration options. The record name has to start with a prefix pfxInterceptor_ and then it has to continue with actual interceptor name. Correct name is for example pfxInterceptor_myFirstExperiment.

The record cannot be empty, in such a case Unity will show you an error: “The interceptor with name pfxInterceptor_myFirstExperiment was not found”

Basic

First step

Interceptors are written in plain JavaScript.

The main part of the interceptor are exported constants which contains a function.

The simplest possible example is this:

export const quotesDetailNew = () => {
  console.log('Test 1');
};

Code above will display message Test 1 at Console tab in web browser developer tools:

The name of the constant quotesDetailNew, determines where and when the code will be triggered. List of possible names is in Unity under System Configuration / Interceptors. When you are exporting non existing name from your interceptor, for example because of typo, Unity will display an error with unknown method names.

Each named constant can exists in two variants, one is for PRE action with a suffix Pre and second one for POST action where the suffix is omitted.

export const quotesDetailNewPre = () => {
  console.log('This will be triggered before quotesDetailNew');
};

export const quotesDetailNew = () => {
  console.log('Test 1');
};

You don't need to implement both variants. In some cases only PRE action has a sense, for others it is only POST action. TBD - Explain where to use PRE & POST

Function parameters

When Unity triggers a function which is in your exported constant, it will pass an object parameter to the function. This object has properties, which contains API functions and data related to the action which was triggered.

export const quotesDetailNew = (parameter) => {
  console.log(parameter);
};

  • No labels