FOAM Metaprogramming Framework
FOAM is described as a full-stack reactive MVC metaprogramming framework primarily implemented in JavaScript. Its core value proposition focuses on building high-performance applications with reduced size and increased developer efficiency, allowing for code generation targeting various languages and platforms. The project appears to be an early-stage or abandoned framework, indicated by its low version number (0.5.0), the use of 'nodejs' (rather than 'node') in examples, a dependency on Google Groups for discussions, and the primary distribution method involving direct HTML script inclusion or pre-bundled `foam.js` files. It predates widespread adoption of modern JavaScript module systems like CommonJS or ESM, typically relying on global scope for accessibility. There is no clear release cadence, and the framework's 'no build' claim for demos contrasts with a build tool for optimized deployment, suggesting a workflow that might be incompatible with contemporary front-end development practices. Key differentiators include its metaprogramming capabilities and focus on efficient code generation, though its current relevance is limited given its apparent inactivity.
Common errors
-
Error: Cannot find module 'foam-framework'
cause Attempting to import or require `foam-framework` as a CommonJS or ESM module.fixFOAM is not designed for module imports. Load it via a script tag in HTML (`<script src="path/to/foam.js"></script>`) or use its dedicated build tools to generate deployable files. -
ReferenceError: FOAM is not defined
cause The `FOAM` global object is not available because the framework's script was not loaded, or it was loaded incorrectly, or code is trying to access it before the script has executed.fixEnsure the `foam.js` script is correctly linked in your HTML (`<script src="path/to/foam.js"></script>`) and that any code accessing `FOAM` runs *after* the script has fully loaded and executed. Verify the path to `foam.js` is correct. -
SyntaxError: Unexpected token '...' (or other modern JavaScript syntax errors)
cause Running FOAM's codebase or generated output in an environment (e.g., an older Node.js version or specific browser) that does not support the JavaScript features it uses, or conversely, running old FOAM code in a new environment without proper transpilation.fixEnsure the environment's JavaScript engine (browser or Node.js) is compatible with the version of JavaScript FOAM was written in. If using a newer environment, be aware that FOAM's code might contain deprecated patterns or lack support for modern syntax.
Warnings
- breaking FOAM is likely incompatible with modern JavaScript syntax (ES2015+) and recent Node.js versions. Its development predates many contemporary language features and runtime advancements, potentially leading to syntax errors or runtime issues.
- gotcha The framework operates by exposing itself globally (e.g., `window.FOAM`) when loaded via script tags. This can lead to global scope pollution and potential conflicts with other libraries or scripts that might use similar global variable names.
- gotcha FOAM does not support modern JavaScript module systems (CommonJS, ESM). Attempts to `import` or `require` modules from the `foam-framework` npm package will fail, as it expects direct script inclusion or use of its build tools.
- gotcha The project appears to be abandoned or no longer actively maintained, given its low version number (0.5.0), outdated documentation references (Google Groups), and absence of recent updates. This implies a lack of security patches, bug fixes, or compatibility updates for newer environments.
- gotcha The build process, described using a `nodejs tools/foam.js` command, is not integrated with modern front-end build pipelines (e.g., Webpack, Rollup, Vite). This can complicate integration into contemporary development workflows and dependency management.
Install
-
npm install foam-framework -
yarn add foam-framework -
pnpm add foam-framework
Imports
- FOAM
import { FOAM } from 'foam-framework'; const FOAM = require('foam-framework');<!-- Load foam.js into an HTML page --> <script src="path/to/foam.js"></script> <!-- FOAM will then be available globally, e.g., window.FOAM -->
Quickstart
nodejs tools/foam.js foam.build.BuildApp controller=my.controller.Model targetPath=. // This command runs the FOAM build tool to generate a bundled application. // 'my.controller.Model' should be replaced with the actual path to your application's main controller model. // The 'targetPath' specifies where the output (e.g., foam.js and foam.html) will be placed.