원클릭으로
designing-web-apps-in-chemical
How complex and scalable web apps are designed in chemical using macro plugins
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
How complex and scalable web apps are designed in chemical using macro plugins
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Comprehensive guide to the Chemical compiler test infrastructure — how tests are organized, written, and executed. Covers the test framework, @test annotation dispatch, test_env and test libraries, and how compiler plugins get tested via lang/tests/build.lab.
Comprehensive deep-dive into the Chemical build pipeline — how chemical.mod is converted to build.lab, how build scripts are JIT-compiled via TinyCC, how jobs are created and executed, and how ASTProcessor orchestrates the parallel compilation passes.
All documentation related to building and running Project or Tests
Comprehensive guide to the Chemical Compiler Binding Interface (CBI) — how compiler plugins are built, registered, and integrated into the compilation pipeline.
Documentation of Syntax and APIs for Chemical Programming Language, A must read before implementing something in chemical programming language.s
Comprehensive guide to Chemical's compiler intrinsic functions and reflection APIs — how GlobalFunctions.cpp provides interpreter-friendly implementations, compile-time reflection, and metadata access.
| name | Designing Web Apps in Chemical |
| description | How complex and scalable web apps are designed in chemical using macro plugins |
Writing scalable and complex web apps require that you have great organization, components that handle their responsibilities and the glue that holds everything together is small, predictable and reliable.
First you must ask yourself, whether the app is a static app (static pages website like a blog), a SPA (single page application) or a server served app (where server serves pages, modifying the actual content based on each user)
Everything happens with the page library, which you should import in the chemical.mod
Here's simple functions that execute on the server, to create a single page with its assets into the current directory.
func CreateOneSimplePage() {
// comes from the page library
var page = HtmlPage()
// lets first put static content in the page
PutStaticContentInSimplePage(page)
// write the static page to the directory
// you should definitely analyze the page library (lang/libs/page) for this function's definition
// so you can understand how it emits the assets for the page
// index.html + any assets it requires (js / css) will be written to current directory
page.writeToDirectory("./", "index.html")
}
// this function returns a random class name for the styles we wrote
// the random class name would be like .h23unfi3
func style_button(page : &mut HtmlPage) : *char {
return #css {
color : blue;
padding : 8px;
border-radius : 4px;
background : white;
// targeting a class name present in the entire page
.my-global-button {
color : red;
}
}
}
// when we open a {} for the attribute value, it means we are going to write chemical code inside those braces
// NOT JS, just chemical code that would execute on the server
func PutStaticContentInSimplePage(page : &mut HtmlPage) {
#js {
const myElem = document.getElementById("clickable-btn")
myElem.onclick = () => {
console.log("you clicked on the button");
}
}
#html {
<div>
<button class={style_button(page)}>Hello World</button>
<button id="clickable-btn" class="my-global-button">This is targeted using global selector</button>
</div>
}
}
You must not do this, an element that begins, must end in the same macro
func InvalidHtml(page : &mut HtmlPage) {
#html {
<div>
}
// chemical statements in between
if(true) {}
#html {
</div>
}
}
Again do NOT write ^ such code.
Here's how to write correct code.
func InvalidHtml(page : &mut HtmlPage) {
#html {
<div>
@{if(true) {
// i can write chemical code here
}}
</div>
}
}
To better provide support for JS handling of elements, applying event listeners and DOM manipulation, universal components come into play.
What if instead of server side functions, we wrote components that can be used at client side or server side ?
// this function returns a random class name for the styles we wrote
// the random class name would be like .h23unfi3
func style_button(page : &mut HtmlPage) : *char {
return #css {
color : blue;
padding : 8px;
border-radius : 4px;
background : white;
// targeting a class name present in the entire page
.my-global-button {
color : red;
}
}
}
#universal MyButton(props) {
// page is always available inside a universal component
var server_value = ${style_button(page)}
state counter = 0
var arr = ["first", "second"]
// the .map on arr would break ssr, meaning it would be rendered at client side
// everything else would render using ssr + hydration
return <div>
<button onClick={() => {
console.log("you pressed my button")
counter++
}}>{counter} : {props.text}</button>
arr.map((i) => {
<span>{i}</span>
})
</div>
}
func PutStaticContentInSimplePage(page : &mut HtmlPage) {
// you can mount universal components in #html or other #universal components
// remember in #html, you can't pass js props, if you want to do that, wrap in a universal component
#html {
<div>
<MyButton text="This is my button" />
<MyButton text="This is my button" />
</div>
}
}
in universal macro, some things are different
{} do not mean a server side (chemical) value, braces contain JS expressions${} contain server side chemical values