Skip to content

Instantly share code, notes, and snippets.

@Elevista
Last active December 19, 2017 16:36
Show Gist options
  • Save Elevista/0e25177e57053e06764b7250db3816e0 to your computer and use it in GitHub Desktop.
Save Elevista/0e25177e57053e06764b7250db3816e0 to your computer and use it in GitHub Desktop.
lodash로 vue 모델의 배열을 다룰때 뮤테이션 감지를 시키기 위해 기본 함수를 래핑합니다.
let lodash = _.runInContext()
export let wrapLodashArrForVue = _(['pull', 'pullAll', 'pullAllBy', 'pullAllWith', 'pullAt', 'remove'])
.map(fnName => {
let fn = lodash[fnName]
return [
fnName,
function (v, …args) {
let ret = fn(v, …args)
if (v instanceof Array) v.push()
return ret
}]
})
.fromPairs()
.value()
// --------------------------------------------------------------------
import { wrapLodashArrForVue } from './vueLodashArray'
_.mixin(wrapLodashArrForVue)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment