Skip to content

Commit

Permalink
refactor(utils): merge extend and assign util function
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jul 3, 2018
1 parent c621a3b commit 3cad567
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
3 changes: 1 addition & 2 deletions src/components/link.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @flow */

import { createRoute, isSameRoute, isIncludedRoute } from '../util/route'
import { _Vue } from '../install'
import { extend } from '../util/misc'

// work around weird flow bug
const toTypes: Array<Function> = [String, Object]
Expand Down Expand Up @@ -88,7 +88,6 @@ export default {
if (a) {
// in case the <a> is a static node
a.isStatic = false
const extend = _Vue.util.extend
const aData = a.data = extend({}, a.data)
aData.on = on
const aAttrs = a.data.attrs = extend({}, a.data.attrs)
Expand Down
9 changes: 2 additions & 7 deletions src/components/view.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { warn } from '../util/warn'
import { extend } from '../util/misc'

export default {
name: 'RouterView',
Expand All @@ -10,6 +11,7 @@ export default {
}
},
render (_, { props, children, parent, data }) {
// used by devtools to display a router-view badge
data.routerView = true

// directly use parent context's createElement() function
Expand Down Expand Up @@ -106,10 +108,3 @@ function resolveProps (route, config) {
}
}
}

function extend (to, from) {
for (const key in from) {
to[key] = from[key]
}
return to
}
12 changes: 3 additions & 9 deletions src/util/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { parsePath, resolvePath } from './path'
import { resolveQuery } from './query'
import { fillParams } from './params'
import { warn } from './warn'
import { extend } from './misc'

export function normalizeLocation (
raw: RawLocation,
Expand All @@ -20,9 +21,9 @@ export function normalizeLocation (

// relative params
if (!next.path && next.params && current) {
next = assign({}, next)
next = extend({}, next)
next._normalized = true
const params: any = assign(assign({}, current.params), next.params)
const params: any = extend(extend({}, current.params), next.params)
if (current.name) {
next.name = current.name
next.params = params
Expand Down Expand Up @@ -59,10 +60,3 @@ export function normalizeLocation (
hash
}
}

function assign (a, b) {
for (const key in b) {
a[key] = b[key]
}
return a
}
6 changes: 6 additions & 0 deletions src/util/misc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function extend (a, b) {
for (const key in b) {
a[key] = b[key]
}
return a
}

0 comments on commit 3cad567

Please sign in to comment.