Browse Source

deprecate $remove

dev
Evan You 9 years ago
parent
commit
6c8182ee4d
  1. 2
      examples/svg/svg.js
  2. 2
      examples/todomvc/js/app.js
  3. 3
      src/runtime/global-api/index.js
  4. 4
      src/runtime/instance/lifecycle.js
  5. 2
      src/runtime/instance/render.js
  6. 19
      src/runtime/observer/array.js
  7. 4
      src/runtime/observer/dep.js
  8. 3
      src/runtime/observer/index.js
  9. 3
      src/runtime/observer/watcher.js
  10. 9
      src/runtime/util/lang.js
  11. 4
      src/runtime/vdom-web/modules/transition.js

2
examples/svg/svg.js

@ -81,7 +81,7 @@ new Vue({
}, },
remove: function (stat) { remove: function (stat) {
if (this.stats.length > 3) { if (this.stats.length > 3) {
this.stats.$remove(stat) this.stats.splice(this.stats.indexOf(stat), 1)
} else { } else {
alert('Can\'t delete more!') alert('Can\'t delete more!')
} }

2
examples/todomvc/js/app.js

@ -81,7 +81,7 @@
}, },
removeTodo: function (todo) { removeTodo: function (todo) {
this.todos.$remove(todo); this.todos.splice(this.todos.indexOf(todo), 1);
}, },
editTodo: function (todo) { editTodo: function (todo) {

3
src/runtime/global-api/index.js

@ -4,7 +4,7 @@ import { initUse } from './use'
import { initMixin } from './mixin' import { initMixin } from './mixin'
import { initExtend } from './extend' import { initExtend } from './extend'
import { initAssetRegisters } from './assets' import { initAssetRegisters } from './assets'
import { nextTick } from '../util/index' import { remove, nextTick } from '../util/index'
import { set, del } from '../observer/index' import { set, del } from '../observer/index'
import directives from '../directives/index' import directives from '../directives/index'
@ -13,6 +13,7 @@ export function initGlobalAPI (Vue) {
Vue.util = util Vue.util = util
Vue.set = set Vue.set = set
Vue.delete = del Vue.delete = del
Vue.remove = remove
Vue.nextTick = nextTick Vue.nextTick = nextTick
Vue.options = { Vue.options = {

4
src/runtime/instance/lifecycle.js

@ -1,5 +1,5 @@
import Watcher from '../observer/watcher' import Watcher from '../observer/watcher'
import { query, toArray, warn, validateProp } from '../util/index' import { query, toArray, warn, validateProp, remove } from '../util/index'
import { observerState } from '../observer/index' import { observerState } from '../observer/index'
import { updateListeners } from '../vdom/helpers' import { updateListeners } from '../vdom/helpers'
@ -115,7 +115,7 @@ export function lifecycleMixin (Vue) {
// remove self from parent // remove self from parent
const parent = this.$parent const parent = this.$parent
if (parent && !parent._isBeingDestroyed) { if (parent && !parent._isBeingDestroyed) {
parent.$children.$remove(this) remove(parent.$children, this)
} }
// unregister ref // unregister ref
if (this._ref) { if (this._ref) {

2
src/runtime/instance/render.js

@ -89,7 +89,7 @@ export function renderMixin (Vue) {
const refs = this.$refs const refs = this.$refs
if (remove) { if (remove) {
if (vFor) { if (vFor) {
refs[key].$remove(ref) remove(refs[key], ref)
} else { } else {
refs[key] = undefined refs[key] = undefined
} }

19
src/runtime/observer/array.js

@ -47,22 +47,3 @@ export const arrayMethods = Object.create(arrayProto)
return result return result
}) })
}) })
/**
* Convenience method to remove the element at given index or target element reference.
*
* @param {*} item
*/
def(
arrayProto,
'$remove',
function $remove (item) {
/* istanbul ignore if */
if (!this.length) return
var index = this.indexOf(item)
if (index > -1) {
return this.splice(index, 1)
}
}
)

4
src/runtime/observer/dep.js

@ -1,3 +1,5 @@
import { remove } from '../util/index'
let uid = 0 let uid = 0
/** /**
@ -34,7 +36,7 @@ Dep.prototype.addSub = function (sub) {
*/ */
Dep.prototype.removeSub = function (sub) { Dep.prototype.removeSub = function (sub) {
this.subs.$remove(sub) remove(this.subs, sub)
} }
/** /**

3
src/runtime/observer/index.js

@ -2,6 +2,7 @@ import Dep from './dep'
import { arrayMethods } from './array' import { arrayMethods } from './array'
import { import {
def, def,
remove,
isArray, isArray,
isObject, isObject,
isPlainObject, isPlainObject,
@ -109,7 +110,7 @@ Observer.prototype.addVm = function (vm) {
*/ */
Observer.prototype.removeVm = function (vm) { Observer.prototype.removeVm = function (vm) {
this.vms.$remove(vm) remove(this.vms, vm)
} }
// helpers // helpers

3
src/runtime/observer/watcher.js

@ -3,6 +3,7 @@ import Dep from './dep'
import { pushWatcher } from './batcher' import { pushWatcher } from './batcher'
import { import {
warn, warn,
remove,
extend, extend,
isArray, isArray,
isObject, isObject,
@ -229,7 +230,7 @@ Watcher.prototype.teardown = function () {
// if the vm is being destroyed or is performing a v-for // if the vm is being destroyed or is performing a v-for
// re-render (the watcher list is then filtered by v-for). // re-render (the watcher list is then filtered by v-for).
if (!this.vm._isBeingDestroyed && !this.vm._vForRemoving) { if (!this.vm._isBeingDestroyed && !this.vm._vForRemoving) {
this.vm._watchers.$remove(this) remove(this.vm._watchers, this)
} }
var i = this.deps.length var i = this.deps.length
while (i--) { while (i--) {

9
src/runtime/util/lang.js

@ -1,3 +1,12 @@
export function remove (arr, item) {
if (arr.length) {
const index = arr.indexOf(item)
if (index > -1) {
return arr.splice(index, 1)
}
}
}
/** /**
* Check if a string starts with $ or _ * Check if a string starts with $ or _
* *

4
src/runtime/vdom-web/modules/transition.js

@ -1,5 +1,5 @@
import { addClass, removeClass } from '../class-util' import { addClass, removeClass } from '../class-util'
import { isIE9, inBrowser, cached } from '../../util/index' import { isIE9, inBrowser, cached, remove } from '../../util/index'
const TRANSITION = 'transition' const TRANSITION = 'transition'
const ANIMATION = 'animation' const ANIMATION = 'animation'
@ -165,7 +165,7 @@ function addTransitionClass (el, cls) {
} }
function removeTransitionClass (el, cls) { function removeTransitionClass (el, cls) {
el._transitionClasses.$remove(cls) remove(el._transitionClasses, cls)
removeClass(el, cls) removeClass(el, cls)
} }

Loading…
Cancel
Save