-
Notifications
You must be signed in to change notification settings - Fork 936
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds more guts to the react js demo. (#116)
- Loading branch information
Showing
10 changed files
with
133 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
export const Types = { | ||
Speed: 'logo.speed', | ||
Size: 'logo.size', | ||
Reset: 'logo.reset' | ||
} | ||
|
||
export const Actions = { | ||
changeSpeed: (speed) => ({ type: Types.Speed, speed }), | ||
changeSize: (size) => ({ type: Types.Size, size }), | ||
reset: () => ({ type: Types.Reset }) | ||
} | ||
|
||
export const INITIAL_STATE = { | ||
size: 100, | ||
speed: 5 | ||
} | ||
|
||
const changeSpeed = (state, { speed }) => ({ ...state, speed }) | ||
const changeSize = (state, { size }) => ({ ...state, size }) | ||
const reset = (state, { size }) => INITIAL_STATE | ||
|
||
// actions -> | ||
const reducerMap = { | ||
[Types.Speed]: changeSpeed, | ||
[Types.Size]: changeSize, | ||
[Types.Reset]: reset | ||
} | ||
|
||
// our reducer | ||
export const reducer = (state = INITIAL_STATE, action) => { | ||
const handler = reducerMap[action.type] | ||
return typeof handler === 'function' ? handler(state, action) : state | ||
} |
21 changes: 11 additions & 10 deletions
21
...o-react-js/src/Redux/RepoMessage.redux.js → ...ges/demo-react-js/src/Redux/Repo.redux.js
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,6 +1,8 @@ | ||
import { combineReducers } from 'redux' | ||
import { reducer as repoMessageReducer } from './RepoMessage.redux' | ||
import { reducer as repoReducer } from './Repo.redux' | ||
import { reducer as logoReducer } from './Logo.redux' | ||
|
||
export default combineReducers({ | ||
repoMessage: repoMessageReducer | ||
repo: repoReducer, | ||
logo: logoReducer | ||
}) |
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,22 @@ | ||
import RS from 'ramdasauce' | ||
import { call, put } from 'redux-saga/effects' | ||
import * as Repo from '../Redux/Repo.redux' | ||
|
||
export function * request (api, action) { | ||
// make the call to github | ||
const { repo } = action | ||
const { ok, data, status, problem } = yield call(api.get, `/repos/${repo}/commits`) | ||
// are we good? | ||
if (ok) { | ||
const entry = RS.dotPath('0', data) | ||
const { commit, author, html_url: url } = entry | ||
const { message, tree } = commit | ||
const { name, avatar_url } = author | ||
const { sha } = tree | ||
console.log({ avatar_url }) | ||
// record the last commit's message | ||
yield put(Repo.Actions.receive(message, url, name, sha, avatar_url)) | ||
} else { | ||
yield put(Repo.Actions.failure(`uh oh: ${problem} status: ${status}`)) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { put } from 'redux-saga/effects' | ||
import * as RepoMessage from '../Redux/RepoMessage.redux' | ||
// import { put } from 'redux-saga/effects' | ||
// import * as RepoMessage from '../Redux/RepoMessage.redux' | ||
|
||
// process STARTUP actions | ||
export function * startup () { | ||
yield put(RepoMessage.Actions.request()) | ||
// yield put(RepoMessage.Actions.request()) | ||
} |
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