This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement redux-connect for server-side rendering
- Loading branch information
1 parent
56f4f3b
commit df35416
Showing
14 changed files
with
143 additions
and
43 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
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { asyncConnect } from 'redux-connect'; | ||
|
||
const defaultPromise = Promise.resolve(); | ||
|
||
const async = ( | ||
resolve = defaultPromise | ||
) => ( | ||
asyncConnect([{ | ||
promise: (options) => { | ||
const payload = { | ||
...options, | ||
getState: options.store.getState, | ||
dispatch: options.store.dispatch | ||
}; | ||
|
||
return resolve(payload); | ||
} | ||
}]) | ||
); | ||
|
||
export default async; |
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,3 +1,5 @@ | ||
import 'isomorphic-fetch'; | ||
|
||
const baseUri = CONFIG.BACKEND.URI; | ||
|
||
const featureService = { | ||
|
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,3 +1,5 @@ | ||
import 'isomorphic-fetch'; | ||
|
||
const baseUri = CONFIG.BACKEND.URI; | ||
|
||
const productService = { | ||
|
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import sinon from 'sinon'; | ||
import { featureService } from 'services'; | ||
|
||
describe('featureService', () => { | ||
let response; | ||
let expectedResult; | ||
let mockResponseJson; | ||
let mockFetch; | ||
let result; | ||
|
||
beforeEach(() => { | ||
response = { json: () => {} }; | ||
expectedResult = { status: 200, data: 'result' }; | ||
|
||
mockResponseJson = sinon.stub(response, 'json').returns(Promise.resolve(expectedResult)); | ||
mockFetch = sinon.stub(window, 'fetch').returns(Promise.resolve(response)); | ||
}); | ||
|
||
afterEach(() => { | ||
window.fetch.restore(); | ||
}); | ||
|
||
describe('getFeatures', () => { | ||
beforeEach(async () => { | ||
result = await featureService.getFeatures(); | ||
}); | ||
|
||
it('should call fetch to retrieve the features', () => mockFetch.should.have.been.called); | ||
it('should convert the result to JSON', () => mockResponseJson.should.have.been.called); | ||
it('should retrieve the result', () => result.should.be.equal(expectedResult)); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import sinon from 'sinon'; | ||
import { productService } from 'services'; | ||
|
||
describe('productService', () => { | ||
let response; | ||
let expectedResult; | ||
let mockResponseJson; | ||
let mockFetch; | ||
let result; | ||
|
||
beforeEach(() => { | ||
response = { json: () => {} }; | ||
expectedResult = { status: 200, data: 'result' }; | ||
|
||
mockResponseJson = sinon.stub(response, 'json').returns(Promise.resolve(expectedResult)); | ||
mockFetch = sinon.stub(window, 'fetch').returns(Promise.resolve(response)); | ||
}); | ||
|
||
afterEach(() => { | ||
window.fetch.restore(); | ||
}); | ||
|
||
describe('getProducts', () => { | ||
beforeEach(async () => { | ||
result = await productService.getProducts(); | ||
}); | ||
|
||
it('should call fetch to retrieve the items', () => mockFetch.should.have.been.called); | ||
it('should convert the result to JSON', () => mockResponseJson.should.have.been.called); | ||
it('should retrieve the result', () => result.should.be.equal(expectedResult)); | ||
}); | ||
}); |
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