1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import ReactInstanceHandles from 'react/lib/ReactInstanceHandles';
|
8 | import ReactElement from 'react/lib/ReactElement';
|
9 | import ReactUpdates from 'react/lib/ReactUpdates';
|
10 | import ReactBlessedIDOperations from './ReactBlessedIDOperations';
|
11 | import invariant from 'invariant';
|
12 | import instantiateReactComponent from 'react/lib/instantiateReactComponent';
|
13 | import inject from './ReactBlessedInjection';
|
14 | import {Screen} from 'blessed';
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | inject();
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | function render(element, screen) {
|
29 |
|
30 |
|
31 | invariant(
|
32 | ReactElement.isValidElement(element),
|
33 | 'render(): You must pass a valid ReactElement.'
|
34 | );
|
35 |
|
36 |
|
37 | invariant(
|
38 | screen instanceof Screen,
|
39 | 'render(): You must pass a valid BlessedScreen.'
|
40 | );
|
41 |
|
42 |
|
43 | const id = ReactInstanceHandles.createReactRootID();
|
44 |
|
45 |
|
46 | const component = instantiateReactComponent(element);
|
47 |
|
48 |
|
49 | ReactBlessedIDOperations.setScreen(screen);
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | ReactUpdates.batchedUpdates(() => {
|
55 |
|
56 | const transaction = ReactUpdates.ReactReconcileTransaction.getPooled();
|
57 | transaction.perform(() => {
|
58 | component.mountComponent(id, transaction, {});
|
59 | });
|
60 | ReactUpdates.ReactReconcileTransaction.release(transaction);
|
61 | });
|
62 |
|
63 |
|
64 | return component._instance;
|
65 | }
|
66 |
|
67 | export {render};
|