-
Notifications
You must be signed in to change notification settings - Fork 1
/
react2.js
50 lines (47 loc) · 1.95 KB
/
react2.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
48
49
50
// React Movies sample app implementation (using styles)
// https://facebook.github.io/react-native/docs/tutorial.html
//
var request = require('request');
var REQUEST_URL = 'https://raw.githubusercontent.com/facebook/react-native/master/docs/MoviesExample.json';
exports.View =
{
title: "Movies",
elements:
[
{ control: "stackpanel", style: "container", contents: [
{ control: "text", style: "loading", visibility: "{!responseData.movies}" },
{ control: "listview", style: "listView", binding: "responseData.movies", itemTemplate: [
{ control: "stackpanel", style: "listItem", contents: [
{ control: "image", style: "thumbnail", resource: "{posters.thumbnail}" },
{ control: "stackpanel", style: "rightContainer", contents: [
{ control: "text", style: "title", value: "{title}" },
{ control: "text", style: "year", value: "{year}" },
]}
]}
]}
]}
]
}
exports.InitializeViewModel = function(context, session)
{
var viewModel =
{
/* Styles */
container: { orientation: "Vertical", width: "*", height: "*" },
loading: { value: "Loading movies...", fontsize: 10 },
listView: { select: "None", height: "*", width: "*", margin: 0 },
listItem: { orientation: "Horizontal", width: "*", margin: 0 },
thumbnail: { height: 100, width: 75 },
rightContainer: { orientation: "Vertical", width: "*" },
title: { font: { bold: true, size: 8 }, width: "*" },
year: { fontsize: 7, width: "*" },
/* Data */
responseData: null,
}
return viewModel;
}
exports.LoadViewModel = function * (context, session, viewModel)
{
var response = yield Synchro.yieldAwaitable(context, function(callback){ request({ url: REQUEST_URL }, callback) });
viewModel.responseData = JSON.parse(response[0].body);
}