Evan You 10 лет назад
Родитель
Сommit
19cfe95543
2 измененных файлов с 14 добавлено и 158 удалено
  1. 14 52
      src/directives/component.js
  2. 0 106
      test/unit/specs/directives/component_spec.js

+ 14 - 52
src/directives/component.js

@@ -25,14 +25,6 @@ module.exports = {
       // we simply remove it from the DOM and save it in a
       // cache object, with its constructor id as the key.
       this.keepAlive = this.param('keep-alive') != null
-      // wait for event before insertion
-      this.waitForEvent = this.param('wait-for')
-
-      if (process.env.NODE_ENV !== 'production') {
-        if (this.waitForEvent) {
-          _.deprecation.WAIT_FOR()
-        }
-      }
 
       // check ref
       // TODO: only check ref in 1.0.0
@@ -84,31 +76,16 @@ module.exports = {
    */
 
   initStatic: function () {
-    // wait-for
     var anchor = this.el
-    var options
-    var waitFor = this.waitForEvent
     var activateHook = this.Component.options.activate
-    if (waitFor) {
-      options = {
-        created: function () {
-          this.$once(waitFor, insert)
-        }
-      }
-    }
-    var child = this.childVM = this.build(options)
-    if (!this.waitForEvent) {
-      if (activateHook) {
-        activateHook.call(child, insert)
-      } else {
-        child.$before(anchor)
-        _.remove(anchor)
-      }
+    var child = this.childVM = this.build()
+    if (activateHook) {
+      activateHook.call(child, insert)
+    } else {
+      insert()
     }
     function insert () {
-      // TODO: no need to fallback to this in 1.0.0
-      // once wait-for is removed
-      (child || this).$before(anchor)
+      child.$before(anchor)
       _.remove(anchor)
     }
   },
@@ -145,33 +122,18 @@ module.exports = {
     } else {
       this.resolveComponent(value, _.bind(function () {
         this.unbuild(true)
-        var options
         var self = this
-        var waitFor = this.waitForEvent
         var activateHook = this.Component.options.activate
-        if (waitFor) {
-          options = {
-            created: function () {
-              this.$once(waitFor, insert)
-            }
-          }
-        }
         var cached = this.getCached()
-        var newComponent = this.build(options)
-        if ((!waitFor && !activateHook) || cached) {
-          this.transition(newComponent, cb)
-        } else {
+        var newComponent = this.build()
+        if (activateHook && !cached) {
           this.waitingFor = newComponent
-          if (activateHook) {
-            activateHook.call(newComponent, insert)
-          }
-        }
-
-        function insert () {
-          self.waitingFor = null
-          // TODO: no need to fallback to this in 1.0.0
-          // once wait-for is removed
-          self.transition((newComponent || this), cb)
+          activateHook.call(newComponent, function () {
+            self.waitingFor = null
+            self.transition(newComponent, cb)
+          })
+        } else {
+          this.transition(newComponent, cb)
         }
       }, this))
     }

+ 0 - 106
test/unit/specs/directives/component_spec.js

@@ -299,21 +299,6 @@ if (_.inBrowser) {
       expect(el.innerHTML).toBe('<ul><li>1</li><li>2</li></ul>')
     })
 
-    it('wait-for for static component', function () {
-      var vm = new Vue({
-        el: el,
-        template: '<view-a wait-for="ok"></view-a>',
-        components: {
-          'view-a': {
-            template: 'AAA'
-          }
-        }
-      })
-      expect(el.textContent).toBe('')
-      vm.$children[0].$emit('ok')
-      expect(el.textContent).toBe('AAA')
-    })
-
     it('activate hook for static component', function (done) {
       new Vue({
         el: el,
@@ -334,63 +319,6 @@ if (_.inBrowser) {
       })
     })
 
-    it('sync wait-for inside compiled hook', function () {
-      new Vue({
-        el: el,
-        template: '<view-a wait-for="ok"></view-a>',
-        components: {
-          'view-a': {
-            template: 'AAA',
-            compiled: function () {
-              expect(el.textContent).toBe('')
-              this.$emit('ok')
-            }
-          }
-        }
-      })
-      expect(el.textContent).toBe('AAA')
-    })
-
-    it('wait-for for dynamic components', function (done) {
-      var vm = new Vue({
-        el: el,
-        data: {
-          view: 'view-a'
-        },
-        template: '<component is="{{view}}" wait-for="ok"></component>',
-        components: {
-          'view-a': {
-            template: 'AAA'
-          },
-          'view-b': {
-            template: 'BBB'
-          }
-        }
-      })
-      vm.$children[0].$emit('ok')
-      expect(el.textContent).toBe('AAA')
-      vm.view = 'view-b'
-      _.nextTick(function () {
-        expect(el.textContent).toBe('AAA')
-        // old vm is already removed, this is the new vm
-        expect(vm.$children.length).toBe(1)
-        vm.$children[0].$emit('ok')
-        expect(el.textContent).toBe('BBB')
-        // ensure switching before ready event correctly
-        // cleans up the component being waited on.
-        // see #1152
-        vm.view = 'view-a'
-        _.nextTick(function () {
-          vm.view = 'view-b'
-          _.nextTick(function () {
-            expect(vm.$children.length).toBe(1)
-            expect(vm.$children[0].$el.textContent).toBe('BBB')
-            done()
-          })
-        })
-      })
-    })
-
     it('activate hook for dynamic components', function (done) {
       var next
       var vm = new Vue({
@@ -440,40 +368,6 @@ if (_.inBrowser) {
       })
     })
 
-    // #1150
-    it('wait-for + keep-alive', function (done) {
-      var vm = new Vue({
-        el: el,
-        data: {
-          view: 'view-a'
-        },
-        template: '<component is="{{view}}" wait-for="ok" keep-alive></component>',
-        components: {
-          'view-a': {
-            template: 'AAA'
-          },
-          'view-b': {
-            template: 'BBB'
-          }
-        }
-      })
-      vm.$children[0].$emit('ok')
-      expect(el.textContent).toBe('AAA')
-      vm.view = 'view-b'
-      _.nextTick(function () {
-        expect(vm.$children.length).toBe(2)
-        vm.$children[1].$emit('ok')
-        expect(el.textContent).toBe('BBB')
-        vm.view = 'view-a'
-        _.nextTick(function () {
-          // should switch without the need to emit
-          // because of keep-alive
-          expect(el.textContent).toBe('AAA')
-          done()
-        })
-      })
-    })
-
     it('activate hook + keep-alive', function (done) {
       var next
       var vm = new Vue({