mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 01:43:28 +08:00
DEV: reduces duplication with curryComponent (#31073)
curryComponent allows us to pass an object as splatted arguments.
This commit is contained in:
parent
76ade65a26
commit
8d38929a67
@ -3,7 +3,9 @@ import { tracked } from "@glimmer/tracking";
|
||||
import { array, hash } from "@ember/helper";
|
||||
import { on } from "@ember/modifier";
|
||||
import { action } from "@ember/object";
|
||||
import { getOwner } from "@ember/owner";
|
||||
import { service } from "@ember/service";
|
||||
import curryComponent from "ember-curry-component";
|
||||
import DButton from "discourse/components/d-button";
|
||||
import FKAlert from "discourse/form-kit/components/fk/alert";
|
||||
import FKCheckboxGroup from "discourse/form-kit/components/fk/checkbox-group";
|
||||
@ -88,6 +90,27 @@ class FKForm extends Component {
|
||||
return validateOn;
|
||||
}
|
||||
|
||||
@action
|
||||
componentFor(klass) {
|
||||
const instance = this;
|
||||
const baseArguments = {
|
||||
get errors() {
|
||||
return instance.formData.errors;
|
||||
},
|
||||
get data() {
|
||||
return instance.formData;
|
||||
},
|
||||
addError: instance.addError,
|
||||
set: instance.set,
|
||||
registerField: instance.registerField,
|
||||
unregisterField: instance.unregisterField,
|
||||
triggerRevalidationFor: instance.triggerRevalidationFor,
|
||||
remove: instance.remove,
|
||||
};
|
||||
|
||||
return curryComponent(klass, baseArguments, getOwner(this));
|
||||
}
|
||||
|
||||
@action
|
||||
addError(name, { title, message }) {
|
||||
this.formData.addError(name, {
|
||||
@ -269,60 +292,11 @@ class FKForm extends Component {
|
||||
class="form-kit__button"
|
||||
label="form_kit.reset"
|
||||
)
|
||||
Field=(component
|
||||
FKField
|
||||
errors=this.formData.errors
|
||||
addError=this.addError
|
||||
data=this.formData
|
||||
set=this.set
|
||||
registerField=this.registerField
|
||||
unregisterField=this.unregisterField
|
||||
triggerRevalidationFor=this.triggerRevalidationFor
|
||||
)
|
||||
Collection=(component
|
||||
FKCollection
|
||||
errors=this.formData.errors
|
||||
addError=this.addError
|
||||
data=this.formData
|
||||
set=this.set
|
||||
remove=this.remove
|
||||
registerField=this.registerField
|
||||
unregisterField=this.unregisterField
|
||||
triggerRevalidationFor=this.triggerRevalidationFor
|
||||
)
|
||||
Object=(component
|
||||
FKObject
|
||||
errors=this.formData.errors
|
||||
addError=this.addError
|
||||
data=this.formData
|
||||
set=this.set
|
||||
registerField=this.registerField
|
||||
unregisterField=this.unregisterField
|
||||
triggerRevalidationFor=this.triggerRevalidationFor
|
||||
remove=this.remove
|
||||
)
|
||||
InputGroup=(component
|
||||
FKInputGroup
|
||||
errors=this.formData.errors
|
||||
addError=this.addError
|
||||
data=this.formData
|
||||
set=this.set
|
||||
remove=this.remove
|
||||
registerField=this.registerField
|
||||
unregisterField=this.unregisterField
|
||||
triggerRevalidationFor=this.triggerRevalidationFor
|
||||
)
|
||||
CheckboxGroup=(component
|
||||
FKCheckboxGroup
|
||||
errors=this.formData.errors
|
||||
addError=this.addError
|
||||
data=this.formData
|
||||
set=this.set
|
||||
remove=this.remove
|
||||
registerField=this.registerField
|
||||
unregisterField=this.unregisterField
|
||||
triggerRevalidationFor=this.triggerRevalidationFor
|
||||
)
|
||||
Field=(this.componentFor FKField)
|
||||
Collection=(this.componentFor FKCollection)
|
||||
Object=(this.componentFor FKObject)
|
||||
InputGroup=(this.componentFor FKInputGroup)
|
||||
CheckboxGroup=(this.componentFor FKCheckboxGroup)
|
||||
set=this.set
|
||||
setProperties=this.setProperties
|
||||
addItemToCollection=this.addItemToCollection
|
||||
|
Loading…
x
Reference in New Issue
Block a user