Skip to content

Commit c8c1056

Browse files
committed
Merge branch 'dev' of github.com:didi/cube-ui into dev
2 parents d715859 + 4913948 commit c8c1056

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

src/common/helpers/create-api-component.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ export default function createAPIComponent(Vue, Component, events = [], single =
99
before(fn) {
1010
beforeFns.push(fn)
1111
},
12-
open(data, renderFn, instanceSingle) {
13-
if (typeof renderFn !== 'function') {
14-
instanceSingle = renderFn
12+
open(data, renderFn, options) {
13+
if (typeof renderFn !== 'function' && options === undefined) {
14+
options = renderFn
1515
renderFn = null
1616
}
17+
let instanceSingle = options
18+
if (typeof options === 'object') {
19+
instanceSingle = !!options.single
20+
delete options.single
21+
}
22+
1723
beforeFns.forEach((before) => {
1824
before(data, renderFn, instanceSingle)
1925
})
@@ -26,7 +32,7 @@ export default function createAPIComponent(Vue, Component, events = [], single =
2632
// singleComponent.show && singleComponent.show()
2733
return singleComponent
2834
}
29-
const component = instantiateComponent(Vue, Component, data, renderFn)
35+
const component = instantiateComponent(Vue, Component, data, renderFn, options)
3036
const instance = component.$parent
3137
const originRemove = component.remove
3238

@@ -61,13 +67,27 @@ export default function createAPIComponent(Vue, Component, events = [], single =
6167
},
6268
create(config, renderFn, single) {
6369
const ownerInstance = this
70+
const isInVueInstance = !!ownerInstance.$on
6471
const renderData = parseRenderData(config, events)
6572

6673
cancelWatchProps()
6774
processProps()
6875
processEvents()
6976

70-
const component = api.open(renderData, renderFn, single)
77+
if (typeof renderFn !== 'function' && single === undefined) {
78+
single = !!renderFn
79+
renderFn = null
80+
}
81+
// to get Vue options
82+
// store router i18n ...
83+
const options = {
84+
single: single
85+
}
86+
if (isInVueInstance) {
87+
options.parent = ownerInstance
88+
}
89+
90+
const component = api.open(renderData, renderFn, options)
7191
if (component.__cube__parent !== ownerInstance) {
7292
component.__cube__parent = ownerInstance
7393
const beforeDestroy = function () {
@@ -78,7 +98,7 @@ export default function createAPIComponent(Vue, Component, events = [], single =
7898
ownerInstance.$off('hook:beforeDestroy', beforeDestroy)
7999
component.__cube__parent = null
80100
}
81-
ownerInstance.$on && ownerInstance.$on('hook:beforeDestroy', beforeDestroy)
101+
isInVueInstance && ownerInstance.$on('hook:beforeDestroy', beforeDestroy)
82102
}
83103
return component
84104

@@ -100,7 +120,7 @@ export default function createAPIComponent(Vue, Component, events = [], single =
100120
renderData.props[key] = propKey
101121
}
102122
})
103-
if (ownerInstance.$watch) {
123+
if (isInVueInstance) {
104124
ownerInstance.__createAPI_watcher = ownerInstance.$watch(function () {
105125
const props = {}
106126
watchKeys.forEach((key, i) => {

src/common/helpers/dom.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ let vendor = (() => {
6565
})()
6666

6767
export function prefixStyle(style) {
68+
/* istanbul ignore if */
6869
if (vendor === false) {
6970
return false
7071
}

src/common/helpers/instantiate-component.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
export default function instantiateComponent(Vue, Component, data, renderFn) {
1+
export default function instantiateComponent(Vue, Component, data, renderFn, options) {
22
let renderData
33
let childrenRenderFn
4+
5+
if (options === undefined) {
6+
options = {}
7+
}
8+
49
const instance = new Vue({
10+
...options,
511
render(createElement) {
612
let children = childrenRenderFn && childrenRenderFn(createElement)
713
if (children && !Array.isArray(children)) {

src/common/helpers/raf.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ export const requestAnimationFrame = (() => {
1111
return noop
1212
}
1313
return window.requestAnimationFrame ||
14+
/* istanbul ignore next */
1415
window.webkitRequestAnimationFrame ||
16+
/* istanbul ignore next */
1517
window.mozRequestAnimationFrame ||
18+
/* istanbul ignore next */
1619
window.oRequestAnimationFrame ||
1720
// if all else fails, use setTimeout
21+
/* istanbul ignore next */
1822
function (callback) {
1923
return window.setTimeout(callback, (callback.interval || DEFAULT_INTERVAL) / 2) // make interval as precise as possible.
2024
}
@@ -26,9 +30,13 @@ export const cancelAnimationFrame = (() => {
2630
return noop
2731
}
2832
return window.cancelAnimationFrame ||
33+
/* istanbul ignore next */
2934
window.webkitCancelAnimationFrame ||
35+
/* istanbul ignore next */
3036
window.mozCancelAnimationFrame ||
37+
/* istanbul ignore next */
3138
window.oCancelAnimationFrame ||
39+
/* istanbul ignore next */
3240
function (id) {
3341
window.clearTimeout(id)
3442
}

src/common/helpers/util.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ function findIndex(ary, fn) {
22
if (ary.findIndex) {
33
return ary.findIndex(fn)
44
}
5+
/* istanbul ignore next */
56
let index = -1
7+
/* istanbul ignore next */
68
ary.some(function (item, i, ary) {
79
const ret = fn.call(this, item, i, ary)
810
if (ret) {
911
index = i
1012
return ret
1113
}
1214
})
15+
/* istanbul ignore next */
1316
return index
1417
}
1518

0 commit comments

Comments
 (0)