CorePondContext
The CorePondContext is the foundational component of the Pond Module in the Flood toolkit. It serves as a container and manager for CorePondComponents, which are the building blocks of your application's functionality.
Lifecycle
A CorePondContext follows a specific lifecycle:
- The context is created.
CorePondComponents are registered using theregistermethod.- Once all components are registered, the
loadmethod is called, triggering theonLoadbehavior of each component in the order they were registered.
When using a CorePondContext in the context of a Flutter App or
Automation, it will automatically handle loading your CorePondContext.
There is no need to manually call this yourself.
While resetting is typically handled by the Reset Debug Module, you can manually reset the CorePondContext by calling the reset method:
corePondContext.reset()This will invoke the onReset behavior of each registered component, effectively returning the application to its initial state as if it was never installed.
CorePondComponent
A CorePondComponent represents a specific piece of functionality within your application. While CorePondComponents do not add any functionality by themselves, they provide the mechanism for you to add features to your app in a modular and composable way.
CorePondComponentBehavior
Each CorePondComponent contains CorePondComponentBehaviors that define the component's lifecycle:
onRegister: Called when the component is registered with theCorePondContext. This is where you should perform any initialization that otherCorePondComponents might depend on during their registration.onLoad: Called after allCorePondComponents have been registered and theCorePondContextis loaded. At this point, you can safely locate and interact with other components.onReset: Called when theCorePondContextis reset. Resetting should return the application to its initial state, as if it had never been run before.
Here's an example of a CorePondComponent that simply stores some state you can use across your app.
class HelloWorldPondComponent extends CorePondComponent {
String? name;
@override
List<CorePondComponentBehavior> get behaviors => [
CorePondComponentBehavior(
onLoad: (context, component) => name = 'John Doe',
)
];
String greet() {
return 'Hello ${name ?? 'N/A'}';
}
}Here's how you would register it to your CorePondContext.
final corePondContext = CorePondContext();
await corePondContext.register(HelloWorldPondComponent());Locating Components
You can locate any CorePondComponent registered within a CorePondContext using the locate method:
corePondContext.locate<HelloWorldPondComponent>() // returns the instance of `HelloWorldPondComponent` registered in the context.If there's a possibility that the component hasn't been registered, you can use the locateOrNull method instead:
corePondContext.locateOrNull<MyOtherComponent>()This will return null if no component of the specified type is found.
Pre-Built Components
Flood provides a FloodCoreComponent that includes a set of essential components you can use to quickly set up your application.
Here are the components included:
- Type
- Environment
- Logs
- Drop
- Auth
- Action
- And other minor components that don't currently include documentation.
To use the FloodCoreComponent within your application, simply register it in your CorePondContext.
final corePondContext = CorePondContext();
await corePondContext.register(FloodCoreComponent(...));If you want to exclude some of these components from your context, simply do not register FloodCoreComponent and register the components you want to include.