mirror of
https://gitee.com/vuejs/vue.git
synced 2024-11-30 02:57:43 +08:00
revert(weex): remove the "receiveTasks" api and support component hook (#7053)
This commit is contained in:
parent
0c11aa8add
commit
0bf0cbef76
@ -125,7 +125,7 @@
|
||||
"typescript": "^2.6.1",
|
||||
"uglify-js": "^3.0.15",
|
||||
"webpack": "^3.10.0",
|
||||
"weex-js-runtime": "^0.23.0",
|
||||
"weex-js-runtime": "^0.23.1",
|
||||
"weex-styler": "^0.3.0"
|
||||
},
|
||||
"config": {
|
||||
|
@ -113,53 +113,6 @@ export function getRoot (instanceId) {
|
||||
return instance.app.$el.toJSON()
|
||||
}
|
||||
|
||||
const jsHandlers = {
|
||||
fireEvent: (id, ...args) => {
|
||||
return fireEvent(instances[id], ...args)
|
||||
},
|
||||
callback: (id, ...args) => {
|
||||
return callback(instances[id], ...args)
|
||||
}
|
||||
}
|
||||
|
||||
function fireEvent (instance, nodeId, type, e, domChanges, params) {
|
||||
const el = instance.document.getRef(nodeId)
|
||||
if (el) {
|
||||
return instance.document.fireEvent(el, type, e, domChanges, params)
|
||||
}
|
||||
return new Error(`invalid element reference "${nodeId}"`)
|
||||
}
|
||||
|
||||
function callback (instance, callbackId, data, ifKeepAlive) {
|
||||
const result = instance.document.taskCenter.callback(callbackId, data, ifKeepAlive)
|
||||
instance.document.taskCenter.send('dom', { action: 'updateFinish' }, [])
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept calls from native (event or callback).
|
||||
*
|
||||
* @param {string} id
|
||||
* @param {array} tasks list with `method` and `args`
|
||||
*/
|
||||
export function receiveTasks (id, tasks) {
|
||||
const instance = instances[id]
|
||||
if (instance && Array.isArray(tasks)) {
|
||||
const results = []
|
||||
tasks.forEach((task) => {
|
||||
const handler = jsHandlers[task.method]
|
||||
const args = [...task.args]
|
||||
/* istanbul ignore else */
|
||||
if (typeof handler === 'function') {
|
||||
args.unshift(id)
|
||||
results.push(handler(...args))
|
||||
}
|
||||
})
|
||||
return results
|
||||
}
|
||||
return new Error(`invalid instance id "${id}" or tasks`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a fresh instance of Vue for each Weex instance.
|
||||
*/
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* globals document */
|
||||
|
||||
import { makeMap } from 'shared/util'
|
||||
import { warn } from 'core/util/index'
|
||||
|
||||
export const isReservedTag = makeMap(
|
||||
'template,script,style,element,content,slot,link,meta,svg,view,' +
|
||||
@ -20,7 +21,7 @@ export const canBeLeftOpenTag = makeMap(
|
||||
)
|
||||
|
||||
export const isRuntimeComponent = makeMap(
|
||||
'richtext,trisition,trisition-group',
|
||||
'richtext,transition,transition-group',
|
||||
true
|
||||
)
|
||||
|
||||
@ -40,3 +41,14 @@ export function query (el, document) {
|
||||
document.documentElement.appendChild(placeholder)
|
||||
return placeholder
|
||||
}
|
||||
|
||||
export function registerHook (cid, type, hook, fn) {
|
||||
if (!document || !document.taskCenter) {
|
||||
warn(`Can't find available "document" or "taskCenter".`)
|
||||
return
|
||||
}
|
||||
if (typeof document.taskCenter.registerHook === 'function') {
|
||||
return document.taskCenter.registerHook(cid, type, hook, fn)
|
||||
}
|
||||
warn(`Not support to register component hook "${type}@${hook}#${cid}".`)
|
||||
}
|
||||
|
@ -152,57 +152,6 @@ describe('framework APIs', () => {
|
||||
expect(root).toMatch(/not found/)
|
||||
})
|
||||
|
||||
// TODO: deprecated, move to weex-js-runtime
|
||||
it('receiveTasks: fireEvent', (done) => {
|
||||
const id = String(Date.now() * Math.random())
|
||||
const instance = createInstance(id, `
|
||||
new Vue({
|
||||
data: {
|
||||
x: 'Hello'
|
||||
},
|
||||
methods: {
|
||||
update: function (e) {
|
||||
this.x = 'World'
|
||||
}
|
||||
},
|
||||
render: function (createElement) {
|
||||
return createElement('div', {}, [
|
||||
createElement('text', { attrs: { value: this.x }, on: { click: this.update }}, [])
|
||||
])
|
||||
},
|
||||
el: "body"
|
||||
})
|
||||
`)
|
||||
expect(getRoot(instance)).toEqual({
|
||||
type: 'div',
|
||||
children: [{
|
||||
type: 'text',
|
||||
attr: { value: 'Hello' },
|
||||
event: ['click']
|
||||
}]
|
||||
})
|
||||
const textRef = framework.getRoot(id).children[0].ref
|
||||
framework.receiveTasks(id, [
|
||||
{ method: 'fireEvent', args: [textRef, 'click'] }
|
||||
])
|
||||
setTimeout(() => {
|
||||
expect(getRoot(instance)).toEqual({
|
||||
type: 'div',
|
||||
children: [{
|
||||
type: 'text',
|
||||
attr: { value: 'World' },
|
||||
event: ['click']
|
||||
}]
|
||||
})
|
||||
framework.destroyInstance(id)
|
||||
const result = framework.receiveTasks(id, [
|
||||
{ method: 'fireEvent', args: [textRef, 'click'] }
|
||||
])
|
||||
expect(result instanceof Error).toBe(true)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('vm.$getConfig', () => {
|
||||
const id = String(Date.now() * Math.random())
|
||||
global.WXEnvironment = {
|
||||
|
Loading…
Reference in New Issue
Block a user