-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcreateElementWithContext.js
33 lines (31 loc) · 1.12 KB
/
createElementWithContext.js
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
/**
* Copyright 2015, Yahoo Inc.
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
'use strict';
var React = require('react');
var FluxibleComponent = require('./FluxibleComponent');
var objectAssign = require('object-assign');
/**
* Creates an instance of the app level component with given props and a proper component
* context.
* @param {FluxibleContext} fluxibleContext
* @param {Object} props
* @return {ReactElement}
*/
module.exports = function createElement(fluxibleContext, props) {
var Component = fluxibleContext.getComponent();
if (!Component) {
throw new Error('A top-level component was not passed to the Fluxible' +
' constructor.');
}
if ('ContextProvider' === Component.displayName) {
return React.createElement(Component, objectAssign({}, {
context: fluxibleContext.getComponentContext()
}, props));
}
var componentInstance = React.createElement(Component, props);
return React.createElement(FluxibleComponent, {
context: fluxibleContext.getComponentContext()
}, componentInstance);
};