forked from jsdf/ReactNativeHackerNews
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoutes.js
47 lines (42 loc) · 1.09 KB
/
Routes.js
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
class Routes {
static register(name, handler) {
if (this.handlers == null) this.handlers = {}
this.handlers[name] = handler
}
static get(name, params) {
if (this.handlers[name] == null) throw new Error('unknown route')
return this.handlers[name](params)
}
static TopStories() {
return {
component: require('./components/TopStoriesScreen'),
title: 'Top Stories',
}
}
static Article(story) {
return {
component: require('./components/ArticleScreen'),
title: story.title,
passProps: {url: story.url}
}
}
static Link(url) {
return {
component: require('./components/ArticleScreen'),
title: url,
passProps: {url: url}
}
}
static Comments(story) {
if (story == null) throw new Error('missing argument: story')
var route = {
component: require('./components/CommentsScreen'),
title: 'Comments',
}
// TODO: get title from store?
if (story.title) route.title = `Comments – ${story.title}`
route.passProps = {storyId: story.id}
return route
}
}
module.exports = Routes