All files / src/messemger-renderer renderer.js

50% Statements 17/34
55.56% Branches 5/9
50% Functions 1/2
50% Lines 17/34
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124          6x   29x 29x       29x       51x               49x               20x                   20x                   22x         51x 51x       51x 51x             26x                                     18x 18x     18x                                                            
import Reconciler from 'react-reconciler';
import emptyObject from 'fbjs/lib/emptyObject';
 
import { createElement } from './createElement';
 
export const Renderer = Reconciler({
  appendInitialChild(parentInstance, child) {
    console.log('appendinitial', parentInstance, child, typeof child);
    Iif(typeof child === 'string'){
      console.log('invariant string')
      return;
    }
    parentInstance.appendChild(child);
  },
 
  createInstance(type, props, internalInstanceHandle) {
    return createElement(type, props, internalInstanceHandle);
  },
 
  createTextInstance(text, rootContainerInstance, internalInstanceHandle) {
    return text;
  },
 
  finalizeInitialChildren(wordElement, type, props) {
    return false;
  },
 
  getPublicInstance(inst) {
    return inst;
  },
 
  prepareForCommit(...rest) {
    console.log('prepareForCommit', rest);
    // noop
  },
 
  prepareUpdate(wordElement, type, oldProps, newProps) {
    console.log('prepareUpdate', wordElement, type, oldProps, newProps);
    return true;
  },
 
  resetAfterCommit(...rest) {
    console.log('resetAfterCommit', rest);
    // noop
  },
 
  resetTextContent(wordElement) {
    console.log('resetTextContent', wordElement);
    // noop
  },
 
  getRootHostContext(rootInstance) {
    console.log('getRootHostContext', rootInstance);
    // You can use this 'rootInstance' to pass data from the roots.
  },
 
  getChildHostContext(...rest) {
    console.log('getChildHostContext', rest);
    return emptyObject;
  },
 
  shouldSetTextContent(type, props) {
    console.log('shouldSetTextContent', type, props);
    return (
      type === 'Text' ||
      typeof props.children === 'string' ||
      typeof props.children === 'number'
    );
  },
 
  now: () => () => {
    console.log('now');
    // noop
  },
 
 
  useSyncScheduling: true,
 
  mutation: {
    appendChild(parentInstance, child) {
      console.log('mutation', parentInstance, child);
      if (parentInstance.appendChild) {
        parentInstance.appendChild(child);
      } else {
        parentInstance.document = child;
      }
    },
 
    appendChildToContainer(parentInstance, child) {
      console.log('appendChildToContainer', parentInstance, child);
      Iif (parentInstance.appendChild) {
        parentInstance.appendChild(child, parentInstance);
      } else {
        parentInstance.children = child;
      }
    },
 
    removeChild(parentInstance, child) {
      parentInstance.removeChild(child);
    },
 
    removeChildFromContainer(parentInstance, child) {
      parentInstance.removeChild(child);
    },
 
    insertBefore(parentInstance, child, beforeChild) {
      // noob
    },
 
    commitUpdate(instance, updatePayload, type, oldProps, newProps) {
      // noop
    },
 
    commitMount(instance, updatePayload, type, oldProps, newProps) {
      // noop
    },
 
    commitTextUpdate(textInstance, oldText, newText) {
      console.log('commitTextUpdate', textInstance, oldText, newText);
      textInstance.children = newText;
    },
  }
})