From 692b49b0701c5eff37050f2eb6394f8760bf3ba5 Mon Sep 17 00:00:00 2001 From: Riku Ayanokozy Date: Thu, 3 Aug 2017 02:10:15 +0800 Subject: [PATCH] Add react-dom/node-stream (#18493) --- types/react-dom/node-stream/index.d.ts | 20 ++++++++++++++++++++ types/react-dom/react-dom-tests.ts | 12 ++++++++++++ types/react-dom/tsconfig.json | 3 ++- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 types/react-dom/node-stream/index.d.ts diff --git a/types/react-dom/node-stream/index.d.ts b/types/react-dom/node-stream/index.d.ts new file mode 100644 index 0000000000..449d45b46d --- /dev/null +++ b/types/react-dom/node-stream/index.d.ts @@ -0,0 +1,20 @@ +/// +import { ReactElement } from 'react'; +import * as stream from 'stream'; + +/** + * Render a ReactElement to its initial HTML. This should only be used on the + * server. + * See https://facebook.github.io/react/docs/react-dom-stream.html#rendertostream + */ +export function renderToStream(element: ReactElement): stream.Readable; + +/** + * Similar to renderToStream, except this doesn't create extra DOM attributes + * such as data-react-id that React uses internally. + * See https://facebook.github.io/react/docs/react-dom-stream.html#rendertostaticstream + */ +export function renderToStaticStream(element: ReactElement): stream.Readable; +export const version: string; + +export as namespace ReactDOMNodeStream; diff --git a/types/react-dom/react-dom-tests.ts b/types/react-dom/react-dom-tests.ts index 534b847787..9a60724dae 100644 --- a/types/react-dom/react-dom-tests.ts +++ b/types/react-dom/react-dom-tests.ts @@ -1,7 +1,9 @@ import * as React from 'react'; import * as ReactDOM from 'react-dom'; import * as ReactDOMServer from 'react-dom/server'; +import * as ReactDOMNodeStream from 'react-dom/node-stream'; import * as ReactTestUtils from 'react-dom/test-utils'; +import * as stream from 'stream'; declare function describe(desc: string, f: () => void): void; declare function it(desc: string, f: () => void): void; @@ -37,6 +39,16 @@ describe('ReactDOMServer', () => { }); }); +describe('ReactDOMNodeStream', () => { + it('renderToStream', () => { + const content: stream.Readable = ReactDOMNodeStream.renderToStream(React.createElement('div')); + }); + + it('renderToStaticStream', () => { + const content: stream.Readable = ReactDOMNodeStream.renderToStaticStream(React.createElement('div')); + }); +}); + describe('React dom test utils', () => { it('Simulate', () => { const element = document.createElement('div'); diff --git a/types/react-dom/tsconfig.json b/types/react-dom/tsconfig.json index c93c6f8195..8c270fabed 100644 --- a/types/react-dom/tsconfig.json +++ b/types/react-dom/tsconfig.json @@ -3,6 +3,7 @@ "index.d.ts", "react-dom-tests.ts", "server/index.d.ts", + "node-stream/index.d.ts", "test-utils/index.d.ts" ], "compilerOptions": { @@ -22,4 +23,4 @@ "noEmit": true, "forceConsistentCasingInFileNames": true } -} \ No newline at end of file +}