Reusable Code in OmniScript - Lightning Web Components

Lightning Web Components are great for breaking down layouts and interfaces into small, reusable pieces.

Step 1:

Create Lightning Web Component BaseComponent is via a BaseComponent folder in the standard LWC folder of a SFDX project.

Export and Import

Inside baseComponent.js, we can define reusable functions and export them for use in other components. In the example below, I define a function called convertToArray and export it

BaseComponent

import { LightningElement } from 'lwc';
import { OmniscriptBaseMixin } from 'vlocity_cmt/omniscriptBaseMixin';
export default class BaseComponent extends OmniscriptBaseMixin(LightningElement) {
}
export function convertToArray(obj) {
if (obj instanceof Array) {
return obj;
} else {
return [obj];
}
}

Child Component

import { LightningElement,api,track} from 'lwc';
import { OmniscriptBaseMixin } from 'vlocity_cmt/omniscriptBaseMixin';
import { convertToArray } from 'c/baseComponent';
export default class ChildComponent extends OmniscriptBaseMixin(LightningElement) {
    connectedCallback() {
        //use convertToArray function here
        convertToArray(obj);
    }
}

 

Comments

Popular posts from this blog

Communicating between Independent LWC in Omniscript

JWT (JSON Web Token)

Efficient way to write apex code

Import third party JS library in OmniScript Custom Lightning Web Components

Server-Side Document Generation

Salesforce Best Features available

Mastering the Matrix: Top 10 Advanced Salesforce Integration Interview Questions