@getoccasion/mitragyna
Advanced tools
+14
-0
@@ -0,1 +1,15 @@ | ||
| ## [0.1.2] - 2020-05-07 | ||
| ### Added | ||
| - add active resource as a peer dependency | ||
| ### Fixed | ||
| - main pointing to index.js | ||
| ### Removed | ||
| - Underscore dependency | ||
| ## [0.1.1] - 2020-05-07 | ||
@@ -2,0 +16,0 @@ |
+7
-14
| { | ||
| "name": "@getoccasion/mitragyna", | ||
| "version": "0.1.1", | ||
| "version": "0.1.2", | ||
| "description": "A library for managing ActiveResource.js as React components", | ||
| "main": "src/mitragyna.js", | ||
| "main": "src/index.js", | ||
| "repository": { | ||
@@ -26,12 +26,3 @@ "type": "git", | ||
| "babel-plugin-transform-react-jsx": "^6.24.1", | ||
| "babel-preset-env": "^1.6.1", | ||
| "grunt": "0.x.x", | ||
| "grunt-babel": "^7.0.0", | ||
| "grunt-contrib-clean": "0.5.x", | ||
| "grunt-contrib-concat": "^1.0.1", | ||
| "grunt-contrib-connect": "0.4.x", | ||
| "grunt-contrib-uglify": "^3.3.0", | ||
| "grunt-contrib-watch": "0.5.x", | ||
| "grunt-umd": "^2.4.0", | ||
| "load-grunt-tasks": "^3.5.2" | ||
| "babel-preset-env": "^1.6.1" | ||
| }, | ||
@@ -42,5 +33,7 @@ "dependencies": { | ||
| "react": "^16.2.0", | ||
| "shallowequal": "^1.0.2", | ||
| "underscore": "^1.8.3" | ||
| "shallowequal": "^1.0.2" | ||
| }, | ||
| "peerDependencies": { | ||
| "active-resource": "GetOccasion/activeresource.js#track_local_changes" | ||
| } | ||
| } |
+34
-49
@@ -1,12 +0,8 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import ActiveResource from 'active-resource'; | ||
| import _ from 'underscore'; | ||
| import React from "react"; | ||
| import PropTypes from "prop-types"; | ||
| import ActiveResource from "active-resource"; | ||
| export class Collection extends React.PureComponent { | ||
| export default class Collection extends React.PureComponent { | ||
| static propTypes = { | ||
| children: PropTypes.oneOfType([ | ||
| PropTypes.array, | ||
| PropTypes.node, | ||
| ]), | ||
| children: PropTypes.oneOfType([PropTypes.array, PropTypes.node]), | ||
| className: PropTypes.string, | ||
@@ -16,6 +12,3 @@ blankComponent: PropTypes.func, | ||
| componentProps: PropTypes.object, | ||
| subject: PropTypes.oneOfType([ | ||
| PropTypes.object, | ||
| PropTypes.func, | ||
| ]).isRequired, | ||
| subject: PropTypes.oneOfType([PropTypes.object, PropTypes.func]).isRequired, | ||
| reflection: PropTypes.string, | ||
@@ -25,3 +18,3 @@ }; | ||
| static defaultProps = { | ||
| inlineRows: false | ||
| inlineRows: false, | ||
| }; | ||
@@ -36,11 +29,4 @@ | ||
| this.state = { | ||
| target: ActiveResource.prototype.Collection.build() | ||
| target: ActiveResource.prototype.Collection.build(), | ||
| }; | ||
| _.bindAll(this, | ||
| 'buildOnTarget', | ||
| 'cloneTarget', | ||
| 'replaceOnTarget', | ||
| 'removeFromTarget', | ||
| ); | ||
| } | ||
@@ -59,6 +45,6 @@ | ||
| this.setState({ target: subject.target() }) | ||
| this.setState({ target: subject.target() }); | ||
| } | ||
| buildOnTarget(attributes) { | ||
| buildOnTarget = (attributes) => { | ||
| const { subject } = this.props; | ||
@@ -70,5 +56,5 @@ let target = this.cloneTarget(); | ||
| this.setState({ target: target }); | ||
| } | ||
| }; | ||
| replaceOnTarget(newItem, oldItem) { | ||
| replaceOnTarget = (newItem, oldItem) => { | ||
| let target = this.cloneTarget(); | ||
@@ -79,5 +65,5 @@ | ||
| return this.setState({ target }); | ||
| } | ||
| }; | ||
| removeFromTarget(item) { | ||
| removeFromTarget = (item) => { | ||
| let target = this.cloneTarget(); | ||
@@ -88,7 +74,7 @@ | ||
| return this.setState({ target }); | ||
| } | ||
| }; | ||
| cloneTarget() { | ||
| cloneTarget = () => { | ||
| return this.state.target.clone(); | ||
| } | ||
| }; | ||
@@ -100,20 +86,19 @@ render() { | ||
| return ( | ||
| <section className={ className }> | ||
| { | ||
| target.size() > 0 ? ( | ||
| target.map((t, indexOf) => | ||
| <Resource afterUpdate={this.replaceOnTarget} | ||
| component={component} componentProps={{...componentProps, indexOf}} | ||
| key={t.id || (t.klass().className + '-' + indexOf)} | ||
| reflection={reflection} | ||
| subject={t}> | ||
| {children} | ||
| </Resource> | ||
| ).toArray() | ||
| ) : (blankComponent != null && | ||
| blankComponent() | ||
| ) | ||
| } | ||
| <section className={className}> | ||
| {target.size() > 0 | ||
| ? target | ||
| .map((t, indexOf) => ( | ||
| <Resource | ||
| afterUpdate={this.replaceOnTarget} | ||
| component={component} | ||
| componentProps={{ ...componentProps, indexOf }} | ||
| key={t.id || t.klass().className + "-" + indexOf} | ||
| reflection={reflection} | ||
| subject={t} | ||
| > | ||
| {children} | ||
| </Resource> | ||
| )) | ||
| .toArray() | ||
| : blankComponent != null && blankComponent()} | ||
| </section> | ||
@@ -120,0 +105,0 @@ ); |
+20
-12
@@ -1,2 +0,2 @@ | ||
| export class ErrorsFor extends React.Component { | ||
| export default class ErrorsFor extends React.Component { | ||
| static propTypes = { | ||
@@ -12,3 +12,7 @@ component: PropTypes.func, | ||
| shouldComponentUpdate(nextProps, nextState, nextContext) { | ||
| return !(shallowEqual(this.props, nextProps) && shallowEqual(this.state, nextState) && shallowEqual(this.context, nextContext)); | ||
| return !( | ||
| shallowEqual(this.props, nextProps) && | ||
| shallowEqual(this.state, nextState) && | ||
| shallowEqual(this.context, nextContext) | ||
| ); | ||
| } | ||
@@ -22,16 +26,20 @@ | ||
| if(errors.empty()) return null; | ||
| if (errors.empty()) return null; | ||
| let customProps = _.omit(this.props, _.keys(ErrorsFor.propTypes)); | ||
| let finalComponent = component || 'summary'; | ||
| return React.createElement(finalComponent, { | ||
| ...customProps, | ||
| key: field, | ||
| }, | ||
| errors.map((error) => { | ||
| return <span key={ error.code }>{ error.message }</span> | ||
| }).toArray() | ||
| let finalComponent = component || "summary"; | ||
| return React.createElement( | ||
| finalComponent, | ||
| { | ||
| ...customProps, | ||
| key: field, | ||
| }, | ||
| errors | ||
| .map((error) => { | ||
| return <span key={error.code}>{error.message}</span>; | ||
| }) | ||
| .toArray() | ||
| ); | ||
| } | ||
| }; | ||
| } |
+102
-109
@@ -1,5 +0,5 @@ | ||
| import classNames from 'classnames'; | ||
| import shallowEqual from 'shallowequal'; | ||
| import classNames from "classnames"; | ||
| import shallowEqual from "shallowequal"; | ||
| export class Field extends React.Component { | ||
| export default class Field extends React.Component { | ||
| static contextTypes = { | ||
@@ -23,6 +23,3 @@ changeRadio: PropTypes.func, | ||
| options: PropTypes.instanceOf(ActiveResource.Collection), | ||
| optionsLabel: PropTypes.oneOfType([ | ||
| PropTypes.string, | ||
| PropTypes.func, | ||
| ]), | ||
| optionsLabel: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), | ||
| type: PropTypes.string.isRequired, | ||
@@ -37,9 +34,3 @@ uncheckedValue: PropTypes.oneOfType([ | ||
| invalidClassName: PropTypes.string, | ||
| value: PropTypes.oneOfType([ | ||
| PropTypes.object, | ||
| PropTypes.func, | ||
| PropTypes.string, | ||
| PropTypes.number, | ||
| PropTypes.bool, | ||
| ]) | ||
| value: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string, PropTypes.number, PropTypes.bool]), | ||
| }; | ||
@@ -50,17 +41,18 @@ | ||
| _.bindAll(this, | ||
| 'afterChange', | ||
| 'changeRadio', | ||
| 'classNames', | ||
| 'commonInputProps', | ||
| 'customInputProps', | ||
| 'getValue', | ||
| 'handleChange', | ||
| 'renderCheckboxComponent', | ||
| 'renderInputComponent', | ||
| 'renderRadioComponent', | ||
| 'renderSelectComponent', | ||
| 'renderTextareaComponent', | ||
| 'setValue', | ||
| 'valueFor', | ||
| _.bindAll( | ||
| this, | ||
| "afterChange", | ||
| "changeRadio", | ||
| "classNames", | ||
| "commonInputProps", | ||
| "customInputProps", | ||
| "getValue", | ||
| "handleChange", | ||
| "renderCheckboxComponent", | ||
| "renderInputComponent", | ||
| "renderRadioComponent", | ||
| "renderSelectComponent", | ||
| "renderTextareaComponent", | ||
| "setValue", | ||
| "valueFor" | ||
| ); | ||
@@ -72,3 +64,7 @@ | ||
| shouldComponentUpdate(nextProps, nextState, nextContext) { | ||
| return !(shallowEqual(this.props, nextProps) && shallowEqual(this.state, nextState) && shallowEqual(this.context, nextContext)); | ||
| return !( | ||
| shallowEqual(this.props, nextProps) && | ||
| shallowEqual(this.state, nextState) && | ||
| shallowEqual(this.context, nextContext) | ||
| ); | ||
| } | ||
@@ -80,4 +76,4 @@ | ||
| switch(type) { | ||
| case 'radioGroup': | ||
| switch (type) { | ||
| case "radioGroup": | ||
| return { | ||
@@ -101,10 +97,10 @@ changeRadio: this.changeRadio, | ||
| resource, | ||
| value: this.valueFor(resource, this.props) | ||
| value: this.valueFor(resource, this.props), | ||
| }); | ||
| switch(type) { | ||
| case 'email': | ||
| case 'number': | ||
| case 'text': | ||
| case 'textarea': | ||
| switch (type) { | ||
| case "email": | ||
| case "number": | ||
| case "text": | ||
| case "textarea": | ||
| this.afterChange = _.debounce(this.afterChange, 500); | ||
@@ -115,13 +111,13 @@ } | ||
| componentDidUpdate(prevProps, prevState) { | ||
| const { resource: prevResource } = prevState | ||
| const { resource } = this.context | ||
| const { resource: prevResource } = prevState; | ||
| const { resource } = this.context; | ||
| if(prevResource !== resource) { | ||
| this.setState({ resource }) | ||
| if (prevResource !== resource) { | ||
| this.setState({ resource }); | ||
| } | ||
| if(!(_.isNull(prevResource.id) || _.isUndefined(prevResource.id)) && prevResource.id !== resource.id) { | ||
| if (!(_.isNull(prevResource.id) || _.isUndefined(prevResource.id)) && prevResource.id !== resource.id) { | ||
| this.setState({ | ||
| value: this.valueFor(resource, this.props) | ||
| }) | ||
| value: this.valueFor(resource, this.props), | ||
| }); | ||
| } | ||
@@ -134,8 +130,5 @@ } | ||
| return classNames( | ||
| className, | ||
| { | ||
| [invalidClassName]: !resource.errors().forField(name).empty() | ||
| } | ||
| ); | ||
| return classNames(className, { | ||
| [invalidClassName]: !resource.errors().forField(name).empty(), | ||
| }); | ||
| } | ||
@@ -157,12 +150,12 @@ | ||
| componentFor(type) { | ||
| switch(type) { | ||
| case 'checkbox': | ||
| switch (type) { | ||
| case "checkbox": | ||
| return this.renderCheckboxComponent(); | ||
| case 'radio': | ||
| case "radio": | ||
| return this.renderRadioComponent(); | ||
| case 'radioGroup': | ||
| case "radioGroup": | ||
| return this.renderRadioGroupComponent(); | ||
| case 'select': | ||
| case "select": | ||
| return this.renderSelectComponent(); | ||
| case 'textarea': | ||
| case "textarea": | ||
| return this.renderTextareaComponent(); | ||
@@ -180,11 +173,11 @@ default: | ||
| var omittedProps; | ||
| switch(type) { | ||
| case 'radio': | ||
| omittedProps = _.omit(Field.propTypes, ['type', 'name']); | ||
| switch (type) { | ||
| case "radio": | ||
| omittedProps = _.omit(Field.propTypes, ["type", "name"]); | ||
| break; | ||
| case 'select': | ||
| omittedProps = component ? _.omit(Field.propTypes, 'type') : Field.propTypes; | ||
| case "select": | ||
| omittedProps = component ? _.omit(Field.propTypes, "type") : Field.propTypes; | ||
| break; | ||
| default: | ||
| omittedProps = _.omit(Field.propTypes, 'type'); | ||
| omittedProps = _.omit(Field.propTypes, "type"); | ||
| } | ||
@@ -199,20 +192,22 @@ | ||
| switch(type) { | ||
| case 'checkbox': | ||
| switch (type) { | ||
| case "checkbox": | ||
| var resourceValue = resource[name]; | ||
| if(resourceValue == value) { | ||
| if (resourceValue == value) { | ||
| return true; | ||
| } else if(resourceValue == uncheckedValue || _.isUndefined(resourceValue) || _.isNull(resourceValue)) { | ||
| } else if (resourceValue == uncheckedValue || _.isUndefined(resourceValue) || _.isNull(resourceValue)) { | ||
| return false; | ||
| } else { | ||
| throw 'Field ' + name + ' with value ' + resource[name] + ' does not match value or uncheckedValue for checkbox' | ||
| throw ( | ||
| "Field " + name + " with value " + resource[name] + " does not match value or uncheckedValue for checkbox" | ||
| ); | ||
| } | ||
| case 'radioGroup': | ||
| case 'select': | ||
| case "radioGroup": | ||
| case "select": | ||
| var val = resource[name](); | ||
| return val ? val.id : ''; | ||
| return val ? val.id : ""; | ||
| default: | ||
| var val = resource[name]; | ||
| return val ? val : ''; | ||
| return val ? val : ""; | ||
| } | ||
@@ -230,3 +225,3 @@ } | ||
| let finalComponent = component || 'input'; | ||
| let finalComponent = component || "input"; | ||
| return React.createElement(finalComponent, { | ||
@@ -242,3 +237,3 @@ ...this.commonInputProps(), | ||
| let finalComponent = component || 'input'; | ||
| let finalComponent = component || "input"; | ||
| return React.createElement(finalComponent, { | ||
@@ -259,3 +254,3 @@ ...this.commonInputProps(), | ||
| let finalComponent = component || 'input'; | ||
| let finalComponent = component || "input"; | ||
| return React.createElement(finalComponent, { | ||
@@ -266,3 +261,3 @@ ...this.commonInputProps(), | ||
| value: value.id, | ||
| name: value.questionId | ||
| name: value.questionId, | ||
| }); | ||
@@ -272,5 +267,3 @@ } | ||
| renderRadioGroupComponent() { | ||
| return <div> | ||
| { this.props.children } | ||
| </div>; | ||
| return <div>{this.props.children}</div>; | ||
| } | ||
@@ -286,23 +279,23 @@ | ||
| selectOptions = options.map((o) => { | ||
| return <option key={o.id} value={o.id}> | ||
| { | ||
| _.isString(optionsLabel) ? ( | ||
| o[optionsLabel] | ||
| ) : ( | ||
| optionsLabel(o) | ||
| ) | ||
| } | ||
| </option>; | ||
| return ( | ||
| <option key={o.id} value={o.id}> | ||
| {_.isString(optionsLabel) ? o[optionsLabel] : optionsLabel(o)} | ||
| </option> | ||
| ); | ||
| }); | ||
| if (includeBlank) { | ||
| selectOptions.unshift(<option key={-1} value=''></option>); | ||
| selectOptions.unshift(<option key={-1} value=""></option>); | ||
| } | ||
| } | ||
| let finalComponent = component || 'select'; | ||
| return React.createElement(finalComponent, { | ||
| ...this.commonInputProps(), | ||
| ...this.customInputProps(), | ||
| value: this.state.value, | ||
| }, selectOptions.toArray()); | ||
| let finalComponent = component || "select"; | ||
| return React.createElement( | ||
| finalComponent, | ||
| { | ||
| ...this.commonInputProps(), | ||
| ...this.customInputProps(), | ||
| value: this.state.value, | ||
| }, | ||
| selectOptions.toArray() | ||
| ); | ||
| } | ||
@@ -313,3 +306,3 @@ | ||
| let finalComponent = component || 'textarea'; | ||
| let finalComponent = component || "textarea"; | ||
| return React.createElement(finalComponent, { | ||
@@ -330,10 +323,10 @@ ...this.commonInputProps(), | ||
| switch(type) { | ||
| case 'checkbox': | ||
| switch (type) { | ||
| case "checkbox": | ||
| value = e.target.checked; | ||
| break; | ||
| case 'number': | ||
| if(e.target.value > max) { | ||
| case "number": | ||
| if (e.target.value > max) { | ||
| value = max; | ||
| } else if(e.target.value < min) { | ||
| } else if (e.target.value < min) { | ||
| value = min; | ||
@@ -345,3 +338,3 @@ } else { | ||
| break; | ||
| case 'radio': | ||
| case "radio": | ||
| changeRadio(e.target.value); | ||
@@ -362,5 +355,5 @@ break; | ||
| let mappedValue; | ||
| switch(type) { | ||
| case 'checkbox': | ||
| if(stateValue) { | ||
| switch (type) { | ||
| case "checkbox": | ||
| if (stateValue) { | ||
| mappedValue = value; | ||
@@ -371,6 +364,6 @@ } else { | ||
| break; | ||
| case 'radio': | ||
| case "radio": | ||
| mappedValue = value; | ||
| break; | ||
| case 'select': | ||
| case "select": | ||
| mappedValue = options.detect((o) => o.id === stateValue); | ||
@@ -393,4 +386,4 @@ break; | ||
| let mappedValue = { persist: _.noop }; | ||
| switch(type) { | ||
| case 'checkbox': | ||
| switch (type) { | ||
| case "checkbox": | ||
| mappedValue = { ...mappedValue, target: { checked: value } }; | ||
@@ -397,0 +390,0 @@ break; |
+64
-58
@@ -1,9 +0,6 @@ | ||
| export class Resource extends React.Component { | ||
| export default class Resource extends React.Component { | ||
| static propTypes = { | ||
| afterError: PropTypes.func, | ||
| afterUpdate: PropTypes.func, | ||
| children: PropTypes.oneOfType([ | ||
| PropTypes.array, | ||
| PropTypes.node, | ||
| ]), | ||
| children: PropTypes.oneOfType([PropTypes.array, PropTypes.node]), | ||
| className: PropTypes.string, | ||
@@ -50,10 +47,11 @@ component: PropTypes.func, | ||
| _.bindAll(this, | ||
| 'afterUpdate', | ||
| 'assignChanges', | ||
| 'queueReflectionChange', | ||
| 'shiftReflectionQueue', | ||
| 'queueChange', | ||
| 'handleSubmit', | ||
| 'updateRoot' | ||
| _.bindAll( | ||
| this, | ||
| "afterUpdate", | ||
| "assignChanges", | ||
| "queueReflectionChange", | ||
| "shiftReflectionQueue", | ||
| "queueChange", | ||
| "handleSubmit", | ||
| "updateRoot" | ||
| ); | ||
@@ -66,7 +64,7 @@ | ||
| if(reflection) { | ||
| if (reflection) { | ||
| var reflectionInstance = root.klass().reflectOnAssociation(reflection); | ||
| if(_.isUndefined(reflectionInstance)) throw 'Reflection ' + reflection + ' not found.'; | ||
| if (_.isUndefined(reflectionInstance)) throw "Reflection " + reflection + " not found."; | ||
| var inverseReflection = reflectionInstance.inverseOf(); | ||
| if(_.isUndefined(inverseReflection)) throw 'Reflection ' + reflection + ' must have inverse.'; | ||
| if (_.isUndefined(inverseReflection)) throw "Reflection " + reflection + " must have inverse."; | ||
@@ -83,4 +81,4 @@ state = { | ||
| ...state, | ||
| queuedReflectionChanges: [] | ||
| } | ||
| queuedReflectionChanges: [], | ||
| }; | ||
| } | ||
@@ -99,7 +97,7 @@ | ||
| if(afterUpdate && !inverseReflection) { | ||
| if (afterUpdate && !inverseReflection) { | ||
| this.setState({ updating: false }); | ||
| this.assignChanges(); | ||
| } else { | ||
| if(afterUpdateRoot && inverseReflection && queuedReflectionChanges[0] === this) { | ||
| if (afterUpdateRoot && inverseReflection && queuedReflectionChanges[0] === this) { | ||
| shiftReflectionQueue(); | ||
@@ -112,3 +110,3 @@ this.assignChanges(); | ||
| componentDidCatch(error) { | ||
| return <p>{ error }</p>; | ||
| return <p>{error}</p>; | ||
| } | ||
@@ -120,7 +118,7 @@ | ||
| if(inverseReflection) { | ||
| if (inverseReflection) { | ||
| var oldTarget = resource.association(inverseReflection.name).target; | ||
| var newTarget = newResource.association(inverseReflection.name).target; | ||
| if(inverseReflection.collection()) { | ||
| if (inverseReflection.collection()) { | ||
| // FIXME: Allow autosave inverseOf collection to appropriately handle multiple resources in the collection, | ||
@@ -143,3 +141,3 @@ // not just the first. If changing multiple fields of resource quickly, root may not be found in oldTarget | ||
| if(_.keys(queuedChanges).length == 0) return; | ||
| if (_.keys(queuedChanges).length == 0) return; | ||
@@ -157,24 +155,27 @@ var newResource = resource.assignAttributes(queuedChanges); | ||
| this.setState({ | ||
| queuedChanges: { | ||
| ...queuedChanges, | ||
| ...change | ||
| } | ||
| }, () => { | ||
| const { afterUpdateRoot, queueReflectionChange, updatingRoot } = this.context; | ||
| this.setState( | ||
| { | ||
| queuedChanges: { | ||
| ...queuedChanges, | ||
| ...change, | ||
| }, | ||
| }, | ||
| () => { | ||
| const { afterUpdateRoot, queueReflectionChange, updatingRoot } = this.context; | ||
| if(afterUpdate || afterUpdateRoot) { | ||
| if(inverseReflection) { | ||
| if(updatingRoot) { | ||
| queueReflectionChange(this); | ||
| if (afterUpdate || afterUpdateRoot) { | ||
| if (inverseReflection) { | ||
| if (updatingRoot) { | ||
| queueReflectionChange(this); | ||
| } else { | ||
| this.assignChanges(); | ||
| } | ||
| } else { | ||
| this.assignChanges(); | ||
| if (!updating) this.assignChanges(); | ||
| } | ||
| } else { | ||
| if(!updating) this.assignChanges(); | ||
| this.assignChanges(); | ||
| } | ||
| } else { | ||
| this.assignChanges(); | ||
| } | ||
| }); | ||
| ); | ||
| } | ||
@@ -218,3 +219,3 @@ | ||
| handleSubmit(e, callback) { | ||
| if(e) e.preventDefault(); | ||
| if (e) e.preventDefault(); | ||
@@ -225,7 +226,7 @@ const { onSubmit, onInvalidSubmit } = this.props; | ||
| var onSubmitCallback = (resourceToSubmit) => { | ||
| if(!_.isUndefined(onSubmit)) { | ||
| if (!_.isUndefined(onSubmit)) { | ||
| onSubmit(resourceToSubmit); | ||
| } | ||
| if(!_.isUndefined(callback)) { | ||
| if (!_.isUndefined(callback)) { | ||
| callback(resourceToSubmit); | ||
@@ -236,7 +237,7 @@ } | ||
| var onInvalidSubmitCallback = (invalidResource) => { | ||
| if(!_.isUndefined(onInvalidSubmit)) { | ||
| if (!_.isUndefined(onInvalidSubmit)) { | ||
| onInvalidSubmit(invalidResource); | ||
| } | ||
| if(!_.isUndefined(callback)) { | ||
| if (!_.isUndefined(callback)) { | ||
| callback(invalidResource); | ||
@@ -247,3 +248,3 @@ } | ||
| let beforeSubmit = this.beforeSubmit || (this.componentRef && this.componentRef.beforeSubmit); | ||
| if(!_.isUndefined(beforeSubmit)) { | ||
| if (!_.isUndefined(beforeSubmit)) { | ||
| new Promise((resolve, reject) => { | ||
@@ -253,6 +254,8 @@ try { | ||
| resolve(result); | ||
| } catch(invalid) { | ||
| } catch (invalid) { | ||
| reject(invalid); | ||
| } | ||
| }).then(onSubmitCallback).catch(onInvalidSubmitCallback) | ||
| }) | ||
| .then(onSubmitCallback) | ||
| .catch(onInvalidSubmitCallback); | ||
| } else { | ||
@@ -269,3 +272,3 @@ onSubmitCallback(resource); | ||
| let body; | ||
| if(component) { | ||
| if (component) { | ||
| body = React.createElement(component, { | ||
@@ -277,3 +280,6 @@ ...componentProps, | ||
| subject: resource, | ||
| ref: (c) => { this.componentRef = c; componentRef(c) } | ||
| ref: (c) => { | ||
| this.componentRef = c; | ||
| componentRef(c); | ||
| }, | ||
| }); | ||
@@ -284,10 +290,10 @@ } else { | ||
| if(isNestedResource) { | ||
| if (isNestedResource) { | ||
| return <section className={className}>{body}</section>; | ||
| } else { | ||
| return ( | ||
| <section className={ className }> | ||
| { body } | ||
| </section> | ||
| <form className={className} onSubmit={this.handleSubmit}> | ||
| {body} | ||
| </form> | ||
| ); | ||
| } else { | ||
| return <form className={className} onSubmit={ this.handleSubmit }>{ body }</form>; | ||
| } | ||
@@ -302,7 +308,7 @@ } | ||
| if(afterUpdate) { | ||
| if (afterUpdate) { | ||
| afterUpdate(newRoot, resource); | ||
| this.setState({ updating: true }) | ||
| this.setState({ updating: true }); | ||
| } | ||
| } | ||
| } |
23499
0.75%6
-60%688
-0.15%- Removed
- Removed