Created
December 11, 2016 19:58
-
-
Save tannerlinsley/6bf958a4e9be1069f13058247a95466a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { State } from 'jumpsuit' | |
import _ from 'lodash' | |
import {FormDefaultProps} from 'react-form' | |
const formState = State('react-form', { | |
initial: {}, | |
set (state, form) { | |
return { | |
...state, | |
[form.id]: form | |
} | |
}, | |
clear (state, id) { | |
return { | |
...state, | |
[id]: undefined | |
} | |
} | |
}) | |
export default formState | |
_.assign(FormDefaultProps, { | |
saveState: (state, props) => { | |
if (props.id) { | |
formState.set({ | |
id: props.id, | |
state | |
}) | |
} | |
}, | |
loadState: (props) => { | |
if (!props.id) { | |
return | |
} | |
const state = formState.getState() | |
if (state[props.id]) { | |
return state[props.id].state | |
} | |
}, | |
clearState: (props) => { | |
if (!props.id) { | |
return | |
} | |
formState.clear(props.id) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment