mvc approach with javascript / jquery no framework -


i'm developing large scale application. approach confused , beginner in javascript if develop since january. looking mvc approach , found guide lines, :

model : contains ajax call , , services

controller: e.g. jquery widget , on

view: e.g. rendering of html , on..

i don't have how structure javascript application following 3 above suggestions. can everything, can manage template can write jquery manipulation , can ajax call.

what not clear me how divided these 3 modules. when try approach i'm not able make module has do.

i tried mv* approach which, see , needs maybe it's better approach, because have bind tons of divs , generate events , client side, receiving data server side.

what know:

which competences of each module? if, example, have bind click event button , have write

.on('click',callback) 

method? have write callback he's gonna call?

i wrote : no framework because i'm sure if don't understand approach writing scratch, impossibile understand use of complete framework.

i hope doubts clear, if not, please comment, i'll try explain better if can. sorry english in case.

this not answer because there no 1 answer. want mention few do's , don't's.

  • do store pure data in model. think of business objects rather display objects. example, money should stored in model number, digits after decimal point, plus indicator of currency is, if matters. don't store number string local choices of characters separate 1000's , integer part fractional part , right number of digits after decimal point.
  • do put handler code click events (and similar user actions) in controller.
  • do put code causes updates screen on load or on external event in controller. (an external event might update stock price due stock exchange data or update weather report coming application.)
  • do put html or code generates html part of view.
  • do have controller call view display updated/changed @ right times.
  • do have either controller or view call model current model data values or update the current model data. (see similar "don't" below.)
  • do reduce connectivity between 3 parts--m, v , c. define can talk whom purpose , keep rule sacred. if find exception, smell indicating problem big picture of rules.

and more things

  • don't put code displays screen on load in controller. that's view concern. means controller has call view somehow.
  • don't spaghetti connect m, v , c code in random fashions. example, might make rule model never calls code in view or controller.
  • don't have both controller , view talking model.

questions:

  • where code go hooks event handlers?
  • where put "business logic"? code knows rules of application. validation, example, business logic. code may need know how zip codes , postal codes uk or canada. if validation fails, controller 1 tells view show error message or red mark or vibrating box or whatever. business logic of validation rules go in controller?
  • where code go loads data external data sources? (servers, json web services, databases, screen scraping, etc.) might think "model" model has call controller when new data comes tell update view. doesn't seem right.
  • similarly, code handles equivalent of "submit" button, moving screen.
  • if converting data form displayable on screen form pure data slow, do?
  • there self-contained portions of screen can built own mv&c. how set interactions between multiples of little mvcs , big mvc whole screen? little guys views big mvc? or controllers? can both @ once? there big model little models in or data flow between little models , big models? knows this?
  • is there bigger mvc comprised of multiple screens? on server if exists.
  • how handle "synthetic" events? "event" occurs when data ok in bad state (or incomplete , complete). listeners event can disable "submit" button , display error messages or animations calling user attention problem. isn't generic event built framework or language. perhaps message server indicating change in state of multiplayer game's world view.

this list of things pop mind when writing own mvc or when evaluating existing framework.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -