The MVVM framework implements the problem record

Source: Internet
Author: User

The MVVM framework referred to here refers to a framework similar to Vue, Avalon through a two-way binding, data driven.

Basic principle: Intercept data by Defineproperties Get,set; When the DOM template is loaded, scan the DOM for special named labels, generate the accessor and refresh function for the corresponding tag property, and when the expression of the property is evaluated, Registering the refresh function with the associated expression variable changes the processing array, and completing the data operation automatically triggers a DOM change.

Code implementation on the basis of http://www.cnblogs.com/Aaronjs/rewrite, the code slightly inconsistent,

Code Address: Https://github.com/lukezhang001/mvvmtest

Because it is simple implementation, and reference, the process is not a lot of problems, encountered the problem simple record as follows:

1, the code to write, in the local debugging process found JS loading state has been pending, the problem is that the browser can not see the JS file debugging, and then through the continuous elimination of comparison, found that the code has a dead loop, modified after normal

2, the code of Mvvm.define factory executed two times, the first execution of the returned scope is a normal object, used to generate a description of the properties of the array, after the defineproperties returned after the model to perform a factory. The original is to copy the properties of the Originalmodel to the model, the problem is that for the function, the simple copy context is the original defined context, resulting in the function of the VM object or scope, rather than model, resulting in incorrect property operation.

3, the introduction of Observer.js in the file, the actual is not used, the code inside the function used a lot of this, and foreach will change the function of this, so if the function parameters of the foreach use this, we must pass the final context parameters into

The MVVM framework implements the problem record

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.