All files / src navigator.js

31.82% Statements 7/22
0% Branches 0/2
0% Functions 0/3
41.18% Lines 7/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52  1x 1x 1x 1x     1x   1x                                                                 1x                  
 
import { getHistory, createListener } from './history'
import { DEFAULT_KEY, createUpdate } from './update'
import { actions } from './actions'
import { RouteMatcher } from './routeMatcher'
 
// const {Component} = require(`${process.env.BABEL_ENV}/component.js`)
import { useEffect } from './env/react/hooks'
 
export const Navigator = props => {
  const Route = RouteMatcher(props)
  const { Component, ComponentProps, signal, history, root, storage } = props
 
  useEffect(() => {
    const disposeHistory = getHistory(history)
      .listen(createListener(signal))
 
    const disposeUpdate = signal
      .register(createUpdate({
        key: root,
        history,
        signal,
        storage
      }))
 
    signal.emit({
      type: actions.init
    })
 
    return () => {
      disposeHistory()
      disposeUpdate()
    }
  }, [
    props.history,
    props.storage
  ])
 
  return Component
    ? <Component {...ComponentProps}>{Route}</Component>
    : Route
}
Navigator.defaultProps = {
  signal: null,
  history: null,
  root: DEFAULT_KEY,
  navigation: null,
  Component: null,
  ComponentProps: {},
  mapChildren: null
}