cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Kran
Helper II
Helper II

notifyOutputChanged: () => void ?

In the index.ts file of a PCF project, there is a init method that takes a parameter "notifyOutputChanged".

 

I understand it is a callback method that we need to call to notify the runtime framework that there are changes in the component.

 

However, since I´m new to Typescript, I´m trying to understand what the syntax of this parameter does which I find confusing.

 

notifyOutputChanged is a arrow function where the body just returns void? Why is notifyOutputChanged returning void here?

 

 

 

 

 

Kran_0-1626960809475.png

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
cchannon
Memorable Member
Memorable Member

The type designation at the end of that arrow function does not refer to setting anything to void; it refers to the return value type. 

() => void

 simply means that it is a function. You call it with no input parameters whatsoever, and it will do something, but it will never return you a value. In this case, the "do something" is that it will call getOutputs.

View solution in original post

DianaBirkelbach
Super User
Super User

Hi    @Kran  ,  
Something similar, but, to be more precise, what you see there is not an arrow function, it's not the function definition, but the signature/the type of the parameter.

The init method has 4 parameters, and because it's TypeScript each type must be specified: context of type ComponentFramework.Context<IInputs>, notityOutputChanged of type function....


init (
context: ComponentFramework.Context<IInputs>,
notifyOutputChanged: () => void,
state: ComponentFramework.Dictionary,
container:HTMLDivElement )

The notifyOutputChanged is a function with no parameters which doesn't return anything, and that's how you declare that in typescript.


In case you would like to read more about function types in TypeScript, you could have a look here: https://www.typescriptlang.org/docs/handbook/2/functions.html#function-type-expressions

 

Kind regards,

Diana

 

Kind regards,
Diana
----------
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

5 REPLIES 5
DianaBirkelbach
Super User
Super User

Hi @Kran , 

 

The notifyOutputChanged does nothing but the notification. The values will be passed through the getOutputs method, which will be called by the framework after that (so async).  From the getOutputs you need to return the changed data.
You can read more in the docs: https://docs.microsoft.com/en-us/powerapps/developer/component-framework/custom-controls-overview?WT...

Hope this helps!

Kind regards,

Diana

Kind regards,
Diana
----------
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Thanks @DianaBirkelbach for quick response!

What I´m trying to understand is how it´s possible that the argument notifyOutputChanged is able to notify the framework to call the method getOutputs() when its expression just sets the function to void?

 

I mean - how can a callback just containing void invoke something else? I feel I´m missing something easy here... 😀

 

cchannon
Memorable Member
Memorable Member

The type designation at the end of that arrow function does not refer to setting anything to void; it refers to the return value type. 

() => void

 simply means that it is a function. You call it with no input parameters whatsoever, and it will do something, but it will never return you a value. In this case, the "do something" is that it will call getOutputs.

View solution in original post

If I understand correctly, when we use the arrow function as a argument in a method as above - then the things right of the arrow defines the return type. 

 

Otherwise, the things right of the arrow defines the body of the function.

 

Is that correct?

 

Super thanks for the replies 😀

DianaBirkelbach
Super User
Super User

Hi    @Kran  ,  
Something similar, but, to be more precise, what you see there is not an arrow function, it's not the function definition, but the signature/the type of the parameter.

The init method has 4 parameters, and because it's TypeScript each type must be specified: context of type ComponentFramework.Context<IInputs>, notityOutputChanged of type function....


init (
context: ComponentFramework.Context<IInputs>,
notifyOutputChanged: () => void,
state: ComponentFramework.Dictionary,
container:HTMLDivElement )

The notifyOutputChanged is a function with no parameters which doesn't return anything, and that's how you declare that in typescript.


In case you would like to read more about function types in TypeScript, you could have a look here: https://www.typescriptlang.org/docs/handbook/2/functions.html#function-type-expressions

 

Kind regards,

Diana

 

Kind regards,
Diana
----------
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,906)