120 | | The `TodoList` component notifies the observers inside the `add()` method by iterating over `self.observers` and calling the `todo_added()` method for each. This works because the `observers` attribute is a [http://users.rcn.com/python/download/Descriptor.htm descriptor]: When it is accessed, it finds all registered components that declare to extend the extension point. For each of those components, it gets the instance from the component manager, potentially activating it if it is getting accessed for the first time. |
121 | | |
122 | | '''Note:''' Component classes are registered at module load time. A specific component is instantiated on first use, either when accessing an extension point for an interface implemented by that component, or when calling the component constructor as `ComponentName(self.compmgr)`. The former use requires the component to be enabled in the `[components]` section of [wiki:TracIni trac.ini], while in the latter use the component will be instantiated regardless. Note that in this last case, even though the component is instantiated, it's only made available through the extension points if it's enabled in `[components]`. |
| 120 | The `TodoList` component notifies the observers inside the `add()` method by iterating over `self.observers` and calling the `todo_added()` method for each. This works because the `observers` attribute is a [http://users.rcn.com/python/download/Descriptor.htm descriptor]: When it is accessed, it finds all ''enabled'' components that declare to extend the extension point. For each of those components, it gets the instance from the component manager, potentially activating it if it is getting accessed for the first time. |
| 121 | |
| 122 | ''Note:'' Only component classes that are enabled (in the `[components]` section of [wiki:TracIni trac.ini]) will be available when iterating over an extension point (like in the code above). Thus it's ''not enough'' to only instantiate a component (e.g. by calling the component constructor as `ComponentName(self.compmgr)`) but one needs to enable it as well. |