Skip to content

Commit ad55e9c

Browse files
Use external domain-tasks NPM module
1 parent e419ec4 commit ad55e9c

File tree

9 files changed

+15
-79
lines changed

9 files changed

+15
-79
lines changed

samples/react/MusicStore/ReactApp/fx/domain-tasks.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.

samples/react/MusicStore/ReactApp/fx/isomorphic-fetch.d.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

samples/react/MusicStore/ReactApp/fx/render-server.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
require('./require-ts-babel')(); // Enable loading TS/TSX/JSX/ES2015 modules
22
var url = require('url');
3-
var domainTasks = require('./domain-tasks.ts');
3+
var domainTasks = require('domain-tasks');
4+
var baseUrl = require('domain-tasks/fetch').baseUrl;
45

5-
function render(bootModulePath, requestUrl, callback) {
6+
function render(bootModulePath, absoluteRequestUrl, requestPathAndQuery, callback) {
67
var bootFunc = require(bootModulePath);
78
if (typeof bootFunc !== 'function') {
89
bootFunc = bootFunc.default;
@@ -12,13 +13,15 @@ function render(bootModulePath, requestUrl, callback) {
1213
}
1314

1415
var params = {
15-
location: url.parse(requestUrl),
16-
url: requestUrl,
16+
location: url.parse(requestPathAndQuery),
17+
url: requestPathAndQuery,
1718
state: undefined
1819
};
1920

2021
// Open a new domain that can track all the async tasks commenced during first render
2122
domainTasks.run(function() {
23+
baseUrl(absoluteRequestUrl);
24+
2225
// Since route matching is asynchronous, add the rendering itself to the list of tasks we're awaiting
2326
domainTasks.addTask(new Promise(function (resolve, reject) {
2427
// Now actually perform the first render that will match a route and commence associated tasks
@@ -33,19 +36,16 @@ function render(bootModulePath, requestUrl, callback) {
3336
}
3437
});
3538
}));
36-
}).then(function() {
39+
}, function(error) {
3740
// By now, all the data should be loaded, so we can render for real based on the state now
3841
// TODO: Add an optimisation where, if domain-tasks had no outstanding tasks at the end of
3942
// the previous render, we don't re-render (we can use the previous html and state).
43+
if (error) { console.error(error); throw error; }
4044
bootFunc(params, callback);
41-
}).catch(function(error) {
42-
process.nextTick(() => { // Because otherwise you can't throw from inside a catch
43-
callback(error, null);
44-
});
4545
});
4646
}
4747

48-
render('../boot-server.tsx', '/', (err, html) => {
48+
render('../boot-server.tsx', 'http://localhost:5000', '/', (err, html) => {
4949
if (err) {
5050
throw err;
5151
}

samples/react/MusicStore/ReactApp/fx/tracked-fetch.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

samples/react/MusicStore/ReactApp/store/AlbumDetails.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fetch } from '../fx/tracked-fetch';
1+
import { fetch } from 'domain-tasks/fetch';
22
import { typeName, isActionType, Action, Reducer } from '../fx/TypedRedux';
33
import { ActionCreator } from './';
44
import { Genre } from './GenreList';

samples/react/MusicStore/ReactApp/store/FeaturedAlbums.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fetch } from '../fx/tracked-fetch';
1+
import { fetch } from 'domain-tasks/fetch';
22
import { typeName, isActionType, Action, Reducer } from '../fx/TypedRedux';
33
import { ActionCreator } from './';
44

samples/react/MusicStore/ReactApp/store/GenreDetails.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fetch } from '../fx/tracked-fetch';
1+
import { fetch } from 'domain-tasks/fetch';
22
import { typeName, isActionType, Action, Reducer } from '../fx/TypedRedux';
33
import { ActionCreator } from './';
44
import { Album } from './FeaturedAlbums';

samples/react/MusicStore/ReactApp/store/GenreList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fetch } from '../fx/tracked-fetch';
1+
import { fetch } from 'domain-tasks/fetch';
22
import { typeName, isActionType, Action, Reducer } from '../fx/TypedRedux';
33
import { ActionCreator } from './';
44

samples/react/MusicStore/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"dependencies": {
2222
"bootstrap": "^3.3.6",
2323
"domain-context": "^0.5.1",
24+
"domain-tasks": "^1.0.0",
2425
"isomorphic-fetch": "^2.2.1",
2526
"ntypescript": "^1.201602072208.1",
2627
"react": "^0.14.7",

0 commit comments

Comments
 (0)