propertyChanged – A New Lifecycle Method Released With Oracle JET v5

On April 16, 2018, Oracle JET version 5.0.0 has been released (Release Notes). Besides changes in the theming process and some oj-components, the update comes with a handy new ViewModel Lifecycle Listener. The listener is called propertyChanged() and does what the name already tells: It listens to changes of properties of composite components.

Building web applications with modularity is a great way to be able to reuse components and test them easily. Of course, components need to interact with each other and exchange data. This can be tricky if data is fetched asynchronously.

Let’s have a look on an example that demonstrates the issue. The application has a dashboard view and a dialog view called form-modal. form-modal is a composite component. The dialog is within the composite. By clicking a button in the dashboard, the dialog gets opened. Employees data from the dashboard is passed to the dialog.

In the form-modal viewModel you can access the property „persons“ from the context parameter. However, in the moment of the initialization of the form-modal component, the employees are not available yet. And this is where propertyChanged comes into the game.

There’s been some lifecycle methods before:

activated

attached

connected

bindingsApplied

disconnected

These methods fire in different moments in the lifecycle of the component. The newly added propertyChanged() method fires once a property has been changed.