迷你MVVM框架 avalonjs 1.3.3发布

时间:2014-08-19 12:20:04   收藏:0   阅读:404

这应该是1.3X系列最后一个版本了,大家可以在仓库中看到,多出了一个叫avalon.observe的东西,它是基于Object.observe,dataset, Promise等新API实现。其中,它也使用全新的静态收集依赖的机制,这个机制也完成得差不多,因此avalon与avalon.mobile下一版将会应用这最新成果,进行大改。

着重说一下最后一个新特性。原来定义一个VM大概如下:

            var model = avalon.define("test", function(vm) {
                vm.firstName = "司徒"
                vm.lastName = "正美"
                vm.fullName = {//一个包含set或get的对象会被当成PropertyDescriptor,
                    set: function(val) {//里面必须用this指向scope,不能使用scope
                        var array = (val || "").split(" ");
                        this.firstName = array[0] || "";
                        this.lastName = array[1] || "";
                    },
                    get: function() {
                        return this.firstName + " " + this.lastName;
                    }
                }
                vm.click = function() {
                    alert(vm.firstName)
                }
                vm.$watch("firstName", function() {
                    alert(vm.firstName)
                })
                vm.arr = ["aaa", ‘bbb‘, "ccc", "ddd"]
                vm.selected = ["bbb", "ccc"]
                vm.checkAllbool = vm.arr.length === vm.selected.length
                vm.checkAll = function() {
                    if (this.checked) {
                        vm.selected = vm.arr
                    } else {
                        vm.selected.clear()
                    }
                }
            })
            model.selected.$watch("length", function(n) {
                model.checkAllbool = n === model.arr.size()
            })

现在还可以这样定义:

            var model = avalon.define({
                $id: "test",
                firstName: "司徒",
                lastName: "正美",
                fullName: {//一个包含set或get的对象会被当成PropertyDescriptor,
                    set: function(val) {//里面必须用this指向scope,不能使用scope
                        var array = (val || "").split(" ");
                        this.firstName = array[0] || "";
                        this.lastName = array[1] || "";
                    },
                    get: function() {
                        return this.firstName + " " + this.lastName;
                    },
                },
                click: function() {
                    alert(model.firstName)
                },
                arr: ["aaa", ‘bbb‘, "ccc", "ddd"],
                selected: ["bbb", "ccc"],
                checkAllbool: true,
                checkAll: function() {
                    if (this.checked) {
                        model.selected = model.arr
                    } else {
                        model.selected.clear()
                    }
                }
            })
            model.checkAllbool = model.arr.length === model.selected.length
            model.$watch("firstName", function() {
                alert(model.firstName)
            })
            model.selected.$watch("length", function(n) {
                model.checkAllbool = n === model.arr.size()
            })

迷你MVVM框架在github的仓库https://github.com/RubyLouvre/avalon

官网地址http://rubylouvre.github.io/mvvm/

avalon的新UI库地址OniUI, 多达34个UI,强大的换肤功能


bubuko.com,布布扣

朋友们用avalon做的东西

迷你MVVM框架 avalonjs 1.3.3发布,布布扣,bubuko.com

原文:http://www.cnblogs.com/rubylouvre/p/3875666.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!