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 { array, hash } from "@ember/helper";
|
||||||
import { on } from "@ember/modifier";
|
import { on } from "@ember/modifier";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
|
import { getOwner } from "@ember/owner";
|
||||||
import { service } from "@ember/service";
|
import { service } from "@ember/service";
|
||||||
|
import curryComponent from "ember-curry-component";
|
||||||
import DButton from "discourse/components/d-button";
|
import DButton from "discourse/components/d-button";
|
||||||
import FKAlert from "discourse/form-kit/components/fk/alert";
|
import FKAlert from "discourse/form-kit/components/fk/alert";
|
||||||
import FKCheckboxGroup from "discourse/form-kit/components/fk/checkbox-group";
|
import FKCheckboxGroup from "discourse/form-kit/components/fk/checkbox-group";
|
||||||
@ -88,6 +90,27 @@ class FKForm extends Component {
|
|||||||
return validateOn;
|
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
|
@action
|
||||||
addError(name, { title, message }) {
|
addError(name, { title, message }) {
|
||||||
this.formData.addError(name, {
|
this.formData.addError(name, {
|
||||||
@ -269,60 +292,11 @@ class FKForm extends Component {
|
|||||||
class="form-kit__button"
|
class="form-kit__button"
|
||||||
label="form_kit.reset"
|
label="form_kit.reset"
|
||||||
)
|
)
|
||||||
Field=(component
|
Field=(this.componentFor FKField)
|
||||||
FKField
|
Collection=(this.componentFor FKCollection)
|
||||||
errors=this.formData.errors
|
Object=(this.componentFor FKObject)
|
||||||
addError=this.addError
|
InputGroup=(this.componentFor FKInputGroup)
|
||||||
data=this.formData
|
CheckboxGroup=(this.componentFor FKCheckboxGroup)
|
||||||
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
|
|
||||||
)
|
|
||||||
set=this.set
|
set=this.set
|
||||||
setProperties=this.setProperties
|
setProperties=this.setProperties
|
||||||
addItemToCollection=this.addItemToCollection
|
addItemToCollection=this.addItemToCollection
|
||||||
|
Loading…
x
Reference in New Issue
Block a user