-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathlib.jsx
33 lines (31 loc) · 902 Bytes
/
lib.jsx
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
import React from 'react';
import ReactDOM from 'react-dom';
BlazeToReact = React.createClass({
mixins: [ReactMeteorData],
renderBlaze() {
this.removeBlaze();
this.view = Blaze.renderWithData(Template[this.props.blazeTemplate], _.omit(this.props, 'blazeTemplate'), ReactDOM.findDOMNode(this.refs[this.props.blazeTemplate]));
},
removeBlaze() {
if (this.view) Blaze.remove(this.view);
},
getMeteorData() {
// Ensure a re-rendering of the template if a prop changes
this.renderBlaze();
return this.props;
},
componentDidUpdate() {
// Needed when used with a conditional show, like {condition ? <BlazeToCreact ../> : null}
this.renderBlaze();
},
componentDidMount() {
this.renderBlaze();
},
componentWillUnmount() {
this.removeBlaze();
},
render() {
return <div ref={this.props.blazeTemplate}/>
}
});
export default BlazeToReact;