SHARE
TWEET

Untitled

xapu Oct 28th, 2017 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Main Block
  2.  
  3. import React, { Component } from 'react'
  4. import logo from './logo.svg'
  5. import './App.css'
  6.  
  7. import Slider from './components/Slider'
  8. import Roster from './components/Roster'
  9. import Focused from './components/Focused'
  10.  
  11. import focusObserver from './utils/observer'
  12.  
  13. class App extends Component {
  14.   constructor(){
  15.     super()
  16.     this.state = {
  17.       focus:0
  18.     }    
  19.   }
  20.  
  21.  
  22.   componentDidMount(){
  23.     focusObserver.addObserver((param)=>{
  24.       this.setState(()=>({focus:param}))
  25.     })
  26.     console.log(this.state)
  27.     focusObserver.executeFuncs(5)
  28.     console.log(this.state)
  29.   }
  30.  
  31.  
  32.  
  33.   render () {
  34.     return (
  35.       <div className='container'>
  36.         <Slider />
  37.         <Roster />
  38.         <Focused />
  39.       </div>
  40.     )
  41.   }
  42. }
  43.  
  44. export default App
  45.  
  46.  
  47. //Observer Block
  48.  
  49. let changeFocus = []
  50.  
  51. let observer = {
  52.     addObserver:(someFunc)=>{
  53.         changeFocus.push(someFunc)
  54.     },
  55.     executeFuncs:(param)=>{
  56.         changeFocus.map(elem=>{
  57.  
  58.             elem(param)
  59.         })
  60.     }
  61. }
  62.  
  63. export default observer
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top