Evan You %!s(int64=12) %!d(string=hai) anos
pai
achega
5e638a0893

+ 25 - 12
src/compiler.js

@@ -52,8 +52,6 @@ function Compiler (vm, options) {
 
     // copy data, methods & compiler options
     var data = compiler.data = options.data || {}
-    extend(vm, data, true)
-    extend(vm, options.methods, true)
     extend(compiler, options.compilerOptions)
 
     // initialize element
@@ -92,10 +90,15 @@ function Compiler (vm, options) {
     // setup observer
     compiler.setupObserver()
 
-    // create bindings for computed properties
-    var computed = options.computed
-    if (computed) {
-        for (key in computed) {
+    // create bindings for computed properties and methods
+    if (options.methods) {
+        for (key in options.methods) {
+            compiler.createBinding(key)
+        }
+    }
+
+    if (options.computed) {
+        for (key in options.computed) {
             compiler.createBinding(key)
         }
     }
@@ -105,7 +108,7 @@ function Compiler (vm, options) {
     if (params) {
         i = params.length
         while (i--) {
-            vm[params[i]] = utils.checkNumber(
+            data[params[i]] = utils.checkNumber(
                 compiler.eval(
                     el.getAttribute(params[i])
                 )
@@ -118,7 +121,15 @@ function Compiler (vm, options) {
 
     // the user might have set some props on the vm 
     // so copy it back to the data...
-    extend(data, vm)
+    for (key in vm) {
+        if (typeof vm[key] !== 'function') {
+            data[key] = vm[key]
+        }
+    }
+
+    vm.$index = data.$index
+    vm.$value = data.$value
+    vm.$key   = data.$key
 
     // observe the data
     compiler.observeData(data)
@@ -570,8 +581,9 @@ CompilerProto.createBinding = function (key, directive) {
     utils.log('  created binding: ' + key)
 
     var compiler = this,
+        methods  = compiler.options.methods,
         isExp    = directive && directive.isExp,
-        isFn     = directive && directive.isFn,
+        isFn     = (directive && directive.isFn) || (methods && methods[key]),
         bindings = compiler.bindings,
         computed = compiler.options.computed,
         binding  = new Binding(compiler, key, isExp, isFn)
@@ -579,6 +591,9 @@ CompilerProto.createBinding = function (key, directive) {
     if (isExp) {
         // expression bindings are anonymous
         compiler.defineExp(key, binding, directive)
+    } else if (isFn) {
+        bindings[key] = binding
+        binding.value = compiler.vm[key] = methods[key]
     } else {
         bindings[key] = binding
         if (binding.root) {
@@ -653,9 +668,7 @@ CompilerProto.defineProp = function (key, binding) {
 CompilerProto.defineMeta = function (key, binding) {
     var vm = this.vm,
         ob = this.observer,
-        value = binding.value = hasOwn.call(vm, key)
-            ? vm[key]
-            : this.data[key]
+        value = binding.value = vm[key]
     // remove initital meta in data, since the same piece
     // of data can be observed by different VMs, each have
     // its own associated meta info.

+ 1 - 14
src/main.js

@@ -113,19 +113,6 @@ function extend (options) {
     var proto = ExtendedVM.prototype = Object.create(ParentVM.prototype)
     utils.defProtected(proto, 'constructor', ExtendedVM)
 
-    // copy prototype props
-    var methods = options.methods
-    if (methods) {
-        for (var key in methods) {
-            if (
-                !(key in ViewModel.prototype) &&
-                typeof methods[key] === 'function'
-            ) {
-                proto[key] = methods[key]
-            }
-        }
-    }
-
     // allow extended VM to be further extended
     ExtendedVM.extend  = extend
     ExtendedVM.super   = ParentVM
@@ -160,7 +147,7 @@ function inheritOptions (child, parent, topLevel) {
     child = child || {}
     if (!parent) return child
     for (var key in parent) {
-        if (key === 'el' || key === 'methods') continue
+        if (key === 'el') continue
         var val = child[key],
             parentVal = parent[key],
             type = utils.typeOf(val),

+ 4 - 3
src/utils.js

@@ -130,10 +130,11 @@ var utils = module.exports = {
     /**
      *  simple extend
      */
-    extend: function (obj, ext, protective) {
+    extend: function (obj, ext) {
         for (var key in ext) {
-            if ((protective && obj[key]) || obj[key] === ext[key]) continue
-            obj[key] = ext[key]
+            if (obj[key] !== ext[key]) {
+                obj[key] = ext[key]
+            }
         }
         return obj
     },

+ 1 - 0
test/functional/fixtures/events.html

@@ -8,6 +8,7 @@
 </div>
 
 <script>
+Vue.config({debug:true})
 var test = new Vue({
     el: 'div',
     methods: {

+ 1 - 1
test/functional/fixtures/repeated-items.html

@@ -21,7 +21,7 @@
 <script src="../../../dist/vue.js"></script>
 <script>
 
-    //Vue.config({debug: true})
+    Vue.config({debug: true})
 
     var items = [
         { title: 'A'},

+ 2 - 0
test/functional/fixtures/routing.html

@@ -50,6 +50,8 @@
 
 <script>
 
+Vue.config('debug', true)
+
 Vue.component('home', {
     template: '<h1>Home</h1><div class="content">{{>yield}}</div>',
     created: function () {

+ 6 - 6
test/unit/specs/api.js

@@ -460,15 +460,15 @@ describe('API', function () {
 
             describe('methods', function () {
                 
-                it('should be mixed to the exteded VM\'s prototype', function () {
-                    var mixins = {
+                it('should be mixed to the exteded VM\'s instances', function () {
+                    var methods = {
                         c: function () {},
                         d: function () {}
                     }
-                    var Test = Vue.extend({ methods: mixins })
-                    for (var key in mixins) {
-                        assert.strictEqual(Test.prototype[key], mixins[key])
-                    }
+                    var Test = Vue.extend({ methods: methods })
+                    var t = new Test()
+                    assert.strictEqual(t.c, methods.c)
+                    assert.strictEqual(t.d, methods.d)
                 })
 
             })

+ 0 - 7
test/unit/specs/utils.js

@@ -151,13 +151,6 @@ describe('Utils', function () {
             assert.strictEqual(a.b, b.b)
         })
 
-        it('should respect the protective option', function () {
-            var a = {a: 1}, b = {a: {}, b: 2}
-            utils.extend(a, b, true)
-            assert.strictEqual(a.a, 1)
-            assert.strictEqual(a.b, b.b)
-        })
-
         it('should always return the extended object', function () {
             var a = {a: 1}, b = {a: {}, b: 2}
             assert.strictEqual(a, utils.extend(a, b))