import React, { Component } from 'react'

import assert from './util/assert'
import createDispatcher from './createDispatcher'

function isDispatcher(obj) {
  return (
    typeof obj === 'object' &&
    typeof obj.subscribe === 'function' &&
    typeof obj.reduce === 'function' &&
    typeof obj.schedule === 'function'
  )
}

export default class Provider extends Component {
  static propTypes = {
    dispatcher: React.PropTypes.object
  };

  static childContextTypes = {
    dispatcher: React.PropTypes.object
  };

  getChildContext() {
    if (this.props.dispatcher) {
      assert(isDispatcher(this.props.dispatcher), 'Expected a Dispatcher to be passed in the dispatcher prop.')
      return { dispatcher: this.props.dispatcher }
    }

    if (!this.dispatcher) {
      this.dispatcher = createDispatcher()
    }

    return { dispatcher: this.dispatcher }
  }

  render() {
    return this.props.children
  }
}

@@ -34,17 +34,16 @@
 'react'%0A
-%0A
 import a
@@ -80,250 +80,47 @@
 ort 
-createDispatcher from './createDispatcher'%0A%0Afunction isDispatcher(obj) %7B%0A  return (%0A    typeof obj === 'object' &&%0A    typeof obj.subscribe === 'function' &&%0A    typeof obj.reduce === 'function' &&%0A    typeof obj.schedule === 'function'%0A  )%0A%7D
+isObservable from './util/isObservable'
 %0A%0Aex
@@ -190,34 +190,34 @@
 pes = %7B%0A    
-dispatcher
+observable
 : React.Prop
@@ -220,32 +220,43 @@
 PropTypes.object
+.isRequired
 %0A  %7D;%0A%0A  static 
@@ -348,43 +348,8 @@
 ) %7B%0A
-    if (this.props.dispatcher) %7B%0A  
     
@@ -357,26 +357,26 @@
 ssert(is
-Dispatcher
+Observable
 (this.pr
@@ -383,85 +383,68 @@
 ops.
-dispatcher), 'Expected a Dispatcher to be passed in the dispatcher prop
+observable), 'Expect prop observable to be an observable
 .')%0A
-  
     
@@ -448,34 +448,34 @@
    return %7B 
-dispatcher
+observable
 : this.props
@@ -479,146 +479,18 @@
 ops.
-dispatcher %7D%0A    %7D%0A%0A    if (!this.dispatcher) %7B%0A      this.dispatcher = createDispatcher()%0A    %7D%0A%0A    return %7B dispatcher: this.dispatcher
+observable
  %7D%0A 

Make Provider take an observable prop