Skip to content

Commit

Permalink
Moduralize the noop() function (vuejs#2834)
Browse files Browse the repository at this point in the history
Currently the `noop` function is being declared and used randomly at
places. This commit moduralizes it (à la lodash) for more DRY code.
  • Loading branch information
phanan authored and yyx990803 committed May 10, 2016
1 parent 5a5c7eb commit e38e494
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/compiler/codegen.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { genHandlers } from './events'
import { ref } from './directives/ref'
import { baseWarn } from './helpers'
import { noop } from 'shared/util'

const baseDirectives = {
ref,
cloak: function () {} // noop
cloak: noop
}

// configurable state
Expand Down
5 changes: 2 additions & 3 deletions src/core/instance/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
isArray,
isPlainObject,
bind,
validateProp
validateProp,
noop
} from '../util/index'

export function initState (vm) {
Expand Down Expand Up @@ -63,8 +64,6 @@ function initData (vm) {
observe(data, vm)
}

function noop () {}

function initComputed (vm) {
const computed = vm.$options.computed
if (computed) {
Expand Down
3 changes: 2 additions & 1 deletion src/entries/web-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import baseModules from 'core/vdom/modules/index'
import platformModules from 'web/runtime/modules/index'
import { query, isUnknownElement, isReservedTag } from 'web/util/index'
import { inBrowser } from 'core/util/env'
import { noop } from 'core/util/index'

// install platform specific utils
Vue.config.isUnknownElement = isUnknownElement
Expand All @@ -18,7 +19,7 @@ Vue.options.directives = platformDirectives
const modules = baseModules.concat(platformModules)
Vue.prototype.__patch__ = inBrowser
? createPatchFunction({ nodeOps, modules })
: function noop () {}
: noop

// wrap mount
Vue.prototype.$mount = function (el) {
Expand Down
5 changes: 5 additions & 0 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,8 @@ export function isPlainObject (obj) {
* @return {Boolean}
*/
export const isArray = Array.isArray

/**
* Perform no operation.
*/
export function noop () {}

0 comments on commit e38e494

Please sign in to comment.