
輕鬆構建功能強大的Web應用程序
探索?祖docs»
加入社區。報告錯誤。請求功能
const Cradova = new Comp ( function ( ) {
const [ year , setYear ] = useState ( 3 , this ) ;
return h1 ( "Cradova is " + year + " yrs old in " , {
onclick ( ) {
setYear ( ( lastYear ) => {
return lastYear + 1 ;
} ) ;
} ,
} ) ;
} ) ;
document . body . appendChild ( Cradova . render ( ) ) ; import { $case , $if , $ifelse , $switch , div , h1 } from "cradova" ;
function Hello ( { name } ) {
return div (
$if ( name === "john" , h1 ( "Hello john" ) ) ,
$if ( name === "paul" , h1 ( "Goodbye paul" ) ) ,
$ifelse ( name === "john" , h1 ( "Hello john" ) , h1 ( "Hello Paul" ) )
) ;
}
const html = div ( Hello ( "john" ) , Hello ( "paul" ) ) ;
function whatsAllowed ( { age } ) {
return div (
$switch (
age ,
$case ( 12 , h1 ( "too young" ) ) ,
$case ( 26 , h1 ( "you are welcome" ) ) ,
$case ( 52 , h1 ( "too old" ) )
)
) ;
}
document . body . append ( html , whatsAllowed ( { age : 26 } ) ) ;Cradova是用於構建單頁應用程序和PWA的網絡開發框架。
Cradova遵循VJS規格
快速而簡單,抽象較少,但易於組合。
Cradova不是基於虛擬DOM或DIFF算法的。取而代之的是,國家管理以簡單,簡單和快速的方式完成。
毫無疑問,這提供了重要的優勢。
當前版本更改
npm i cradova <!-- unpkg -->
< script src =" https://unpkg.com/cradova/dist/index.js " > </ script >
<!-- js deliver -->
< script src =" https://cdn.jsdelivr.net/npm/cradova/dist/index.js " > </ script > Cradova的某些方面在以下示例中沒有反映。將來的文檔將需要更多功能。
import { div , h1 } from "cradova" ;
function Hello ( name ) {
return h1 ( "Hello " + name , {
className : "title" ,
style : {
color : "grey" ,
} ,
} ) ;
}
const html = div ( Hello ( "peter" ) , Hello ( "joe" ) ) ;
document . body . append ( html ) ; 這是一系列基本示例,可以給您一些想法
import {
br ,
button ,
Comp ,
createSignal ,
div ,
h1 ,
reference ,
useRef ,
} from "cradova" ;
// hello message
function HelloMessage ( ) {
return div ( "Click to get a greeting" , {
onclick ( ) {
const name = prompt ( "what are your names" ) ;
this . innerText = name ? "hello " + name : "Click to get a greeting" ;
} ,
} ) ;
}
// reference (not state)
function typingExample ( ) {
const ref = useRef ( ) ;
return div (
input ( {
oninput ( ) {
ref . current ( "text" ) . innerText = this . value ;
} ,
placeholder : "typing simulation" ,
} ) ,
p ( " no thing typed yet!" , { reference : ref . bindAs ( "text" ) } )
) ;
}
function App ( ) {
return div ( typingExample , HelloMessage ) ;
}
document . body . append ( App ( ) ) ; 讓我們看看一個簡單的招待示例
import {
button ,
Comp ,
createSignal ,
div ,
h1 ,
input ,
main ,
p ,
useRef ,
useState ,
} from "../dist/index.js" ;
// creating a store
const todoStore = new Signal ( {
todo : [ "take bath" , "code coded" , "take a break" ] ,
} ) ;
// create actions
const addTodo = function ( todo : string ) {
todoStore . publish ( "todo" , [ ... todoStore . pipe . todo , todo ] ) ;
} ;
const removeTodo = function ( todo : string ) {
const ind = todoStore . pipe . todo . indexOf ( todo ) ;
todoStore . pipe . todo . splice ( ind , 1 ) ;
todoStore . publish ( "todo" , todoStore . pipe . todo ) ;
} ;
function TodoList ( ) {
// can be used to hold multiple references
const referenceSet = useRef ( ) ;
// bind Comp to Signal
todoStore . subscribe ( "todo" , todoList ) ;
// vjs
return main (
h1 ( `Todo List` ) ,
div (
input ( {
placeholder : "type in todo" ,
reference : referenceSet . bindAs ( "todoInput" ) ,
} ) ,
button ( "Add todo" , {
onclick ( ) {
addTodo (
referenceSet . elem < HTMLInputElement > ( "todoInput" ) ! . value || ""
) ;
referenceSet . elem < HTMLInputElement > ( "todoInput" ) ! . value = "" ;
} ,
} )
) ,
todoList
) ;
}
const todoList = new Comp ( function ( ) {
const data = this . subData ;
return div (
data . map ( ( item : any ) =>
p ( item , {
title : "click to remove" ,
onclick ( ) {
removeTodo ( item ) ;
} ,
} )
)
) ;
} ) ;
document . body . appendChild ( TodoList ( ) ) ; 與僅附加到DOM的東西不同,構建應用程序的更好是使用路由系統。
Cradova路由器是一個允許您執行以下操作的模塊:
在您的應用程序中創建指定的路由,請幫助您處理導航在路由上渲染一個頁面,請訪問導航更改在頁面級別上創建錯誤邊界,除了Comp Level。
讓我們嘗試一個例子。
import { Page , Router } from "cradova" ;
// Comp can be used as page template this way
const template = new Comp ( function ( name ) {
// an effect run once after page renders
const self = this ;
self . effect ( ( ) => {
const name = new Promise ( ( res ) => {
res ( "john doe" ) ;
} ) ;
setTimeout ( async ( ) => {
self . recall ( await name ) ;
} , 1000 ) ;
} ) ;
// effects can be used to make api calls needed for the page
return div ( name ? ">>>>>>>> Hello " + name : " loading..." ) ;
} ) ;
const home = new Page ( {
name : "home page" , // page title
template : ( ) => div ( template ) ,
} ) ;
// in your routes.ts file
Router . BrowserRoutes ( {
// Ways to use paths and Pages
"*" : home ,
"/home" : home ,
"/home?" : home ,
"/home/:name" : home ,
// will be lazy loaded
"/lazy-loaded-home" : async ( ) => await import ( "./home" ) ,
} ) ;
// creates these routes
Router . navigate ( "/home" , data ) ;
// navigates to that page
Router . onPageEvent ( ( lastRoute , newRoute ) => {
console . log ( lastRoute , newRoute ) ;
} ) ;
// listen for navigation changes有關Cradova路由器的更多信息
每個Cradova應用程序都可以安裝在DIV上,並使用屬性data-wrapper =“ app”
如果它已經存在,則Cradova將使用它。
如果尚未存在,Cradova將使用DATA-WRAPPER =“ APP”創建DIV。
因此,如果您想使用自己的安裝點,請使用data-wrapper =“ app”創建一個DIV。
有關Cradova頁面的更多信息
cradova頁面具有onacivate()和onDeactivate()方法,該方法也可以在與之結合的該變量上的組件函數中可用。
這允許您管理應用程序中每個頁面的渲染圈
有關Cradova Comp的更多信息
Cradova comp是一個動態組件類,它發出了簡單的抽象,例如:
這些行為允許您管理應用程序中的COMP渲染圈
有關Cradova的更多信息
Cradova信號允許您創建強大的數據存儲。
具有:
借助這些簡單簡單的抽象,您可以在非常方便的情況下編寫數據存儲。
目前,我們正在為Cradova創建文檔網站,並且資源有限。如果您有興趣伸出援手,我們邀請您加入我們的社區,獲得第一手經驗,並為Cradova的發展做出貢獻。
要獲得進一步的見解並幫助Cradova,請訪問Discord和Telegram社區聊天。
我們目前正在努力設置以下內容:
██████╗ ██████╗ █████═╗ ███████╗ ███████╗ ██╗ ██╗ █████╗
██╔════╝ ██╔══██╗ ██╔═╗██║ █ ██ ██╔═════╝█ ██║ ██║ ██╔═╗██
██║ ██████╔╝ ███████║ █ ██ ██║ ██ ██║ ██║ ██████╗
██║ ██╔══██╗ ██║ ██║ █ ██ ██║ ██ ╚██╗ ██╔╝ ██║ ██╗
╚██████╗ ██║ ██║ ██║ ██║ ███████╔╝ ████████ ╚███╔╝ ██║ ██║
╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚════╝ ╚══╝ ╚═╝ ╚═╝
開源和免費。
加入我們的電報。
如果您為該項目貢獻代碼,則隱含地允許在同一許可下分發代碼。您還暗中驗證了所有代碼都是您的原始工作。
您的支持是隨時進行變革的良好力量,您可以通過對Github贊助商進行重新出現或固定的讚助來確保我們的項目,增長,Cradova,Cradova,Jet Path等,增長和改進,增長和改進:
通過加密支持 -
bc1q228fnx44ha9y5lvtku70pjgaeh2jj3f867nwye0xd067560fDed3B1f3244d460d5E3011BC42C4E5d7ltc1quvc04rpmsurvss6ll54fvdgyh95p5kf74wppa6THag6WuG4EoiB911ce9ELgN3p7DibtS6vP輕鬆構建功能強大的Web應用程序。