index.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* @flow */
  2. declare var document: Object;
  3. import { makeMap } from 'shared/util'
  4. import { warn } from 'core/util/index'
  5. export const RECYCLE_LIST_MARKER = '@inRecycleList'
  6. export const isReservedTag = makeMap(
  7. 'template,script,style,element,content,slot,link,meta,svg,view,' +
  8. 'a,div,img,image,text,span,input,switch,textarea,spinner,select,' +
  9. 'slider,slider-neighbor,indicator,canvas,' +
  10. 'list,cell,header,loading,loading-indicator,refresh,scrollable,scroller,' +
  11. 'video,web,embed,tabbar,tabheader,datepicker,timepicker,marquee,countdown',
  12. true
  13. )
  14. // Elements that you can, intentionally, leave open (and which close themselves)
  15. // more flexible than web
  16. export const canBeLeftOpenTag = makeMap(
  17. 'web,spinner,switch,video,textarea,canvas,' +
  18. 'indicator,marquee,countdown',
  19. true
  20. )
  21. export const isRuntimeComponent = makeMap(
  22. 'richtext,transition,transition-group',
  23. true
  24. )
  25. export const isUnaryTag = makeMap(
  26. 'embed,img,image,input,link,meta',
  27. true
  28. )
  29. export function mustUseProp (tag: string, type: ?string, name: string): boolean {
  30. return false
  31. }
  32. export function getTagNamespace (tag?: string): string | void { }
  33. export function isUnknownElement (tag?: string): boolean {
  34. return false
  35. }
  36. export function query (el: string | Element, document: Object) {
  37. // document is injected by weex factory wrapper
  38. const placeholder = document.createComment('root')
  39. placeholder.hasAttribute = placeholder.removeAttribute = function () {} // hack for patch
  40. document.documentElement.appendChild(placeholder)
  41. return placeholder
  42. }
  43. // Register the component hook to weex native render engine.
  44. // The hook will be triggered by native, not javascript.
  45. export function registerComponentHook (
  46. componentId: string,
  47. type: string, // hook type, could be "lifecycle" or "instance"
  48. hook: string, // hook name
  49. fn: Function
  50. ) {
  51. if (!document || !document.taskCenter) {
  52. warn(`Can't find available "document" or "taskCenter".`)
  53. return
  54. }
  55. if (typeof document.taskCenter.registerHook === 'function') {
  56. return document.taskCenter.registerHook(componentId, type, hook, fn)
  57. }
  58. warn(`Failed to register component hook "${type}@${hook}#${componentId}".`)
  59. }
  60. // Updates the state of the component to weex native render engine.
  61. export function updateComponentData (
  62. componentId: string,
  63. newData: Object | void,
  64. callback?: Function
  65. ) {
  66. if (!document || !document.taskCenter) {
  67. warn(`Can't find available "document" or "taskCenter".`)
  68. return
  69. }
  70. if (typeof document.taskCenter.updateData === 'function') {
  71. return document.taskCenter.updateData(componentId, newData, callback)
  72. }
  73. warn(`Failed to update component data (${componentId}).`)
  74. }