Last active
October 12, 2017 23:04
-
-
Save JasonOffutt/0a2349beb15902be0a3af1ed0221f128 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// components/search/factory.js | |
// Grab singleton instance of DI container | |
import { container } from './depdendencies'; | |
import actionFactory from '../../actions'; | |
export const createActions = () => { | |
const http = container.instance('HTTP'); | |
return actionFactory(http); | |
}; |
This file contains hidden or 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
// actions/index.js | |
import search from './search'; | |
export default (http) => ({ | |
search: search(http) | |
}); |
This file contains hidden or 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
// actions/search.js | |
const requestResults = () => ({ type: 'SEARCH_REQUEST' }); | |
const receiveResults = (response) => ({ type: 'SEARCH_RESPONSE', response }); | |
const requestError = (response) => ({ type: 'SEARCH_ERROR', response }); | |
const createQuery (http) => { | |
return (dispatch) => { | |
return (query) => { | |
const url = `/api/search?q=${query}`; | |
dispatch(requestResults()); | |
return http(url).get() | |
.then((response) => dispatch(receiveResults(response)) | |
.catch((response) => dispatch(requestError(response)); | |
}; | |
}; | |
}; | |
export default (http) => ({ | |
query: createQuery(http) | |
}); |
This file contains hidden or 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
// test/spec/actions/search.js | |
import actionFactory from '../../src/actions'; | |
import httpStub from '../stubs/http'; | |
const actions = actionFactory(httpStub); | |
describe('Search action tests', () => { | |
describe('query', () => { | |
it('should do something useful', () => { | |
// test things, etc... | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment