Download pptx - Kissy mvc

Transcript
Page 1: Kissy mvc

KISSY MVC Overview

[email protected]

2011-11-17 Draft

Page 2: Kissy mvc

• mvc 模块

• KISSY.use (“mvc”,function(S,mvc){– mvc.View => 视图– mvc.Model => 模型– mvc.Collection => 集合– mvc.Router => 路由– mvc.sync => 默认系统同步

• })

Page 3: Kissy mvc

Smart Model

• Flexible data transfer– sync– parse– url– urlRoot

Page 4: Kissy mvc

Smart Model默认服务地址:

/notes/{noteId}

Page 5: Kissy mvc

Smart Model

• Event-Driven– *Change– BeforeXChange– AfterXChange

Page 6: Kissy mvc

Smart Model Code

Page 7: Kissy mvc

Smart Model

• Server-Transparent– Load– Save– destroy

Page 8: Kissy mvc

Smart Model

Page 9: Kissy mvc

Smart Collection

• Flexible data transfer– sync– parse

Page 10: Kissy mvc

Smart Collection

Page 11: Kissy mvc

Smart Collection

• models management– sort– getById– getByCid– Add– Remve– S.each– S.filter

Page 12: Kissy mvc

Smart Collection

Page 13: Kissy mvc

Smart Collection

• Event-Driven– Bubbled *Change– add– remove– afterModelsChange• ( .load() )

Page 14: Kissy mvc

Smart Collection

• Server-tranparent– load– create

Page 15: Kissy mvc

Smart Collection

Page 16: Kissy mvc

Dumb View

Page 17: Kissy mvc

Dumb View

Controllable View With DOM Event

Page 18: Kissy mvc

Controllable View

• Delegate Events• Create Container

bookmark?

router

model view

!bookmark? model view

Page 19: Kissy mvc

Controllable View

Page 20: Kissy mvc

Powerful router• url hash dispatched to function with path param and query

param (intelligent dispatch)

• “/edit/:id” -> fn– /edit/99?q=1 => fn(pathParam,queryParam)

• pathParam => {id:99}• queryParam => {q:1}

• “/new/*path”– /new/kissy-mvc/is-good => fn(pathParam)

• pathParam => {path:”kissy-mvc/is-good”}

• “/*path”

Page 21: Kissy mvc

Graceful html5 support

• Promotion @ Html5 History– http://xx.com/#new– =>– http://xx.com/new

• Degradation @ html < 5– http://xx.com/new– =>– http://xx.com/#new

Page 22: Kissy mvc

Router Events

• Also some events

hashchange route model view

Page 23: Kissy mvc

Powerful Router

Page 24: Kissy mvc

Global sync

• mvc.sync

– Load notes list => /notes/?_method=read– Update note => /notes/noteId?_method=update– Delete note => /notes/noteId?_method=delete– Create note => /notes/?_method=create– Load single note => /notes/noteId?_method=read

Page 25: Kissy mvc

Example

• KISSY Notebook

Page 26: Kissy mvc

list

Page 27: Kissy mvc

NotesView/NoteView

Page 28: Kissy mvc

SearchView

Page 29: Kissy mvc

EditView

Page 30: Kissy mvc

Router

Page 31: Kissy mvc

Sync

• Using localStorage

Page 32: Kissy mvc

ReferAPI:http://docs.kissyui.com/docs/html/api/component/mvc/index.html

Demo:http://docs.kissyui.com/kissy/src/mvc/demo.html