We can read about the architecture and the life cycle of the Power Apps component here.
Check the screencast – PowerApps Component Life Cycle
Let us see it in action using a sample project.
Launching the test harness, we can see the init executed followed by updateView.
Making any change in the component’s form factor, width, height, or Data Inputs property triggers the updateView method.
Now let us update the index.ts and add a textElement along with an event listener for its change event.
Inside the test harness, when we change the Value of the sampleProperty, if we want the value of the textElement to be updated, we need to use the updateView method to fetch the changed value from the bound sample property field and reflect this new data in the UI.
We can get the value of the sampleProperty from the context and use it to set the textElement value as shown below.
Now let us do the opposite, let us change the value inside the textElement. Here as expected none of the methods triggers.
Here we need to call the notifyOutputChanged method, to notify the host that the component’s output has changed.
On calling notifyOutputChanged, the framework runtime will first call getOutputs to get the value of the bound properties of the component, and then notifies the host.
The host will perform the validation and if the output received is valid it will call the updateView.
But before we do that let us first try setting the value of the sampleProperty in the change event handler of the textElement. Here on changing the value inside the text box, we can see only the change event handler is triggered. No other methods are triggered here as expected.
There is no update in the value of the bound sampleProperty.
This is because we need to call the notifyOutputChanged method to let the host know about the changes made in the value inside the text box.
On calling the notifyOutputChanged and changing the text value this time, we can see the getOutputs being called.
The value remains the same for the bound property and updateView method is not called as our getOutputs method was not returning anything.
Let us update the getOutputs method to return the sampleProperty having the text value.
On changing the textElement value this time getOutputs is called, followed by updateView.
- To notify the host, about the user changes in the UI ècall notifyOutputChanged
è the framework will call the getOutputs
è followed by èupdateView
- Host changes the data/properties èupdateView will be called è context passed è we can update the UI as per our requirements
Check the following links to understand more about the life cycle –
To learn about PCF –
Getting started with PCF Custom Controls by Danish Naglekar
PCF Academy by Andrew Butenko –https://www.youtube.com/watch?v=YJ9hrKxAhTU&list=PL0WiRFWRFGlQr5tGZdUGUlyTl7Gi1Wb_K
Hope it helps..