-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.js
65 lines (58 loc) · 2.02 KB
/
index.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
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
'use strict'
// @create-index
// imagine one day a program that automatically generates this
// until that day, this is manual
//
// TypeComponent will accept a function (.default) or a module (exports), so you don't need to add .default to new entries.
// Also, TypeComponent.attributes() will return module.attributes if it is defined.
const WebComponents = {
TestJoin: require('./test-join'),
Undebate: require('./undebate'),
CandidateConversation: require('./candidate-conversation'),
UndebateLine: require('./undebate-line'),
UndebateIframes: require('./undebate-iframes'),
Unpoll: require('./unpoll'),
HartfordVotes: require('./HartfordVotes'),
FAQ: require('./FAQ'),
About: require('./About'),
HartfordViewers: require('./HartfordViewers'),
CcWrapper: require('./cc-wrapper'),
}
import React from 'react'
class WebComponent extends React.Component {
static attributes(webComponent) {
let WebComponent
if (typeof webComponent === 'object') {
WebComponent = WebComponents[webComponent.webComponent]
if (typeof WebComponent === 'object') return WebComponent.attributes
else return {}
} else {
WebComponent = WebComponents[webComponent]
if (typeof WebComponent === 'object') return WebComponent.attributes
else return {}
}
}
render() {
const objOrStr = this.props.webComponent
var WebComponentClass
var newProps = {}
if (typeof objOrStr === 'object') {
Object.assign(newProps, this.props, objOrStr)
WebComponentClass = WebComponents[objOrStr.webComponent]
} else {
// string
Object.assign(newProps, this.props)
WebComponentClass = WebComponents[objOrStr]
}
if (typeof WebComponentClass === 'undefined') {
logger.error('WebComponent not defined:', objOrStr)
return null
}
if (WebComponentClass.default)
// commonJS module or require
WebComponentClass = WebComponentClass.default
delete newProps.webComponent
return <WebComponentClass {...newProps} />
}
}
export default WebComponent