Project Structure
โครงสร้างไฟล์ของ WebX และหน้าที่ของแต่ละส่วน
โครงสร้างปัจจุบันแยก runtime, component, store และ directive ออกจากกันเพื่อให้แก้ไขง่าย
web/
index.html
webx.json
components/
home/
app.js
template.html
style.css
counter/
app.js
template.html
style.css
directives/
index.js
stores/
appStore.js
wbx/
app.js
core/
bindings.js
cfx.js
component.js
controlFlow.js
directives.js
errorOverlay.js
evaluator.js
lifecycle.js
props.js
reactivity.js
scheduler.js
store.js
styles.js
types/
essentials.js
utils/
getFileContent.js
render.jsApplication Files
web/index.html คือ entry HTML และกำหนด import map
web/webx.json คือ app manifest สำหรับบอก main component และ component ที่ต้อง register
web/wbx/app.js คือ runtime entry ที่อ่าน manifest, validate config, โหลด component แล้ว render ลงใน #app
Component Files
แต่ละ component มีไฟล์หลักสามแบบ:
app.jsกำหนด state, props, method, watch, store, lifecycle และ CFX eventstemplate.htmlมี<template>เป็น root สำหรับ markupstyle.cssเป็น style ภายนอกของ component และถูก scope ด้วย class rewrite
นอกจากนี้ template.html ยังสามารถมี <style scoped> ในไฟล์เดียวกันได้
<template>
<section class="panel">...</section>
</template>
<style scoped>
.panel {
border: 1px solid #d0d5dd;
}
</style>Core Runtime
ไฟล์ใน web/wbx/core ถูกแบ่งตาม responsibility:
bindings.jsดูแล interpolation และsyncdirectives.jsดูแล@event,:bind, built-in directive และ custom directivecontrolFlow.jsดูแล<for>,<if>,<elseif>,<else>reactivity.jsสร้าง reactivedataและpropsด้วย Proxystore.jsสร้าง shared store แบบ Zustand-likeprops.jsparse และ validate props ด้วย Zodstyles.jsscope CSS ด้วยการเปลี่ยนชื่อ classlifecycle.jsรันonMountedและonUnmountedcfx.jsรวม NUI message listener และcfx.callerrorOverlay.jsแสดง error overlay บนหน้าเว็บ
Naming Rule
ชื่อ folder component เป็นชื่อที่ runtime ใช้โหลดไฟล์ เช่น counter จะโหลดจาก @components/counter/app.js
ชื่อ tag ใน template มาจากค่า template ที่ export ใน component:
export default {
template: 'Counter'
}เรียกใช้ใน parent:
<Counter :title="name" />