Guest User

Untitled

a guest
Jan 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import * as actions from './../state/priorities/actions';
  4. import { TimelineLite } from 'gsap';
  5.  
  6. class GsapComponent extends React.Component {
  7.  
  8. constructor(props) {
  9. super(props);
  10.  
  11. this.state = {
  12. style: {}
  13. }
  14.  
  15. this.tl = new TimelineLite();
  16. }
  17.  
  18. componentDidMount() {
  19. if (this.props.component === undefined) {
  20. // after the component mounts it should be added to the redux store
  21. this.props.addGsap(this.props.id);
  22. }
  23. }
  24.  
  25. componentWillReceiveProps(nextProps) {
  26. // never called
  27. console.log(nextProps);
  28. }
  29.  
  30. componentDidUpdate(prevProps, prevState) {
  31. // never called
  32. console.log('did update');
  33. console.log(this.props);
  34. }
  35.  
  36. to = (options) => {
  37. // not relevant
  38. }
  39.  
  40. render() {
  41. return (
  42. <div ref={ref => this.ref = ref} style={this.props.component !== undefined ? this.props.component.style : {}}>
  43. <div>
  44. {this.props.children}
  45. </div>
  46. <div>{JSON.stringify(this.props.component)}</div>
  47. </div>
  48. );
  49. }
  50.  
  51. }
  52.  
  53. const mapStateToProps = (state, ownProps) => {
  54. return {
  55. component: state.priorities.gsap[ownProps.id]
  56. };
  57. }
  58.  
  59. const mapDispatchToProps = (dispatch) => {
  60. return {
  61. addGsap: (key) => dispatch(actions.addGsap(key)),
  62. updateGsap: (key, styles, next = {}) => dispatch(actions.updateGsap(key, styles, next))
  63. };
  64. }
  65.  
  66. GsapComponent = connect(mapStateToProps, mapDispatchToProps)(GsapComponent);
  67.  
  68. export { GsapComponent };
Add Comment
Please, Sign In to add comment