Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit b267a6c

Browse files
committed
Starting work on local forms!!!
1 parent 22bb418 commit b267a6c

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

src/components/control-component.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,14 @@ function createControlClass(customControlPropsMap = {}, s = defaultStrategy) {
565565

566566
Control.propTypes = propTypes;
567567

568+
Control.contextTypes = {
569+
localStore: PropTypes.shape({
570+
subscribe: PropTypes.func,
571+
dispatch: PropTypes.func,
572+
getState: PropTypes.func,
573+
}),
574+
};
575+
568576
Control.defaultProps = {
569577
changeAction: s.actions.change,
570578
updateOn: 'change',

src/components/form-component.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ const propTypes = {
3131
onSubmit: PropTypes.func,
3232
dispatch: PropTypes.func,
3333
children: PropTypes.node,
34+
store: PropTypes.shape({
35+
subscribe: PropTypes.func,
36+
dispatch: PropTypes.func,
37+
getState: PropTypes.func,
38+
}),
3439
};
3540

3641
const defaultStrategy = {
@@ -52,7 +57,10 @@ function createFormClass(s = defaultStrategy) {
5257
}
5358

5459
getChildContext() {
55-
return { model: this.props.model };
60+
return {
61+
model: this.props.model,
62+
localStore: this.props.store,
63+
};
5664
}
5765

5866
componentDidMount() {
@@ -296,6 +304,11 @@ function createFormClass(s = defaultStrategy) {
296304

297305
Form.childContextTypes = {
298306
model: PropTypes.any,
307+
localStore: PropTypes.shape({
308+
subscribe: PropTypes.func,
309+
dispatch: PropTypes.func,
310+
getState: PropTypes.func,
311+
}),
299312
};
300313

301314
function mapStateToProps(state, { model }) {

src/local.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React, { PropTypes } from 'react';
2+
import Form from './components/form-component';
3+
import combineForms from './reducers/forms-reducer';
4+
import { createStore } from 'redux';
5+
6+
class LocalForm extends React.Component {
7+
constructor(props) {
8+
super(props);
9+
10+
this.store = props.store || createStore(combineForms({
11+
local: {},
12+
}));
13+
}
14+
15+
render() {
16+
return (
17+
<Form model="local" store={this.store} {...this.props} />
18+
);
19+
}
20+
}
21+
22+
LocalForm.propTypes = {
23+
store: PropTypes.shape({
24+
subscribe: PropTypes.func,
25+
dispatch: PropTypes.func,
26+
getState: PropTypes.func,
27+
}),
28+
};
29+
30+
export default LocalForm;

src/utils/resolve-model.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default function wrapWithModelResolver(WrappedComponent) {
2121
super(props, context);
2222

2323
this.model = context.model;
24+
this.store = context.localStore;
2425
}
2526
shouldComponentUpdate(nextProps) {
2627
return !shallowEqual(this.props, nextProps);
@@ -30,7 +31,11 @@ export default function wrapWithModelResolver(WrappedComponent) {
3031
this.props.model,
3132
this.model);
3233

33-
return <WrappedComponent {...this.props} model={resolvedModel} />;
34+
return (<WrappedComponent
35+
{...this.props}
36+
model={resolvedModel}
37+
store={this.store || undefined}
38+
/>);
3439
}
3540
}
3641

@@ -40,6 +45,11 @@ export default function wrapWithModelResolver(WrappedComponent) {
4045

4146
ResolvedModelWrapper.contextTypes = {
4247
model: PropTypes.any,
48+
localStore: PropTypes.shape({
49+
subscribe: PropTypes.func,
50+
dispatch: PropTypes.func,
51+
getState: PropTypes.func,
52+
}),
4353
};
4454

4555
return ResolvedModelWrapper;

0 commit comments

Comments
 (0)