-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/new context api #198
Merged
rkuykendall
merged 18 commits into
formsy:master
from
ThibautMarechal:feature/new-context-api
Feb 15, 2020
Merged
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
62a0bf0
Merge pull request #1 from formsy/master
ThibautMarechal 46534c2
first draw
ThibautMarechal c3b97f7
working solution
ThibautMarechal 3a773b6
remove childContextTypes
ThibautMarechal 8180300
Merge branch 'master' into feature/new-context-api
ThibautMarechal 547ef49
Merge remote-tracking branch 'formsy/master' into feature/new-context…
ThibautMarechal 37bf258
tests passing :)
ThibautMarechal 474ddc2
make eslint? work
ThibautMarechal c3790fe
Merge remote-tracking branch 'formsy/master'
ThibautMarechal ee08c30
build
ThibautMarechal 0f45780
Merge branch 'master' into feature/new-context-api
ThibautMarechal 238e443
fix merge
ThibautMarechal 8f49cb2
Update src/FormsyContext.ts
ThibautMarechal f33066b
Update src/index.ts
ThibautMarechal ddaaae0
CR rkuykendall
ThibautMarechal 10b3935
Merge branch 'feature/new-context-api' of https://github.com/ThibautM…
ThibautMarechal bfa8767
don't commit build files
ThibautMarechal 4d02570
Update src/index.ts
ThibautMarechal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react'; | ||
import { FormsyContextInterface } from './interfaces'; | ||
|
||
const noFormsyErrorMessage = 'No Context Provider defined'; | ||
|
||
const throwNoFormsyProvider = () => { | ||
throw new Error(noFormsyErrorMessage); | ||
}; | ||
|
||
const defaultValue = { | ||
attachToForm: throwNoFormsyProvider, | ||
detachFromForm: throwNoFormsyProvider, | ||
isFormDisabled: () => true, | ||
isValidValue: throwNoFormsyProvider, | ||
validate: throwNoFormsyProvider, | ||
}; | ||
|
||
export default React.createContext<FormsyContextInterface>(defaultValue); |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,21 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import formDataToObject from 'form-data-to-object'; | ||
import FormsyContext from './FormsyContext'; | ||
|
||
import utils from './utils'; | ||
import validationRules from './validationRules'; | ||
import Wrapper, { propTypes } from './Wrapper'; | ||
|
||
import { IData, IModel, InputComponent, IResetModel, IUpdateInputsWithError, ValidationFunction } from './interfaces'; | ||
import { | ||
IData, | ||
IModel, | ||
InputComponent, | ||
IResetModel, | ||
IUpdateInputsWithError, | ||
ValidationFunction, | ||
FormsyContextInterface, | ||
} from './interfaces'; | ||
|
||
type FormHTMLAttributesCleaned = Omit<React.FormHTMLAttributes<HTMLFormElement>, 'onChange' | 'onSubmit'>; | ||
|
||
|
@@ -54,6 +63,8 @@ class Formsy extends React.Component<FormsyProps, FormsyState> { | |
|
||
public emptyArray: any[]; | ||
|
||
public contextValue: FormsyContextInterface; | ||
|
||
public prevInputNames: any[] | null = null; | ||
|
||
public static displayName = 'Formsy'; | ||
|
@@ -117,10 +128,6 @@ class Formsy extends React.Component<FormsyProps, FormsyState> { | |
validationErrors: PropTypes.object, // eslint-disable-line | ||
}; | ||
|
||
public static childContextTypes = { | ||
formsy: PropTypes.object, | ||
}; | ||
|
||
public constructor(props: FormsyProps) { | ||
super(props); | ||
this.state = { | ||
|
@@ -130,17 +137,14 @@ class Formsy extends React.Component<FormsyProps, FormsyState> { | |
}; | ||
this.inputs = []; | ||
this.emptyArray = []; | ||
} | ||
|
||
public getChildContext = () => ({ | ||
formsy: { | ||
this.contextValue = { | ||
attachToForm: this.attachToForm, | ||
detachFromForm: this.detachFromForm, | ||
isFormDisabled: this.isFormDisabled, | ||
isValidValue: (component, value) => this.runValidation(component, value).isValid, | ||
validate: this.validate, | ||
}, | ||
}); | ||
}; | ||
} | ||
|
||
public componentDidMount = () => { | ||
this.validateForm(); | ||
|
@@ -509,16 +513,20 @@ class Formsy extends React.Component<FormsyProps, FormsyState> { | |
...nonFormsyProps | ||
} = this.props; | ||
|
||
return React.createElement( | ||
'form', | ||
{ | ||
onReset: this.resetInternal, | ||
onSubmit: this.submit, | ||
...nonFormsyProps, | ||
disabled: false, | ||
}, | ||
// eslint-disable-next-line react/destructuring-assignment | ||
this.props.children, | ||
return ( | ||
<FormsyContext.Provider value={this.contextValue}> | ||
{React.createElement( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason to not convert this to jsx? Mixing jsx and |
||
'form', | ||
{ | ||
onReset: this.resetInternal, | ||
onSubmit: this.submit, | ||
...nonFormsyProps, | ||
disabled: false, | ||
}, | ||
// eslint-disable-next-line react/destructuring-assignment | ||
this.props.children, | ||
)} | ||
</FormsyContext.Provider> | ||
); | ||
}; | ||
} | ||
|
This file contains 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's been 2 years, so this seems like an acceptable change.