This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
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 #152 from cglewis/dev
closes #134
- Loading branch information
Showing
5 changed files
with
77 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { createAction } from 'redux-actions'; | ||
import { ofType } from 'redux-observable'; | ||
import { of } from 'rxjs'; | ||
import { ajax as rxAjax } from 'rxjs/ajax'; | ||
import { catchError, debounceTime, mergeMap, map } from 'rxjs/operators'; | ||
|
||
import { setTools } from "domain/data"; | ||
|
||
// ACTIONS | ||
const fetchTools = createAction('FETCH_TOOLS'); | ||
|
||
// EPIC | ||
const fetchToolsEpic = (action$, store, ajax = rxAjax) => { | ||
return action$.pipe( | ||
ofType(fetchTools.toString()) | ||
,debounceTime(500) | ||
,mergeMap((action) => { | ||
const url = '/tools'; | ||
return ajax({ 'url': url, 'crossDomain': true, 'responseType': 'json' }).pipe( | ||
map((result) => { | ||
const resp = result.response; | ||
const tools = []; | ||
const keys = Object.keys(resp); | ||
for(const key of keys){ | ||
const items = resp[key]; | ||
for(const item of items){ | ||
tools.push(item); | ||
} | ||
} | ||
console.log("tools: "); | ||
console.log(tools); | ||
return tools; | ||
}) | ||
,map(setTools) | ||
); | ||
}) | ||
,catchError((error) => { | ||
console.log("error xhr: %o", error) | ||
const newErr = new Error("Error fetching Tools: " + error.message); | ||
}) | ||
); | ||
} | ||
|
||
export default fetchToolsEpic; | ||
export { fetchTools }; |
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