Mini mvvm framework avalonjs 0.8 released

Source: Internet
Author: User

The most important feature of this version is the introduction of the amd specification module loader, that is, the original parallel loader of the mass framework. In contrast, it introduces the XXX of requirejs! Style plug-in mechanism, for example, to be triggered when the DOM tree is created, ready is used !, To load a CSS file, use CSS! Css_path.

The loader is indispensable for single-page applications on mobile devices or PCs. According to incomplete statistics of the company's content, the performance of browsers such as mobile phones is only about of that of PCs, and the test object is still the mobile phone of the company's rich colleagues, what IP address, Samsung Galaxy.

In the past week, the integration of angular and requirejs encountered various difficulties. Finally, we had to download an integrated application from GitHub to modify it. Because there is no integration capability, our angular cannot be upgraded at will. Therefore, I am deeply aware of the importance of the built-in loader. Of course, the loader has always been a feature that some friends of Weibo are eager to expect. Because we need to synchronize two projects that are not under our control at the same time, we are truly exhausted.

Currently, in addition. in addition to JS, there is another name: aveon. mobile. JS stuff, it's aveon. the optimized version of JS is built based on the new attributes in the HTML5 era and is no longer compatible with legacy IE. The supported version of IE is ie10, which ensures smooth operation on mobile devices.

For example, hasclass, addclass, removeclass, and toggleclass are implemented in avron. js in this way.

Hasclass: function (CLS) {var El = This [0] | |{} if (El. nodetype = 1) {return !! El. classname & ("" + el. classname + ""). indexof ("" + CLS + "")>-1 }}, addclass: function (CLS) {var node = This [0] If (CLS & typeof CLS === "string" & node. nodetype = 1) {If (! Node. classname) {node. classname = CLS} else {var A = (node. classname + "" + CLs ). match (rnospaces). sort () for (var j =. length-1; j> 0; -- j) if (a [J] = A [J-1]). splice (J, 1) node. classname =. join ("") }} return this}, removeclass: function (CLS) {var node = This [0] If (CLS & typeof CLS> "O" & node. nodetype = 1 & node. classname) {var classnames = (CLS | ""). match (rnospaces) | [] var Cl = classnames. length var set = "" + node. classname. match (rnospaces ). join ("") + "" For (var c = 0; c

The following figure shows how to implement the function in aveon. Mobile:

         hasClass: function(cls) {            var el = this[0] || {}            return el.nodeType === 1 && el.classList.contains(cls)        },        addClass: function(cls) {            var el = this[0]            if (cls && typeof cls === "string" && el && el.nodeType === 1) {                cls.replace(rword, function(c) {                    el.classList.add(c)                })            }            return this        },        removeClass: function(cls) {            var node = this[0]            if (cls && typeof cls > "o" && node && node.nodeType === 1 && node.className) {                cls.replace(rword, function(c) {                    node.classList.remove(c)                })            }            return this        },        toggleClass: function(value, stateVal) {            var state = stateVal,                    className, i = 0            var classNames = value.match(rnospaces) || []            var isBool = typeof stateVal === "boolean"            var node = this[0] || {}, classList            if (classList = node.classList) {                while ((className = classNames[i++])) {                    state = isBool ? state : !classList.contains(className)                    classList[state ? "add" : "remove"](className)                }            }            return this        },

The ATTR method has different implementations in these two versions. The dataset is used in aveon. Mobile. js.

  data: function(name, value) {            name = "data-" + hyphen(name || "")            switch (arguments.length) {                case 2:                    this.attr(name, value)                    return this                case 1:                    var val = this.attr(name)                    return parseData(val)                case 0:                    var attrs = this[0].attributes,                            ret = {}                    for (var i = 0, attr; attr = attrs[i++]; ) {                        name = attr.name                        if (!name.indexOf("data-")) {                            name = camelize(name.slice(5))                            ret[name] = parseData(attr.value)                        }                    }                    return ret            }        },//----------------------------------------------------------       avalon.data = function(name, val) {            var dataset = this[0].dataset;            switch (arguments.length) {                case 2:                    dataset[name] = val                    return this                case 1:                    val = dataset[name]                    return parseData(val)                case 0:                    var ret = {}                    for (var name in dataset) {                        ret[name] = parseData(dataset[name])                    }                    return ret            }        }

Avron. Mobile. js even tried to use hidden to implement visible binding.

    if (typeof DOC.createElement("div").hidden === "boolean") {        bindingHandlers.visible = function(data, vmodels) {            var elem = data.element            watchView(data.value, vmodels, data, function(val) {                elem.hidden = !val            })        }    }

In the future, we will try to strengthen the future of version 0.9.InternationalizationSupport for array elementsDeep monitoring, Aveon. Mobile will try to useWebworkerAnd then release the official version 1.0 !!!!!!!!!!

Mini mvvm framework in GitHub warehouse https://github.com/RubyLouvre/avalon

Official Website address http://rubylouvre.github.io/mvvm/

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.