Advertisement
Guest User

Untitled

a guest
Aug 26th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. function performWork(deadline) {
  2. if (!nextUnitOfWork) {
  3. // on initial render
  4. // or if all work is complete and the nextUnitOfWork is null
  5. //grab the first item on the workInProgress queue.
  6. initialUnitOfWork();
  7. }
  8. loopThroughWork(deadline)
  9. if (nextUnitOfWork || workQueue.length > 0) {
  10. // if theres more work to be done. get to know when the browser will be occupied
  11. // and check if we can perform some work with the timing provided.
  12. requestIdleCallback(performWork);
  13. }
  14. }
  15.  
  16. function initialUnitOfWork() {
  17. //grab the first item in the array
  18. // its a first come first serve scenario.
  19. const update = workQueue.shift();
  20.  
  21. // if there are no updates pending
  22. // abort since there is no work to do.
  23. if (!update) {
  24. return;
  25. }
  26.  
  27. // this call will apply if the update came from setState
  28. // we need the object passed in this.setState to the
  29. // partialState of the current fiber
  30. if (update.partialState) {
  31. update.instance.__fiber.partialState = update.partialState;
  32. }
  33.  
  34. const root =
  35. update.from === HOST_ROOT
  36. ? update.dom._rootContainerFiber
  37. : getRootNode(update.instance.__fiber);
  38.  
  39. nextUnitOfWork = {
  40. tag: HOST_ROOT,
  41. stateNode: update.dom || root.stateNode, // the properties from the update are checked first for existence
  42. props: update.newProps || root.props, // if the update properties are missing default back to the root properties
  43. alternate: root
  44. };
  45. }
  46.  
  47. function getRootNode(fiber) {
  48. // climb up the fiber until we reach to the fiber with no parent
  49. // This will give us the alternate property of each fiber if its not
  50. // the host_root, meaning the fiber at the very top of the tree
  51. let node = fiber;
  52. while (node.parent) {
  53. // as long as the current node has a parent keep climbing up
  54. // until node.parent is null.
  55. node = node.parent;
  56. }
  57. return node;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement