managarten/apps/context/apps/mobile/utils/debounce.ts
Till-JS bb0e0cf5cb 🚚 feat(context): integrate context app into monorepo
Restructure the context app (formerly basetext) to follow the monorepo
pattern with proper workspace configuration.

Changes:
- Move app files to apps/context/apps/mobile/
- Rename package to @context/mobile
- Update bundle ID to com.manacore.context
- Create pnpm-workspace.yaml for project workspace
- Add dev scripts to root package.json
- Update CLAUDE.md with project documentation

The app structure is prepared for future web/backend additions.

Note: Existing TypeScript errors in the original codebase are preserved.
These should be fixed in a follow-up PR.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 15:09:04 +01:00

37 lines
832 B
TypeScript

export function debounce<T extends (...args: any[]) => any>(
func: T,
wait: number,
options?: { leading?: boolean; trailing?: boolean }
): (...args: Parameters<T>) => void {
let timeout: NodeJS.Timeout | null = null;
let result: any;
const leading = options?.leading ?? false;
const trailing = options?.trailing ?? true;
const debounced = function (this: any, ...args: Parameters<T>) {
const context = this;
const later = () => {
timeout = null;
if (trailing) result = func.apply(context, args);
};
const callNow = leading && !timeout;
if (timeout) clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) result = func.apply(context, args);
return result;
};
debounced.cancel = () => {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
};
return debounced;
}