overview
The platform will call a set of methods on a component in order to manage it through its lifecycle. We refer to these methods as lifecycle methods. Lifecyle methods are called using the dependency injection framework.
Note: during a component's lifetime, it may happen that is lifecycle methods get wrapped. For instance, the $process method may get replaced by another implementation that calls the $process. This means that developers cannot relay on this.$process being the same function that was placed there by the constructor.
Lifecycle Methods
- $css -$css is similar to $libraries above. It returns any urls that represent style sheets that need to be loaded
- $copy - $copy is a method that is called when a component is copied by the
user, typically by click ctrl-c. The method should return a copy of the
config that should be placed in the clipboard. This is useful if the
copied config should be different from the config of the ctrl.
if this method is not present, the config that is copied to the clipboard matches the config of the component in the blog or workspace that is being copied. - $html - For components that need to insert html into the page, the $html method needs to be implemented.
- $libraries - for components that are dependent on libraries (not other modules) that need to be loaded before the component can function, you can implement a method named "$libraries" that returns an array of urls that need to be loaded.
- $process - The $process method is called right after a components html has been inserted. If the component has no html,
the $process method is still called. For components that retrieve data or some other non-visual action, the $process
method is the primary method that implements the components functionality.
For components that have more complex html, the process method can be used to insert html into its html container. In such a case, the $process method should use the $id service to get the id of the inserted html. - $imports When a component uses data that is provided by another component, such as a chart displaying data provided by a data component, the component gets acces to that data through the data bus. If a component is dependent on data on the bus, it should implement the $imports method. This method returns an array of data names that it is dependent on. This enables the platform to track dependencies between components.
- $remove - The $remove method is called when the component is removed from the page. This gives the component a chance to clean itself up by removing its html and any data it may have place on the data bus.
- $exports - If a component puts data on the data bus, it should implement the $exports method, which should return an array of data names of the datasets it places on the data bus.
- $update - Whenever data on the data bus changes, the platform calls $imports on all components. For any component that imports the data that has changed on the bus, the $update method is called.
- $select - The $select method is called when the component is selected by the user in the page. This gives the component the chance to highlight itself in the page as well as display any controls to edit the component. It should have an argument named "selected" that is passed to it. When the $select is not present, the component is not selectable.
- $inline - The $inline method is used to control the buttons and controls that appear when a component is selected. (if the component has such controls). It should be passed a boolean argument named "open" that indicates whether to open or close the controls. In general, a component should open these controls whenever its $select method is called with selected set to true. However, occasionally, the framework needs to hide the controls, so this method is made available for that purpose.