get-svelte
Version:
A simple, powerful state management library for Svelte applications, inspired by GetX for Flutter
58 lines (57 loc) • 2.17 kB
TypeScript
/**
* Abstract base class for controllers in the Get system.
* Provides state management functionality and listener management for reactive updates.
* Controllers created from this base class can be registered and managed by the Get class.
*/
export default abstract class GetxController {
/**
* Collection of listener functions that will be called when state changes
* @private
*/
private listeners;
/**
* Registers a new listener function to be notified of state changes
* @param {Function} listener - The callback function to execute when state changes
*/
addListener(listener: () => void): void;
/**
* Removes a previously registered listener function
* @param {Function} listener - The callback function to remove from listeners
*/
removeListener(listener: () => void): void;
/**
* Notifies all registered listeners of a state change
* Should be called by subclasses when their state changes
* @protected
*/
protected notifyListener(): void;
/**
* Lifecycle hook called when the controller is initialized
* Can be overridden by subclasses to perform initialization tasks
* @protected
*/
protected onInit(): void;
/**
* Lifecycle hook called when the controller is closed/deleted
* Can be overridden by subclasses to perform cleanup tasks
*/
onClose(): void;
/**
* Reference to the InnerCaller instance that manages this controller's lifecycle
* @private
*/
private innerCaller;
/**
* Sets the inner caller for this controller
* This is typically called by the Get class when registering the controller
* @param {InnerCaller} innerCaller - The inner caller instance
* @param {Function} onDisposeCallBack - Callback function to execute when the controller is disposed
*/
setInnerCaller(innerCaller: any, onDisposeCallBack: Function): void;
/**
* Disposes of this controller instance
* Triggers the disposal callback which typically removes it from the Get registry
* @returns {any} Result of the disposal callback
*/
dispose(): any;
}