markdalgleish / redial

Universal data fetching and route lifecycle management for React etc.
1.1k stars 42 forks source link

Handle routes with undefined components #5

Closed cameronhunter closed 8 years ago

cameronhunter commented 8 years ago

Handle routes with undefined components such as:

<Route path="/">
  <IndexRoute component={App} />
</Route>
vyorkin commented 8 years ago

@cameronhunter does it work for you? because in my case it fails on .filter(({ fetcher }) => fetcher)

I don't know if there is a better way to do it, but here is what I did:

...
  const promises = (Array.isArray(components) ? components : [components])
    .filter(component => component)
    // Get component fetcher functions
    .map(component => ({ component, fetcher: component[name] }))
...

e.g.

> const array = [undefined, 1, 'foo', undefined, undefined, null, 2, 3, false, 0]
'use strict'
> array.filter(x => x)
[ 1, 'foo', 2, 3 ]
cameronhunter commented 8 years ago

Yep, I prefer your method – I've created a new pull request.