[Original] backbone source code analysis-jsmvc

Source: Internet
Author: User

Author: nuysoft/cloud/nuysoft@gmail.com

Disclaimer: This article is an original article. If you need to reprint it, please indicate the source and retain the original article link.

Backbone0.9.1 Source Code Analysis Series

Jquery1.6.1 Source Code Analysis Series

 

Next, I will discuss the MVC model.

 

Jsmvc responsibilities

M model

  • Business Model: business logic, process, status, rules
  • (CORE) Data Model: business data, data validation, addition, deletion, modification, and query (Ajax)

V View

  • (CORE) view: definition, management, and Configuration
  • Template: definition, configuration, and management
  • Components: definition, configuration, and management
  • (CORE) User event configuration and management
  • User input validation, configuration, and management

C Controller/Distributor

  • (CORE) event distribution, model distribution, and view Distribution
  • No data processing or business processing, that is, the business is irrelevant.
  • Extension: Permission control, exception handling, etc.
  • C is the core of the jsmvc framework. It implements centralized configuration and management and can have multiple controllers.

Tool Library

  • Mainly asynchronous requests and Dom operations, which can depend on jquery and so on.

 

Jsmvc implementation

 

The MVC model, view, and controller control are independent of each other, and C serves as a bridge. As a mature development model that has been around for a long time, MVC has already provided a classic reference for controllable implementation. In the browser and JS application scenarios, we will discuss the following:

M modelYesSelf-containedYesNested inclusionDoes not actively reference views and controllers. It can be a simple JSON object/array orCompositeImplement nested inclusion;

V ViewYesNested inclusionCan be implemented using composite; views need to reference models (M-V), A view references multiple views, and the view will receive notifications of the model and automatically update the model. You can useObserver Mode ObserverImplementation; view needs to respond to user interaction, useBrowser event model;

C ControllerAs the core of the MVC frameworkCentralized ConfigurationPolicy (V-C); You can have multiple controllers (C + C), UseStrategy Mode strategyImplementation; the browser event model is required for the hash event driver.

We can see that the M model is not associated with the c controller. Generally, I don't think it is necessary; however, in some frameworks, the association between M model and C controller events (such as magix used by the company) is also a practice that can be referenced.

 

The above discussion resolves the positioning of MVC in JS, but the key to understanding how jsmvc runs lies in its understanding of event-driven.

 

Event-driven

 

In the browser, jsmvc hasThree event-driven methods:

1.Hash driver, Using the popstate/hashchange event driver controller (the front side has been introduced, and the principle, implementation, and skills of the backbone router and history will be explained in detail later)

2.DOM eventsTo drive the view (which we are familiar)

3.Model event(Business Model events and data model events), used to drive the combination of models and models (this will be explained in conjunction with the model of backbone)

 

I will write it here today. The next section describes the architecture of backbone, what it can do, what it cannot do, and what it can expand.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.