Skip to content

Commit 68aa434

Browse files
committed
API call using 'superagent'
1 parent 65cf8bf commit 68aa434

File tree

8 files changed

+164
-21
lines changed

8 files changed

+164
-21
lines changed

src/web-module/Controllers/ValuesController.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
1+
using System.Collections.Generic;
52
using Microsoft.AspNet.Mvc;
63

74
namespace web_module.Controllers {

src/web-module/Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <binding AfterBuild='default' />
1+
/// <binding />
22
var path = require('path');
33

44
var vendorJs = ['jquery', 'bootstrap', 'react', 'react-dom', 'react-router', 'react-datepicker', 'flux', 'superagent', 'lodash', 'numeral', 'moment', 'moment/locale/it', 'moment/locale/fr', 'moment/locale/de', 'moment/locale/es', 'cookie', 'async'];

src/web-module/client/js/Content.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var React = require('react');
22
var Hello = require('./Hello');
3-
var Values = require('./Values');
3+
var Values = require('./Values/ValuesList');
44
module.exports = React.createClass({
55

66
render: function () {

src/web-module/client/js/Values.jsx

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var sa = require('superagent');
2+
var store = require('./ValuesStore');
3+
4+
module.exports = {
5+
loadValues: function() {
6+
sa.get('api/values').end(function(err, res) {
7+
store.setValues(res.body);
8+
});
9+
}
10+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var React = require('react');
2+
var store = require('./ValuesStore');
3+
var actions = require('./ValuesActions');
4+
5+
var Value = React.createClass({
6+
render: function () {
7+
return <li>{this.props.val}</li>
8+
}
9+
});
10+
11+
module.exports = React.createClass({
12+
getInitialState: function () {
13+
return {
14+
values: []
15+
};
16+
},
17+
componentDidMount: function () {
18+
this.unregister = store.watch(this.onStoreChange)
19+
actions.loadValues();
20+
},
21+
onStoreChange: function (values) {
22+
this.setState({
23+
values: values
24+
});
25+
},
26+
componentWillUnmount: function () {
27+
if (this.unregister) {
28+
this.unregister();
29+
}
30+
},
31+
render: function () {
32+
return <div className="values">
33+
<ol>
34+
{this.state.values.map(function (v) { return <Value val={v } />;})}
35+
</ol>
36+
</div>;
37+
}
38+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var _values = [];
2+
var _subscribers = [];
3+
4+
function setValues(values) {
5+
_values = values;
6+
_subscribers.forEach(function(sub) {
7+
sub(_values);
8+
});
9+
}
10+
11+
function getValues() {
12+
return _values;
13+
}
14+
15+
function watch(subscriber) {
16+
_subscribers.push(subscriber);
17+
return function() {
18+
_subscribers.splice(_subscribers.indexOf(subscriber), 1);
19+
}
20+
}
21+
22+
module.exports = {
23+
getValues: getValues,
24+
setValues: setValues,
25+
watch: watch
26+
};

src/web-module/wwwroot/js/app.js

Lines changed: 87 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)