prepack/test/react
Dominic Gannaway b0fe89e863 Add shape model functionality to React components (#2320)
Summary:
Release notes: React components can have their props modelled via `__optimizeReactComponentTree`

This extends the current shape modelling functionality added for InstantRender (great work by hotsnr ) and provides the same powers to the React compiler. An example of usage:

```js
var React = require("React");

function App(props) {
  return <div>
    <h1>{props.header.toString()}</h1>
    <ul>
      {
        props.items && props.items.map(item =>
          <li key={item.id}>{item.title.toString()}</li>
        )
      }
    </ul>
  </div>;
}

App.getTrials = function(renderer, Root) {
  var items = [{ id: 0, title: "Item 1" }, { id: 1, title: "Item 2" }, { id: 2, title: "Item 3" }];
  renderer.update(<Root items={items} header={"Hello world!"} />);
  return [["render simple with props model", renderer.toJSON()]];
};

if (this.__optimizeReactComponentTree) {

  let universe = {
    Item: {
      kind: "object",
      jsType: "object",
      properties: {
        id: {
          shape: {
            kind: "scalar",
            jsType: "integral",
          },
          optional: false,
        },
        title: {
          shape: {
            kind: "scalar",
            jsType: "string",
          },
          optional: false,
        },
      },
    },
    Props: {
      kind: "object",
      jsType: "object",
      properties: {
        header: {
          shape: {
            kind: "scalar",
            jsType: "string",
          },
          optional: false,
        },
        items: {
          shape: {
            kind: "array",
            jsType: "array",
            elementShape: {
              shape: {
                kind: "link",
                shapeName: "Item",
              },
              optional: false,
            },
          },
          optional: true,
        },
      },
    },
  };

  let appModel = {
    component: {
      props: "Props",
    },
    universe,
  };

  __optimizeReactComponentTree(App, {
    model: JSON.stringify(appModel),
  });
}

module.exports = App;
```
Pull Request resolved: https://github.com/facebook/prepack/pull/2320

Differential Revision: D8996429

Pulled By: trueadm

fbshipit-source-id: 31eb4b42fcfab4aec785492ed0baecfb5533a0e2
2018-07-25 11:27:47 -07:00
..
__snapshots__ Add shape model functionality to React components (#2320) 2018-07-25 11:27:47 -07:00
AssignSpread Make React tests fast (#2187) 2018-07-02 11:25:58 -07:00
ClassComponents Fix React branch serialization issues (#2318) 2018-07-25 09:55:21 -07:00
FactoryComponents Make React tests fast (#2187) 2018-07-02 11:25:58 -07:00
FBMocks Upgrade Prepack to Babel 7 (#2256) 2018-07-14 09:55:18 -07:00
FirstRenderOnly Reduce React bloat on equivalent objects with similar temporal alias trees (#2193) 2018-07-05 05:09:30 -07:00
FunctionalComponents Add shape model functionality to React components (#2320) 2018-07-25 11:27:47 -07:00
ReactDOM Make React tests fast (#2187) 2018-07-02 11:25:58 -07:00
ReactNative Run Prettier checks on CI (#2212) 2018-07-10 09:55:23 -07:00
Reconciliation Run Prettier checks on CI (#2212) 2018-07-10 09:55:23 -07:00
RenderProps Make React tests fast (#2187) 2018-07-02 11:25:58 -07:00
ServerRendering Make React tests fast (#2187) 2018-07-02 11:25:58 -07:00
AssignSpread-test.js Make React tests fast (#2187) 2018-07-02 11:25:58 -07:00
ClassComponents-test.js Fix React branch serialization issues (#2318) 2018-07-25 09:55:21 -07:00
FactoryComponents-test.js Make React tests fast (#2187) 2018-07-02 11:25:58 -07:00
FBMocks-test.js Improve fb-www mocks objectWithoutProperties value by ensuring we store known values (#2194) 2018-07-02 13:11:28 -07:00
FirstRenderOnly-test.js Reduce React bloat on equivalent objects with similar temporal alias trees (#2193) 2018-07-05 05:09:30 -07:00
FunctionalComponents-test.js Add shape model functionality to React components (#2320) 2018-07-25 11:27:47 -07:00
ReactDOM-test.js Make React tests fast (#2187) 2018-07-02 11:25:58 -07:00
ReactNative-test.js Run Prettier checks on CI (#2212) 2018-07-10 09:55:23 -07:00
Reconciliation-test.js Support React keys in array branches, fixes #2139 (#2157) 2018-07-04 08:23:26 -07:00
RenderProps-test.js Make React tests fast (#2187) 2018-07-02 11:25:58 -07:00
ServerRendering-test.js Make React tests fast (#2187) 2018-07-02 11:25:58 -07:00
setupReactTests.js Upgrade Prepack to Babel 7 (#2256) 2018-07-14 09:55:18 -07:00