UNPKG

tiny-essentials

Version:

Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.

55 lines 2.19 kB
export default SaveAsync; /** * Class representing an asynchronous save system with callback support. * * This class is designed to handle database operations asynchronously and supports * adding multiple operations to a queue, as well as running callbacks after each action. * * @class SaveAsync */ declare class SaveAsync { /** * Creates an instance of SaveAsync. * * @param {object} db - The database reference to interact with (e.g., Firebase or other DB). */ constructor(db: object); db: object; list: any[]; callbacks: {}; using: boolean; /** * Registers a callback to be run when a specific action type is executed. * * @param {string} where - The action type (e.g., "set", "push", etc.). * @param {Function} callback - The callback function to run when the action is performed. * @returns {boolean} Returns `true` if the callback is successfully registered. */ on(where: string, callback: Function): boolean; /** * Runs all callbacks associated with a specific action type. * * @param {string} type - The action type (e.g., "set", "push", etc.). * @param {any} data - The data passed to the callback(s). * @param {string} [where] - The location (optional) where the action was performed. */ _runCallbacks(type: string, data: any, where?: string): void; /** * Processes the queued actions and executes them one by one. * * Each action in the queue is processed asynchronously. Once one action completes, * the next action in the queue is triggered. */ action(): void; /** * Inserts a new action into the queue. * * The action will be executed when the system is ready (i.e., when the queue is not in use). * * @param {object} [data={}] - The data to be saved (optional). * @param {string} [type='set'] - The type of the database action (e.g., 'set', 'push', etc.). * @param {string|null} [where=null] - The location where the data should be stored (optional). */ insert(data?: object, type?: string, where?: string | null): void; } //# sourceMappingURL=saveAsync.d.mts.map