Skip to content

Commit 75136a6

Browse files
authored
Merge branch 'master' into refactor2
2 parents a40e241 + 3bfeb35 commit 75136a6

28 files changed

+1123
-17
lines changed

.eslintrc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
],
1313
"rules": {
1414
"brace-style": 0,
15-
"import/no-extraneous-dependencies": 0,
16-
"jsx-a11y/no-static-element-interactions": 0,
1715
"linebreak-style": 0,
1816
"new-cap": 0,
1917
"newline-per-chained-call": 1,
2018
"no-mixed-operators": 0,
2119
"radix": 1,
20+
"no-use-before-define": 0,
21+
"import/no-extraneous-dependencies": 0,
22+
"import/prefer-default-export": 0,
23+
"jsx-a11y/no-static-element-interactions": 0,
2224
"react/forbid-prop-types": 0,
2325
"react/jsx-filename-extension": [
2426
1,

.flowconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[include]
2+
3+
[ignore]
4+
5+
[libs]
6+
7+
[options]

circle.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
machine:
22
node:
33
version: 6.2.1
4+
45
test:
56
post:
67
- npm run coverage

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"packages": [
44
"packages/*"
55
],
6-
"version": "0.0.5"
6+
"version": "0.0.6"
77
}

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"start": "lerna exec -- npm start",
44
"link": "lerna exec -- npm link @accounts/client; lerna exec -- npm link @accounts/common; lerna exec -- npm link; lerna exec -- npm link @accounts/react",
55
"compile": "lerna run compile",
6+
"flow:check": "flow check",
67
"lint": "eslint packages/*/src",
78
"prebootstrap": "npm install",
89
"postinstall": "lerna bootstrap",
@@ -19,13 +20,14 @@
1920
},
2021
"license": "MIT",
2122
"devDependencies": {
22-
"lerna": "2.0.0-beta.37",
23-
"eslint": "^3.10.2",
2423
"babel-eslint": "^7.1.1",
24+
"eslint": "^3.10.2",
2525
"eslint-config-airbnb": "^13.0.0",
2626
"eslint-config-airbnb-base": "^10.0.1",
2727
"eslint-plugin-import": "^2.2.0",
2828
"eslint-plugin-jsx-a11y": "^2.2.3",
29-
"eslint-plugin-react": "^6.7.1"
29+
"eslint-plugin-react": "^6.7.1",
30+
"flow-bin": "^0.38.0",
31+
"lerna": "2.0.0-beta.32"
3032
}
3133
}

