alpha

Explains the structure of Power Apps code components, covering the manifest, TypeScript implementation and resources, for developers building custom controls.
description: 'Understanding code components structure and implementation'
applyTo: '**/*.{ts,tsx,js,json,xml,pcfproj,csproj}'
Code components are a type of solution component that can be included in a solution file and imported into different environments. They can be added to both model-driven and canvas apps.
Code components consist of three elements:
Note: The definition and implementation of code components using Power Apps component framework is the same for both model-driven and canvas apps. The only difference is the configuration part.
The manifest is the ControlManifest.Input.xml metadata file that defines a component. It is an XML document that describes:
field or a datasetWhen a user configures a code component, the data in the manifest file filters the available components so that only valid components for the context are available for configuration. The properties defined in the manifest file are rendered as configuration columns so that users can specify values. These property values are then available to the component at runtime.
More information: [Manifest schema reference](https://learn.microsoft.com/en-us/power-apps/developer/component-framework/manifest-schema-reference/)
Code components are implemented using TypeScript. Each code component must include an object that implements the methods described in the code component interface. The [Power Platform CLI](https://learn.microsoft.com/en-us/power-platform/developer/cli/introduction) auto-generates an index.ts file with stubbed implementations using the pac pcf init command.
The component object implements these lifecycle methods:
When the page loads, the application creates an object using data from the manifest:
var obj = new <"namespace on manifest">.<"constructor on manifest">();
Example:
var controlObj = new SampleNameSpace.LinearInputComponent();
The page then initializes the component:
controlObj.init(context, notifyOutputChanged, state, container);
Init Parameters:
| Parameter | Description |
|-----------|-------------|
| context | Contains all information about how the component is configured and all parameters. Access input properties via context.parameters.<property name from manifest>. Includes Power Apps component framework APIs. |
| notifyOutputChanged | Alerts the framework whenever the component has new outputs ready to be retrieved asynchronously. |
| state | Contains component data from the previous page load if explicitly stored using setControlState method. |
| container | An HTML div element to which developers can append HTML elements for the UI. |
When a user interacts with your component to change data, call the notifyOutputChanged method passed in the init method. The platform responds by calling the getOutputs method, which returns values with the changes made by the user. For a field component, this would typically be the new value.
If the platform changes the data, it calls the updateView method of the component and passes the new context object as a parameter. This method should be implemented to update the values displayed in the component.
When a user navigates away from the page, the code component loses scope and all memory allocated for objects is cleared. However, some methods (like event handlers) may stay and consume memory based on browser implementation.
Best Practices:
setControlState method to store information for the next time within the same sessiondestroy method to remove cleanup code such as event handlers when the page closesThe resource node in the manifest file refers to the resources that the component requires to implement its visualization. Each code component must have a resource file to construct its visualization. The index.ts file generated by the tooling is a code resource. There must be at least 1 code resource.
You can define additional resource files in the manifest:
More information: [resources element](https://learn.microsoft.com/en-us/power-apps/developer/component-framework/manifest-schema-reference/resources)
© GitHub, Inc. · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com


Sea turtle carrying floating film studio island
Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.
image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost
Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.
video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

Cozy Pixel Art Farm Island Village
Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.
image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape
Loading reviews…
Loading comments…