Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

Architecture ของ Backbone.js ใน JavaScript

BackboneJS ให้โครงสร้างกับเว็บแอปพลิเคชัน แยก business logic และ user interface logic

Architecture ของ BackboneJS ประกอบด้วย modules:

HTTP Request

HTTP client ส่ง HTTP request ไป server เป็น request message เบราว์เซอร์, search engines เป็น HTTP clients ผู้ใช้ request ไฟล์ (documents, images) ผ่าน HTTP request protocol

Router

ใช้ routing client-side applications เชื่อมต่อกับ actions และ events ผ่าน URLs เป็น URL representation ของ application objects URL เปลี่ยนโดยผู้ใช้ด้วยตนเอง Backbone ใช้ URL เข้าใจว่า application state ไหนควรส่งหรือแสดงให้ผู้ใช้

View

BackboneJS views รับผิดชอบ how และ what เพื่อ display จากแอปพลิเคชัน ไม่ contain HTML markup ระบุ idea ข้างหลัง presentation ของ model's data ให้ผู้ใช้ Views reflect "what your data model looks like"

Events

Events เป็นส่วนสำคัญของแอปพลิเคชัน ผูก custom events ของผู้ใช้กับแอปพลิเคชัน ผสมเข้า object ใดๆ ได้ และ bind/trigger custom events ผูก custom events ด้วยชื่อที่ต้องการ

Model

Models แทน business entities พร้อม business logic และ validations ใช้สำหรับ data storage และ business logic Models ดึงและบันทึกได้จาก data storage Model รับ HTTP request จาก Events ผ่าน View ใช้ Router sync ข้อมูลจาก database ส่ง response กลับ client

Collection

Collection คือชุดของ models ที่ bind events เมื่อ model ถูก modified ใน collection Collection มี list ของ models ที่ loop ได้ รองรับ sorting และ filtering สร้าง collection ได้ define model type และ instance properties Event บน model จะ trigger บน collection ด้วย

Data Source

Connection setup ไป database จาก server มีข้อมูลที่ client request