Advertisement
Guest User

Untitled

a guest
Nov 6th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var React = require('react');
  2. var SubnavItemModule = require('../modules/subnav-filter-item-module');
  3. var SubnavStore = require('../../stores/subnav-store');
  4. var Link = require('react-router-component').Link;
  5.  
  6. function getSubnavItems() {
  7.  
  8.   return {subnavItems: SubnavStore.getSubnavItems()}
  9. }
  10.  
  11. var SubnavArea = React.createClass({
  12.  
  13.   getInitialState:function() {
  14.  
  15.     return getSubnavItems();
  16.   },
  17.  
  18.   componentWillMount:function(){
  19.  
  20.     console.log('%c subnav-area.js ::: ADDING Listener: SubnavStore.addSubnavListener(this._onChange)', 'background: #222; color: salmon;');
  21.     SubnavStore.addChangeListener(this._onChange, 'subnav-area.js');
  22.   },
  23.  
  24.   componentWillUnmount:function() {
  25.  
  26.     SubnavStore.removeChangeListener(this._onChange)
  27.   },
  28.  
  29.   _onChange: function(){
  30.  
  31.     console.log('%c subnav-area.js ::: _onChange() called!', 'background: #222; color: salmon', 'Next func --> this.setState(getSubnavItems())');
  32.     this.setState(getSubnavItems())
  33.   },
  34.  
  35.   render:function() {
  36.  
  37.     if (this.state.subnavItems[0].type != undefined) {
  38.  
  39.       var subnavType = this.state.subnavItems[0].type;
  40.       var subnavItems = this.state.subnavItems[0].links.map(function(subnavItem){
  41.  
  42.         return (
  43.  
  44.           <SubnavItemModule key={subnavItem._id} _id={subnavItem._id} _text={subnavItem._text} active={subnavItem.active} />
  45.         );
  46.       })
  47.     }
  48.  
  49.     return (
  50.  
  51.       <div className="subnav">
  52.         <div className="container">
  53.         <p className="legend">{this.state.subnavItems[0].legend}</p>
  54.         {subnavItems}
  55.         </div>
  56.       </div>
  57.     )
  58.   }
  59. });
  60.  
  61. module.exports = SubnavArea;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement