ad84e7602f9b6f5a6c19d191943a44eefe335edfb8c6f9d4ee0f748d6da6e0c26c1b9ed227ff97660a29f5e6193ec4a687f50876b64370dbf1f01a722fef73-exec 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* @flow */
  2. declare var document: WeexDocument;
  3. import { warn } from 'core/util/index'
  4. export const RECYCLE_LIST_MARKER = '@inRecycleList'
  5. // Register the component hook to weex native render engine.
  6. // The hook will be triggered by native, not javascript.
  7. export function registerComponentHook (
  8. componentId: string,
  9. type: string, // hook type, could be "lifecycle" or "instance"
  10. hook: string, // hook name
  11. fn: Function
  12. ) {
  13. if (!document || !document.taskCenter) {
  14. warn(`Can't find available "document" or "taskCenter".`)
  15. return
  16. }
  17. if (typeof document.taskCenter.registerHook === 'function') {
  18. return document.taskCenter.registerHook(componentId, type, hook, fn)
  19. }
  20. warn(`Failed to register component hook "${type}@${hook}#${componentId}".`)
  21. }
  22. // Updates the state of the component to weex native render engine.
  23. export function updateComponentData (
  24. componentId: string,
  25. newData: Object | void,
  26. callback?: Function
  27. ) {
  28. if (!document || !document.taskCenter) {
  29. warn(`Can't find available "document" or "taskCenter".`)
  30. return
  31. }
  32. if (typeof document.taskCenter.updateData === 'function') {
  33. return document.taskCenter.updateData(componentId, newData, callback)
  34. }
  35. warn(`Failed to update component data (${componentId}).`)
  36. }