Skip to content

Commit

Permalink
alpha.4
Browse files Browse the repository at this point in the history
  • Loading branch information
lupengyu committed Dec 19, 2016
1 parent 9660df2 commit 9a00546
Show file tree
Hide file tree
Showing 14 changed files with 715 additions and 698 deletions.
6 changes: 3 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "melon",
"version": "1.0.0-alpha.3",
"homepage": "http://react-melon.github.io/melon",
"version": "1.0.0-alpha.4",
"homepage": "http://react-melon.github.io/melon-form",
"authors": [
"ludafa@outlook.com"
],
"description": "react ui components",
"main": "lib/index.js",
"moduleType": [
"amd"
"umd"
],
"keywords": [
"react",
Expand Down
3 changes: 1 addition & 2 deletions lib/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/index.js.map

Large diffs are not rendered by default.

13 changes: 2 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "melon-form",
"version": "1.0.0-alpha.3",
"version": "1.0.0-alpha.4",
"description": "React Form",
"main": "./lib/index.js",
"scripts": {
Expand Down Expand Up @@ -136,16 +136,7 @@
],
"plugins": [
"transform-es3-property-literals",
"transform-es3-member-expression-literals",
[
"transform-runtime",
{
"helpers": true,
"polyfill": false,
"regenerator": false,
"moduleName": "babel-runtime"
}
]
"transform-es3-member-expression-literals"
]
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @file constants
* @author leon <ludafa@outlook.com>
*/

export const DEFAULT_META = {
touched: false,
submitting: false,
focus: false,
dirty: false,
error: null
};
153 changes: 75 additions & 78 deletions src/createActionCreators.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,57 @@ import * as types from './actionTypes';
import {isValid, resolveAsyncTasks} from './util/validity';
import * as selectors from './selectors';

function createEventMeta(name, type) {

return {
event: {
handler: type,
getEvent(state) {
return {
name,
value: state.value
};
}
}
};

}

export default function createActionCreators(options) {

return props => {
let model = options.model;

function createEventMeta(name, type) {
let memoizedActions;
let memoizedProps;

return {
event: {
handler: type,
getEvent(state) {
return {
name,
value: state.value
};
}
}
};
return props => {

if (memoizedActions && props === memoizedProps) {
return memoizedActions;
}

function initialize(value, schema, validator) {
function initialize(value) {
return {
type: types.INITIALIZE,
payload: {
value,
schema,
validator
model
}
};
}

function updateValidity(validity) {
return {
type: types.VALIDITY_UPDATE,
payload: validity
payload: {validity, model}
};
}

function validate(origin) {

return (dispatch, getState) => {

const {
model,
validate
} = options;
let validate = options.validate;

if (props.noValidate || !validate) {
return;
Expand Down Expand Up @@ -85,15 +90,16 @@ export default function createActionCreators(options) {

dispatch({
type: types.ASYNC_VALIDATE_START,
payload: name
payload: {name, model}
});

return task.then(
() => {
dispatch({
type: types.ASYNC_VALIDATE_SUCCEED,
payload: {
name
name,
model
}
});
},
Expand All @@ -102,7 +108,8 @@ export default function createActionCreators(options) {
type: types.ASYNC_VALIDATE_FAILED,
payload: {
name,
error
error,
model
}
});
}
Expand Down Expand Up @@ -138,15 +145,16 @@ export default function createActionCreators(options) {

function touchAll() {
return {
type: types.TOUCH_ALL
type: types.TOUCH_ALL,
payload: {model}
};
}

function submit(callback) {

return (dispatch, getState) => {

let state = getState()[options.model];
let state = getState()[model];

function onValidateFinish(validity) {

Expand All @@ -170,14 +178,15 @@ export default function createActionCreators(options) {

function reset() {
return {
type: types.RESET
type: types.RESET,
payload: {model}
};
}

function focus(name) {
return {
type: types.FOCUS,
payload: name
payload: {name, model}
};
}

Expand All @@ -186,7 +195,8 @@ export default function createActionCreators(options) {
type: types.CHANGE,
payload: {
name,
value
value,
model
},
meta: createEventMeta(name, 'onFieldChange')
};
Expand All @@ -198,7 +208,7 @@ export default function createActionCreators(options) {

dispatch({
type: types.BLUR,
payload: name
payload: {name, model}
});

return dispatch(validate(name));
Expand All @@ -210,25 +220,20 @@ export default function createActionCreators(options) {
function touch(name) {
return {
type: types.TOUCH,
payload: name
payload: {name, model}
};
}

function arrayPush(name, ...elements) {

return dispatch => {

dispatch({
type: types.ARRAY_PUSH,
payload: {
name,
elements
},
meta: createEventMeta(name, 'onFieldChange')
});

dispatch(validate(name));

return {
type: types.ARRAY_PUSH,
payload: {
name,
elements,
model
},
meta: createEventMeta(name, 'onFieldChange')
};

}
Expand All @@ -240,74 +245,64 @@ export default function createActionCreators(options) {
...replacements
) {

return dispatch => {

dispatch({
type: types.ARRAY_SPLICE,
payload: {
name,
start,
deleteCount,
replacements
},
meta: createEventMeta(name, 'onFieldChange')
});

dispatch(validate(name));

return {
type: types.ARRAY_SPLICE,
payload: {
name,
start,
deleteCount,
replacements,
model
},
meta: createEventMeta(name, 'onFieldChange')
};

}

function arraySwap(name, from, to) {

return dispatch => {

dispatch({
type: types.ARRAY_SWAP,
payload: {
from,
to,
name
},
meta: createEventMeta(name, 'onFieldChange')
});

dispatch(validate(name));

return {
type: types.ARRAY_SWAP,
payload: {
from,
to,
name,
model
},
meta: createEventMeta(name, 'onFieldChange')
};

}

function register(name) {
return {
type: types.REGISTER,
payload: name
payload: {name, model}
};
}

function unregister(name) {
return {
type: types.UNREGISTER,
payload: name
payload: {name, model}
};
}

function startPending(name) {
return {
type: types.PENDING_START,
payload: name
payload: {name, model}
};
}

function stopPending(name) {
return {
type: types.PENDING_STOP,
payload: name
payload: {name, model}
};
}

return {
memoizedActions = {

// form
initialize,
Expand All @@ -334,6 +329,8 @@ export default function createActionCreators(options) {
arraySwap
};

return memoizedActions;

};

}

0 comments on commit 9a00546

Please sign in to comment.