Skip to content

Commit

Permalink
Merge pull request #99 from plouc/feat-redux-migration
Browse files Browse the repository at this point in the history
Migrate to redux
  • Loading branch information
Raphaël Benitte authored Aug 23, 2016
2 parents 1e9446b + c47965f commit 721fa06
Show file tree
Hide file tree
Showing 102 changed files with 2,363 additions and 2,408 deletions.
7 changes: 5 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"react"
],
"rules": {
"semi": [1, "never"],
"semi": [2, "never"],
"prefer-template": 2,
"indent": [2, 4, {
"SwitchCase": 1
Expand All @@ -29,7 +29,10 @@
"beforeColon": false,
"afterColon": true
}],
"quotes": [2, "single"],
"quotes": [2, "single", {
"avoidEscape": true,
"allowTemplateLiterals": true
}],
"jsx-quotes": [2, "prefer-double"],
"array-bracket-spacing": [2, "never"],
"eol-last": 2,
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ logs
*.log
node_modules
.idea
lib
/lib
.nyc_output
coverage
npm-debug.log*

# Ignore non default themes
Expand Down
7 changes: 6 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
.travis.yml
CHANGELOG.md
CHANGELOG.md
.nyc_output
coverage
.DS_Store
test
npm-debug.log*
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
language: node_js
node_js:
- '0.12'
- '4'
- '5'
before_install:
- npm install -g npm
- '6'
script:
- npm run eslint
- npm test
- npm run test-cover
after_success:
- npm run coveralls
39 changes: 30 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"url": "https://github.com/plouc"
},
"engines": {
"node": "0.12.x",
"node": ">=6.0.0",
"npm": ">=3.0.0"
},
"license": "MIT",
Expand Down Expand Up @@ -46,9 +46,11 @@
"html-webpack-plugin": "2.22.0",
"lodash": "4.10.0",
"memory-cache": "0.1.5",
"node-uuid": "1.4.7",
"react-hot-loader": "1.3.0",
"react-mixin": "3.0.4",
"reflux": "0.4.1",
"react-redux": "4.4.5",
"redux": "3.5.2",
"redux-thunk": "2.1.0",
"request": "2.71.0",
"superagent": "1.8.3",
"superagent-bluebird-promise": "3.0.0",
Expand All @@ -59,19 +61,22 @@
"ws": "1.1.0"
},
"devDependencies": {
"ava": "0.16.0",
"babel-eslint": "6.0.2",
"babel-loader": "6.2.5",
"babel-preset-es2015": "6.6.0",
"babel-preset-es2015": "6.9.0",
"babel-preset-react": "6.5.0",
"babel-preset-stage-2": "6.13.0",
"babel-register": "6.7.2",
"coveralls": "2.11.12",
"css-loader": "0.23.1",
"enzyme": "2.4.1",
"eslint": "2.7.0",
"eslint": "3.3.1",
"eslint-plugin-react": "4.3.0",
"expect": "1.16.0",
"mocha": "2.4.5",
"mockery": "1.5.1",
"nyc": "8.1.0",
"react": "15.3.0",
"react-addons-test-utils": "15.3.0",
"react-dom": "15.3.0",
Expand All @@ -83,11 +88,27 @@
"stylus-loader": "2.3.1"
},
"peerDependencies": {
"react": "15.3.0",
"react-dom": "15.3.0"
"react": ">=15.0.0",
"react-dom": ">=15.0.0"
},
"scripts": {
"eslint": "eslint ./src/*",
"test": "mocha --compilers js:babel-register --recursive"
"eslint": "eslint ./src/** ./test/**",
"test": "ava --verbose",
"test-cover": "nyc ava --verbose",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"cover-report": "nyc report --reporter=lcov && open coverage/lcov-report/index.html"
},
"ava": {
"files": [
"test/**/*.test.js"
],
"tap": false,
"failFast": true,
"require": [
"babel-register"
],
"babel": "inherit"
},
"nyc": {
}
}
9 changes: 0 additions & 9 deletions src/ui/actions/ApiActions.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/ui/actions/ConfigActions.js

This file was deleted.

13 changes: 0 additions & 13 deletions src/ui/actions/ConnectionStatusActions.js

This file was deleted.

12 changes: 0 additions & 12 deletions src/ui/actions/DashboardActions.js

This file was deleted.

11 changes: 0 additions & 11 deletions src/ui/actions/NotificationsActions.js

This file was deleted.

18 changes: 18 additions & 0 deletions src/ui/actions/apiActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const API_SUBSCRIPTION = 'API_SUBSCRIPTION'
export const BUFFER_API_SUBSCRIPTION = 'BUFFER_API_SUBSCRIPTION'
export const API_DATA = 'API_DATA'

export const subscribeToApi = subscription => {
return (dispatch, getState) => {
const { ws } = getState()
const type = ws.connected ? API_SUBSCRIPTION : BUFFER_API_SUBSCRIPTION

dispatch({ type, subscription })
}
}

export const receiveApiData = ({ id, body }) => ({
type: API_DATA,
id,
data: body,
})
47 changes: 47 additions & 0 deletions src/ui/actions/configurationActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import request from 'superagent'
import { connect } from './wsActions'
import {
setDashboards,
startDashboardRotation,
} from './dashboardsActions'
import {
notifySuccess,
} from './notificationsActions'

export const FETCH_CONFIGURATION = 'FETCH_CONFIGURATION'
export const FETCH_CONFIGURATION_SUCCESS = 'FETCH_CONFIGURATION_SUCCESS'
export const FETCH_CONFIGURATION_FAILURE = 'FETCH_CONFIGURATION_FAILURE'

const fetchConfigurationSuccess = configuration => ({
type: FETCH_CONFIGURATION_SUCCESS,
configuration,
})

const fetchConfigurationFailure = error => ({
type: FETCH_CONFIGURATION_FAILURE,
error,
})

export const fetchConfiguration = () => dispatch => {
dispatch({
type: FETCH_CONFIGURATION,
})

request.get('http://localhost:5000/config')
.end((error, res) => {
if (error) {
dispatch(fetchConfigurationFailure(error))
} else {
const configuration = res.body

dispatch(fetchConfigurationSuccess(res.body))
dispatch(connect(configuration))
//dispatch(notifySuccess({
// message: 'configuration loaded',
// ttl: 2000,
//}))
dispatch(setDashboards(configuration.dashboards))
dispatch(startDashboardRotation(configuration.rotationDuration))
}
})
}
38 changes: 38 additions & 0 deletions src/ui/actions/dashboardsActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export const SET_DASHBOARDS = 'SET_DASHBOARDS'
export const SET_CURRENT_DASHBOARD = 'SET_CURRENT_DASHBOARD'


export const setDashboards = dashboards => ({
type: SET_DASHBOARDS,
dashboards,
})

const setCurrentDashboard = index => {
return {
type: SET_CURRENT_DASHBOARD,
index,
}
}

const nextDashboard = (interval, dispatch, getState) => {
setTimeout(() => {
const { dashboards: { dashboards, current } } = getState()

let next
if (current < dashboards.length - 1) {
next = current + 1
} else {
next = 0
}

dispatch(setCurrentDashboard(next))
nextDashboard(interval, dispatch, getState)
}, interval)
}

export const startDashboardRotation = interval => {
return (dispatch, getState) => {
nextDashboard(interval, dispatch, getState)
}
}

Loading

0 comments on commit 721fa06

Please sign in to comment.