Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c512aa0

Browse files
maisanogaearon
andauthored
[Blocks] Scaffolding react-fetch + first pass at node implementation (facebook#18863)
* First pass at scaffolding out the Node implementation of react-data. While incomplete, this patch contains some changes to the react-data package in order to start adding support for Node. The first part of this change accounts for splitting react-data/fetch into two discrete entries, adding (and defaulting to) the Node implementation. The second part is sketching out a rough approximation of `fetch` for Node. This implementation is not complete by any means, but provides a starting point. * Remove NodeFetch module and put it directly into ReactDataFetchNode. * Replaced react-data with react-fetch. This patch shuffles around some of the scaffolding that was in react-data in favor of react-fetch. It also removes the additional "fetch" package in favor of something flatter. * Tweak package organization * Simplify and add a test Co-authored-by: Dan Abramov <[email protected]>
1 parent e936034 commit c512aa0

24 files changed

+376
-70
lines changed

fixtures/blocks/src/server/Comments.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/* eslint-disable import/first */
88

99
import * as React from 'react';
10-
import {fetch} from 'react-data/fetch';
10+
import {fetch} from 'react-fetch';
1111

1212
// TODO: Replace with asset reference.
1313
import Link from '../client/Link';

fixtures/blocks/src/server/Feed.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/* eslint-disable import/first */
88

99
import * as React from 'react';
10-
import {fetch} from 'react-data/fetch';
10+
import {fetch} from 'react-fetch';
1111
import PostList from './PostList';
1212

1313
export default function Feed() {

fixtures/blocks/src/server/PostList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import * as React from 'react';
1010
import {Suspense, unstable_SuspenseList as SuspenseList} from 'react';
11-
import {preload} from 'react-data/fetch';
11+
import {preload} from 'react-fetch';
1212
import PostGlimmer from './PostGlimmer';
1313
import Post from './Post';
1414

fixtures/blocks/src/server/ProfileBio.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/* eslint-disable import/first */
88

99
import * as React from 'react';
10-
import {fetch} from 'react-data/fetch';
10+
import {fetch} from 'react-fetch';
1111

1212
export default function ProfileBio({userId}) {
1313
const user = fetch(`/users/${userId}`).json();

fixtures/blocks/src/server/ProfilePage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import * as React from 'react';
99
import {Suspense} from 'react';
10-
import {fetch} from 'react-data/fetch';
10+
import {fetch} from 'react-fetch';
1111
import {matchRoute} from './ServerRouter';
1212
import ProfileTimeline from './ProfileTimeline';
1313
import ProfileBio from './ProfileBio';

fixtures/blocks/src/server/ProfileTimeline.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/* eslint-disable import/first */
88

99
import * as React from 'react';
10-
import {fetch} from 'react-data/fetch';
10+
import {fetch} from 'react-fetch';
1111
import PostList from './PostList';
1212

1313
export default function ProfileTimeline({userId}) {

packages/react-data/npm/fetch.js

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

packages/react-data/npm/index.js

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

packages/react-data/src/__tests__/ReactDataFetch-test.js

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

packages/react-data/README.md renamed to packages/react-fetch/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# react-data
1+
# react-fetch
22

33
This package is meant to be used alongside yet-to-be-released, experimental React features. It's unlikely to be useful in any other context.
44

packages/react-data/fetch.js renamed to packages/react-fetch/index.browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99

1010
'use strict';
1111

12-
export * from './src/fetch/ReactDataFetch';
12+
export * from './src/ReactFetchBrowser';

packages/react-data/index.js renamed to packages/react-fetch/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99

1010
'use strict';
1111

12-
export * from './src/ReactData';
12+
export * from './index.node';

packages/react-data/src/ReactData.js renamed to packages/react-fetch/index.node.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
* @flow
88
*/
99

10-
export function createResource(): any {
11-
// TODO
12-
}
10+
'use strict';
11+
12+
export * from './src/ReactFetchNode';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
if (process.env.NODE_ENV === 'production') {
4+
module.exports = require('./cjs/react-fetch.browser.production.min.js');
5+
} else {
6+
module.exports = require('./cjs/react-fetch.browser.development.js');
7+
}

packages/react-fetch/npm/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = require('./index.node');
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
if (process.env.NODE_ENV === 'production') {
4+
module.exports = require('./cjs/react-fetch.node.production.min.js');
5+
} else {
6+
module.exports = require('./cjs/react-fetch.node.development.js');
7+
}
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
{
22
"private": true,
3-
"name": "react-data",
3+
"name": "react-fetch",
44
"description": "Helpers for creating React data sources",
55
"version": "0.0.0",
66
"repository": {
77
"type" : "git",
88
"url" : "https://github.com/facebook/react.git",
9-
"directory": "packages/react-data"
9+
"directory": "packages/react-fetch"
1010
},
1111
"files": [
1212
"LICENSE",
1313
"README.md",
1414
"build-info.json",
1515
"index.js",
16-
"fetch.js",
16+
"index.node.js",
17+
"index.browser.js",
1718
"cjs/"
1819
],
1920
"peerDependencies": {
2021
"react": "^16.13.1"
22+
},
23+
"browser": {
24+
"./index.js": "./index.browser.js"
2125
}
2226
}

0 commit comments

Comments
 (0)