-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9908 from marmelab/upgrade-fakerest
Upgrade FakeRest to 4.0
- Loading branch information
Showing
16 changed files
with
166 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,3 @@ | ||
import simpleRestProvider from 'ra-data-simple-rest'; | ||
|
||
const restProvider = simpleRestProvider('http://localhost:4000'); | ||
|
||
const delayedDataProvider = new Proxy(restProvider, { | ||
get: (target, name, self) => { | ||
// as we await for the dataProvider, JS calls then on it. We must trap that call or else the dataProvider will be called with the then method | ||
if (name === 'then') { | ||
return self; | ||
} | ||
return (resource: string, params: any) => | ||
new Promise(resolve => | ||
setTimeout( | ||
() => | ||
resolve(restProvider[name as string](resource, params)), | ||
500 | ||
) | ||
); | ||
}, | ||
}); | ||
|
||
export default delayedDataProvider; | ||
export default simpleRestProvider('http://localhost:4000'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import FakeRest from 'fakerest'; | ||
import { FetchMockAdapter, withDelay } from 'fakerest'; | ||
import fetchMock from 'fetch-mock'; | ||
import generateData from 'data-generator-retail'; | ||
|
||
export default () => { | ||
const data = generateData(); | ||
const restServer = new FakeRest.FetchServer('http://localhost:4000'); | ||
const adapter = new FetchMockAdapter({ | ||
baseUrl: 'http://localhost:4000', | ||
data, | ||
loggingEnabled: true, | ||
middlewares: [withDelay(500)], | ||
}); | ||
if (window) { | ||
window.restServer = restServer; // give way to update data in the console | ||
window.restServer = adapter.server; // give way to update data in the console | ||
} | ||
restServer.init(data); | ||
restServer.toggleLogging(); // logging is off by default, enable it | ||
fetchMock.mock('begin:http://localhost:4000', restServer.getHandler()); | ||
fetchMock.mock('begin:http://localhost:4000', adapter.getHandler()); | ||
return () => fetchMock.restore(); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.