Module Export Syntax
When exporting functions in the following files, we recommend you use the standard export syntax contained in the documentation's code examples:
You can also use other export formats that are part of the ES6 (ES2015) module export syntax. However, the following export formats are not supported in events.js
, data.js
, routers.js
, or SPI code files:
-
Re-exporting a function: Directly re-exporting a function imported from an npm or Velo package. For example, this doesn't work:
Copy1import { myFunction } from 'myPackage';23export const wixMediaManager_onFileUploaded = myFunction;The following alternative syntax is supported:
Copy1import { myFunction } from 'myPackage';23export const wixMediaManager_onFileUploaded = (paramA, paramB) => myFunction(paramA, paramB); -
Dynamic exports: Exports including a dynamic operation or expression that requires execution to resolve. For example, this doesn't work:
Copy1import myPackage from 'my-package';23export const myRouter_Router = myPackage.router((paramA, paramB) => {4// ...5});The following alternative syntax is supported:
Copy1import myPackage from 'my-package';23const functionForExport = myPackage.router((paramA, paramB) => {4// ...5})67export const myRouter_Router = (paramA, paramB) => functionForExport(paramA, ParamB); -
Exports wrapped in objects: Exports where functions are defined as properties of an object. For example, this doesn't work:
Copy1const dataHooks = {2beforeInsert: (paramA, paramB) => {3// ...4}5};67export const MyCollection_beforeInsert = dataHooks.beforeInsert;The following alternative syntax is supported:
Copy1const dataHooks = {2beforeInsert: (paramA, paramB) => {3// ...4}5};67export const MyCollection_beforeInsert = (paramA, paramB) => dataHooks.beforeInsert(paramA, paramB); -
CommonJS exports: Exports in the CommonJS (CJS) format that preceded ES6 (ES2015). For example, this doesn't work:
Copy1module.exports = {2MyCollection_beforeInsert: () => {}3};
Functions exported using a syntax that isn't supported aren't called by the triggering event.