caelum0x f80b04ae0f feat(ritgram): move GitGram app into railyard as Ritgram, next to Rithub
Moved later/gitgram-ai/gitgram/ to apps/ritgram/ (fresh history; full history stays in caelum0x/gitgram).
AITimeMachine stays separate in later/gitgram-ai per the Rithub master plan.
Logs, pid files and env files are ignored; GPL-3.0 mobile/proximity noted in THIRD_PARTY_NOTICES.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-13 04:18:46 +03:00

103 lines
2.4 KiB
TypeScript

// Performance optimization utilities
import React from 'react';
// Lazy load component
export function lazyLoad<T extends React.ComponentType<any>>(
importFunc: () => Promise<{ default: T }>
): React.LazyExoticComponent<T> {
return React.lazy(importFunc);
}
// Debounce function for search/input
export function debounce<T extends (...args: any[]) => any>(
func: T,
wait: number
): (...args: Parameters<T>) => void {
let timeout: NodeJS.Timeout | null = null;
return function executedFunction(...args: Parameters<T>) {
const later = () => {
timeout = null;
func(...args);
};
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(later, wait);
};
}
// Throttle function for scroll events
export function throttle<T extends (...args: any[]) => any>(
func: T,
limit: number
): (...args: Parameters<T>) => void {
let inThrottle: boolean;
return function executedFunction(...args: Parameters<T>) {
if (!inThrottle) {
func(...args);
inThrottle = true;
setTimeout(() => (inThrottle = false), limit);
}
};
}
// Memoize expensive computations
export function memoize<Args extends any[], Return>(
fn: (...args: Args) => Return
): (...args: Args) => Return {
const cache = new Map<string, Return>();
return (...args: Args): Return => {
const key = JSON.stringify(args);
if (cache.has(key)) {
return cache.get(key)!;
}
const result = fn(...args);
cache.set(key, result);
return result;
};
}
// Image preloader
export function preloadImages(urls: string[]): Promise<void[]> {
return Promise.all(
urls.map(
(url) =>
new Promise<void>((resolve, reject) => {
const img = new Image();
img.onload = () => resolve();
img.onerror = reject;
img.src = url;
})
)
);
}
// Batch API calls
export function batchRequests<T>(
requests: (() => Promise<T>)[],
batchSize: number = 5
): Promise<T[]> {
const results: T[] = [];
const processBatch = async (batch: (() => Promise<T>)[]) => {
const batchResults = await Promise.all(batch.map((req) => req()));
results.push(...batchResults);
};
const processAll = async () => {
for (let i = 0; i < requests.length; i += batchSize) {
const batch = requests.slice(i, i + batchSize);
await processBatch(batch);
}
};
return processAll().then(() => results);
}