You have a new contract: You are going to serve as the lead Software Architect and…
- User
You have a new contract: You are going to serve as the lead Software Architect and Engineer for the Cat.js project. This is a lightweight, state-of-the-art engine designed to build powerful UIs, prioritizing the highest performance and efficiency, and based exclusively on modern native browser APIs, primarily Web Components.
Practices and things to avoid for Cat.js
No Virtual DOMs or similar practices. No Webpack, bundlers, polyfills, etc. Write HTML or CSS code into a JS file, function or similar. Render methods for components, or logics that trigger unnecessary reflows and repainting. Requirements for Cat.js
Our engine it's attach through a script:src tag on the top of the head tag. Written on vanilla low level JavaScript that fits perfectly the browser runtime. Beautiful and ease Syntax and Project tree CSC - Client Side Compiler before loading the DOM.
So far this is our engine: // cat.js
(function() { 'use strict';
/**
- Internal module for tracking loaded files and components. */ const Registry = (function() { const loadedFiles = new Set(); const registeredComponents = new Set(); const currentLoadingPath = new Set();
return { isFileLoaded: (path) => loadedFiles.has(path), markFileAsLoaded: (path) => loadedFiles.add(path), isComponentRegistered: (name) => registeredComponents.has(name), registerComponent: (name) => registeredComponents.add(name), isInCurrentLoadingPath: (path) => currentLoadingPath.has(path), addToCurrentLoadingPath: (path) => currentLoadingPath.add(path), removeFromCurrentLoadingPath: (path) => currentLoadingPath.delete(path), }; })();
/**
- Internal module for handling pending insertions. */ const InsertionManager = (function() { const pendingInsertions = new Map(); let observer = null;
function addPendingInsertion(selector, fragment) { if (!pendingInsertions.has(selector)) { pendingInsertions.set(selector, []); } pendingInsertions.get(selector).push(fragment);
// Initialize MutationObserver if not already done if (!observer) { observer = new MutationObserver(handleMutations); observer.observe(document, { childList: true, subtree: true }); }}
function handleMutations(mutationsList) { for (const mutation of mutationsList) { for (const node of mutation.addedNodes) { checkNodeForPendingInsertions(node); } } }
function checkNodeForPendingInsertions(node) { if (node.nodeType !== Node.ELEMENT_NODE) { return; }
pendingInsertions.forEach((fragments, selector) => { let targets = []; if (node.matches(selector)) { targets.push(node); } const matchedDescendants = node.querySelectorAll(selector); if (matchedDescendants.length > 0) { targets = targets.concat(Array.from(matchedDescendants)); } for (const targetElement of targets) { performInsertions(targetElement, selector); } }); // Recursively check child nodes for (const child of node.children) { checkNodeForPendingInsertions(child); } - Assistant