/* @flow */

import matchRoutePattern from 'match-route-pattern'

import type {
  Screen,
  Transition,
  TransitionHandler,
  Location,
  QueryParameters
} from '../types'

export default function createTransition(pattern: string, handler: TransitionHandler): Transition {
  return function transition(location: Location): Promise<?Screen> {
    var queryParameters: ?QueryParameters = matchRoutePattern(pattern, location.pathname + location.search)

    if (!queryParameters) {
      return Promise.resolve(undefined)
    }

    return handler(queryParameters)
      .then(screen => screen) // Flow fix
  }
}

@@ -531,16 +531,32 @@
  return 
+Promise.resolve(
 handler(
@@ -571,16 +571,17 @@
 ameters)
+)
 %0A      .

Allow to return raw data from transition handler