forked from craftzdog/hyper-holoplay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (34 loc) · 1012 Bytes
/
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
exports.decorateTerm = (Term, { React, notify }) => {
const { init, update } = require('./renderer')
return class extends React.Component {
constructor(props, context) {
super(props, context)
this._div = null
this._holo = null
}
_onDecorated = term => {
if (this.props.onDecorated) this.props.onDecorated(term)
this._div = term ? term.termRef : null
this._initHolo()
}
_initHolo() {
this._holo = init(this._div)
window.requestAnimationFrame(this._drawFrame)
}
// Draw the next frame in the particle simulation.
_drawFrame = () => {
update(this._holo)
window.requestAnimationFrame(this._drawFrame)
}
render() {
// Return the default Term component with our custom onTerminal closure
// setting up and managing the particle effects.
return React.createElement(
Term,
Object.assign({}, this.props, {
onDecorated: this._onDecorated
})
)
}
}
}