Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(weex): update weex utils #7115

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions src/platforms/weex/util/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* globals document */
/* @flow */
declare var document: Object;

import { makeMap } from 'shared/util'
import { warn } from 'core/util/index'
Expand Down Expand Up @@ -30,25 +31,50 @@ export const isUnaryTag = makeMap(
true
)

export function mustUseProp () { /* console.log('mustUseProp') */ }
export function getTagNamespace () { /* console.log('getTagNamespace') */ }
export function isUnknownElement () { /* console.log('isUnknownElement') */ }
export function mustUseProp (tag: string, type: ?string, name: string): boolean {
return false
}

export function getTagNamespace (tag?: string): string | void { }

export function isUnknownElement (tag?: string): boolean {
return false
}

export function query (el, document) {
export function query (el: string | Element, document: Object) {
// document is injected by weex factory wrapper
const placeholder = document.createComment('root')
placeholder.hasAttribute = placeholder.removeAttribute = function () {} // hack for patch
document.documentElement.appendChild(placeholder)
return placeholder
}

export function registerHook (cid, type, hook, fn) {
// Register the component hook to weex native render engine.
// The hook will be triggered by native, not javascript.
export function registerComponentHook (
componentId: string,
type: string, // hook type, could be "lifecycle" or "instance"
hook: string, // hook name
fn: Function
) {
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)
return document.taskCenter.registerHook(componentId, type, hook, fn)
}
warn(`Failed to register component hook "${type}@${hook}#${componentId}".`)
}

// Updates the state of the component to weex native render engine.
export function updateComponentData (componentId: string, newData: Object) {
if (!document || !document.taskCenter) {
warn(`Can't find available "document" or "taskCenter".`)
return
}
if (typeof document.taskCenter.updateData === 'function') {
return document.taskCenter.updateData(componentId, newData)
}
warn(`Not support to register component hook "${type}@${hook}#${cid}".`)
warn(`Failed to update component data (${componentId}).`)
}