How to: assign variables from JS in VBCS

Sumedh Chakravorty
2 min readDec 18, 2019

--

In VBCS you should not assign variables in JS, but some times we need to!. Let’s say you are subscribing to WebSocket data in your JS PageModule and you need to assign that data to a VBCS variable so that you could use it in your application. Or, you have an event listener which you are subscribing in your PageModule and you want to pass down the value to a VBCS variable when the event handler is invoked. In both the cases, you should fire a custom event from your JS, with the data you want to pass (optionally). Lets see how.

Step 1: Create the eventHelper in your PageModule

When PageModules are created, they are injected with context in their constructor. The context has a utility method called getEventHelper which will give you an instance of EventHelper.

save the event helper reference in this.eventHelper

Step 2: Fire custom event

using the this.eventHelper you can now dispatch custom events from your PageModule. use the this.eventHelper.fireCustomEvent(name, payload) to dispatch it. name must be a unique identifier for the event (will be used later to add action chain listener), payload is optional where you can pass any value (eg. data from WS calls or listener callback data etc).

Step 3: Declare Custom event on your page

You need to declare the event before adding listeners to it. use the same name that was used while dispatching it from PageModule. Optionally, you can provide payload shape/type as well.

Step 4: Add a listener to invoke action chain

Final step would be to invoke the action chain and pass the data (if required). Switch to the Event Listeners tab and add a new listener to the newly created custom event. Map the $event with the action chain input if required. The listener should appear under the Custom Event Listeners tab.

Version

VBCS: 19.3.1

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Sumedh Chakravorty
Sumedh Chakravorty

Written by Sumedh Chakravorty

Product Manager for Oracle Visual Builder.I talk about Oracle JET, VBCS, React, React Native, Spring Boot. Views are my own.

No responses yet

Write a response