packages/material-ui/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@accounts/react-material-ui",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "React frontend build with material-ui for js-accounts",
55
"main": "lib/index.js",
66
"scripts": {
@@ -73,9 +73,9 @@
7373
"webpack-node-externals": "^1.5.4"
7474
},
7575
"dependencies": {
76-
"@accounts/client": "next",
77-
"@accounts/common": "next",
78-
"@accounts/react": "next",
76+
"@accounts/client": "0.0.3",
77+
"@accounts/common": "0.0.3",
78+
"@accounts/react": "^0.0.6",
7979
"flexbox-react": "^4.1.0",
8080
"material-ui": "^0.16.4",
8181
"react-dom": "^15.4.0",

packages/react-native/.npmigonre

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

packages/react-native/package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "@accounts/react-native",
3+
"version": "0.0.6",
4+
"description": "react-native components for js-accounts",
5+
"main": "src/index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/js-accounts/react.git"
12+
},
13+
"author": "David Yahalomi",
14+
"license": "MIT",
15+
"dependencies": {
16+
"immutable": "^3.8.1",
17+
"lodash.isempty": "^4.4.0",
18+
"lodash.memoize": "^4.1.2",
19+
"reselect": "^2.5.4"
20+
},
21+
"devDependencies": {
22+
"flow-bin": "^0.38.0",
23+
"@accounts/client": "^0.0.5",
24+
"@accounts/common": "^0.0.5",
25+
"react": "^15.4.2",
26+
"react-native": "^0.41.1",
27+
"react-redux": "^5.0.2",
28+
"redux-thunk": "^2.2.0",
29+
"redux": "^3.6.0"
30+
},
31+
"peerDependencies": {
32+
"@accounts/client": "^0.0.5",
33+
"@accounts/common": "^0.0.5",
34+
"react": "^15.4.2",
35+
"react-native": "^0.41.1",
36+
"react-redux": "^5.0.2",
37+
"redux-thunk": "^2.2.0",
38+
"redux": "^3.6.0"
39+
}
40+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// @flow
2+
import memoize from 'lodash.memoize';
3+
import type { Dispatch } from 'redux';
4+
5+
const DOM = 'FORMS/';
6+
export const FORM_SUBMITTED = `${DOM}FORM_SUBMITTED`;
7+
export const FORM_APPROVED = `${DOM}FORM_APPROVED`;
8+
export const FORM_ERROR = `${DOM}FORM_ERROR`;
9+
export const FORM_CLEAR = `${DOM}FORM_CLEAR`;
10+
export const FIELD_UPDATED = `${DOM}FIELD_UPDATED`;
11+
export const FIELD_CLEAR = `${DOM}FIELD_CLEAR`;
12+
export const FIELD_ERROR = `${DOM}FIELD_RESET`;
13+
14+
export const submittedForm = (formName: string) => () => ({
15+
type: FORM_SUBMITTED,
16+
formName,
17+
});
18+
19+
export const approvedForm = (formName: string) => (result: Object) => ({
20+
type: FORM_APPROVED,
21+
formName,
22+
result,
23+
});
24+
25+
export const errorForm = (formName: string) => (error: string | Error) => ({
26+
type: FORM_ERROR,
27+
formName,
28+
error,
29+
});
30+
31+
const errorMessage = err => ((typeof err !== 'string') ? err.message : err);
32+
33+
export const submitForm = (formName: string) => (submit: (Object) => Promise<any>) => () =>
34+
(dispatch: Dispatch<Object>, getState: Function) => {
35+
const boundSubmittedForm = submittedForm(formName);
36+
dispatch(boundSubmittedForm());
37+
38+
const state = getState();
39+
40+
submit(state).then(
41+
res => {
42+
dispatch(approvedForm(formName)(res));
43+
dispatch(clearForm(formName)());
44+
},
45+
err => dispatch(errorForm(formName)(errorMessage(err)))
46+
);
47+
};
48+
49+
export const clearForm = (formName: string) => () => ({
50+
type: FORM_CLEAR,
51+
formName,
52+
});
53+
54+
export const updateField = (formName: string) => (fieldName: string) => (event: Object) => ({
55+
type: FIELD_UPDATED,
56+
formName,
57+
fieldName,
58+
value: event && event.nativeEvent && event.nativeEvent.text,
59+
});
60+
61+
export const clearField = (formName: string) => (fieldName: string) => () => ({
62+
type: FIELD_CLEAR,
63+
formName,
64+
fieldName,
65+
});
66+
67+
export const errorField = (formName: string) => (fieldName: string) => (error: string) => ({
68+
type: FIELD_ERROR,
69+
formName,
70+
fieldName,
71+
error,
72+
});
73+
74+
export const createFormActions = memoize((formName: string) => ({
75+
submitForm: submitForm(formName),
76+
approvedForm: approvedForm(formName),
77+
errorForm: errorForm(formName),
78+
clearForm: clearForm(formName),
79+
updateField: updateField(formName),
80+
clearField: clearField(formName),
81+
errorField: errorField(formName),
82+
}));
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { createReducer, filterActions } from '../redux/util';
2+
3+
import {
4+
FIELD_UPDATED,
5+
FIELD_ERROR,
6+
FIELD_CLEAR,
7+
FORM_SUBMITTED,
8+
FORM_APPROVED,
9+
FORM_ERROR,
10+
FORM_CLEAR,
11+
} from './actions';
12+
13+
const fieldUpdatedHandler = (state, action) => {
14+
const validate = state.getIn([action.fieldName, 'validate']);
15+
16+
return state.setIn([action.fieldName, 'value'], action.value)
17+
.setIn([action.fieldName, 'error'], validate(action.value));
18+
};
19+
20+
const formReducer = initialState => createReducer(initialState, {
21+
// Per field reducers
22+
[FIELD_UPDATED]: fieldUpdatedHandler,
23+
[FIELD_CLEAR]: (state, action) => state.remove(action.fieldName),
24+
[FIELD_ERROR]: (state, action) => state.setIn([action.fieldName, 'error'], action.error),
25+
26+
// Per form reducer
27+
[FORM_SUBMITTED]: state => state.set('submitting', true),
28+
[FORM_APPROVED]: state => state.set('submitting', false),
29+
[FORM_ERROR]: (state, action) => state.set('error', action.error),
30+
[FORM_CLEAR]: () => initialState,
31+
});
32+
33+
const formNameFilter = formName => action => action.formName === formName;
34+
export const createFormReducer = (formName, initialState) =>
35+
filterActions(formNameFilter(formName), formReducer(initialState), initialState);

0 commit comments

Comments
 (0)