This repository has been archived on 2026-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
gitgram-ai/gitgram/mobile/utils/bundleOptimization.ts
caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as
opaque submodule gitlinks on GitHub) into fully-tracked first-party content.

AITM now merges its 7 vendored repos as first-party engines:
- memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts
- git: vendored C git (bundled binary) + gitnexus (in-process code intelligence)
- agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess)

Includes the full session's product build: Gitgram web/mobile/backend features,
AITM website/CLI/MCP, the unified memory layer, engine build tooling
(scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md),
and extensive test suites.

Build artifacts, node_modules, external/, and gemini-cli are gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 14:14:09 +03:00

75 lines
1.8 KiB
TypeScript

// Bundle optimization utilities
import React from 'react';
// Code splitting helper
export const createLazyComponent = <T extends React.ComponentType<any>>(
importFunc: () => Promise<{ default: T }>
) => {
return React.lazy(importFunc);
};
// Dynamic import helper
export async function dynamicImport<T>(
modulePath: string
): Promise<T> {
return import(modulePath) as Promise<T>;
}
// Preload critical resources
export function preloadResources(resources: string[]) {
if (typeof window !== 'undefined') {
resources.forEach((resource) => {
const link = document.createElement('link');
link.rel = 'preload';
link.href = resource;
link.as = resource.endsWith('.css') ? 'style' : 'script';
document.head.appendChild(link);
});
}
}
// Memory leak prevention utilities
export class MemoryManager {
private static listeners: Map<string, Set<() => void>> = new Map();
static addCleanup(key: string, cleanup: () => void) {
if (!this.listeners.has(key)) {
this.listeners.set(key, new Set());
}
this.listeners.get(key)!.add(cleanup);
}
static removeCleanup(key: string, cleanup: () => void) {
const cleanups = this.listeners.get(key);
if (cleanups) {
cleanups.delete(cleanup);
}
}
static cleanup(key: string) {
const cleanups = this.listeners.get(key);
if (cleanups) {
cleanups.forEach((cleanup) => cleanup());
cleanups.clear();
}
}
static cleanupAll() {
this.listeners.forEach((cleanups) => {
cleanups.forEach((cleanup) => cleanup());
cleanups.clear();
});
this.listeners.clear();
}
}
// React hook for cleanup
export function useCleanup(cleanup: () => void, deps: any[] = []) {
React.useEffect(() => {
return cleanup;
}, deps);
}
// Note: For React Native, use React.useEffect directly instead of this helper