import methods from './methods'
import {Observable} from 'rxjs/Observable'
import {map} from 'rxjs/operator/map'
import {publishReplay} from 'rxjs/operator/publishReplay'
import pick from 'lodash/pick'
import nestedGet from './nestedGet'

const locationProperties = [
  'pathname',
  'search',
  'state',
  'action',
  'key'
]

export default function location(history) {
  if (!history || !history.listen || !history.push || !history.getCurrentLocation) {
    throw new Error('History 3 required e.g. https://github.com/ReactJSTraining/history')
  }

  const location$ = Observable.create(observer => {
    observer.next(history.getCurrentLocation())
    return history.listen(::observer.next)
  })
    ::publishReplay(1).refCount()

  return methods({
    // Allow nested gets.
    OBSERVE: ({path}) =>
      location$::map(l => nestedGet(l, path)),
    PUSH: ({params}) => {
      history.push(pick(params, locationProperties))
      return Promise.resolve()
    },
    REPLACE: ({params}) => {
      history.replace(pick(params, locationProperties))
      return Promise.resolve()
    }
  })
}

@@ -518,23 +518,16 @@
 com/
-ReactJSTraining
+mjackson
 /his
@@ -1067,24 +1067,106 @@
 e.resolve()%0A
+    %7D,%0A    GO_BACK: () =%3E %7B%0A      history.goBack()%0A      return Promise.resolve()%0A
     %7D%0A  %7D)%0A%7D

Add GO_BACK to location