make PartCreator a bit more testable by not asking for deps of dep
parent
419c800167
commit
9bfba9db3e
|
@ -26,7 +26,7 @@ import {htmlSerializeIfNeeded, textSerialize} from '../../../editor/serialize';
|
|||
import {findEditableEvent} from '../../../utils/EventUtils';
|
||||
import {parseEvent} from '../../../editor/deserialize';
|
||||
import Autocomplete from '../rooms/Autocomplete';
|
||||
import {PartCreator} from '../../../editor/parts';
|
||||
import {PartCreator, autoCompleteCreator} from '../../../editor/parts';
|
||||
import {renderModel} from '../../../editor/render';
|
||||
import EditorStateTransfer from '../../../utils/EditorStateTransfer';
|
||||
import {MatrixClient} from 'matrix-js-sdk';
|
||||
|
@ -303,8 +303,7 @@ export default class MessageEditor extends React.Component {
|
|||
const {editState} = this.props;
|
||||
const room = this._getRoom();
|
||||
const partCreator = new PartCreator(
|
||||
() => this._autocompleteRef,
|
||||
query => this.setState({query}),
|
||||
autoCompleteCreator(() => this._autocompleteRef, query => this.setState({query})),
|
||||
room,
|
||||
this.context.matrixClient,
|
||||
);
|
||||
|
|
|
@ -117,7 +117,8 @@ class BasePart {
|
|||
}
|
||||
}
|
||||
|
||||
class PlainPart extends BasePart {
|
||||
// exported for unit tests, should otherwise only be used through PartCreator
|
||||
export class PlainPart extends BasePart {
|
||||
acceptsInsertion(chr) {
|
||||
return chr !== "@" && chr !== "#" && chr !== ":" && chr !== "\n";
|
||||
}
|
||||
|
@ -348,18 +349,24 @@ class PillCandidatePart extends PlainPart {
|
|||
}
|
||||
}
|
||||
|
||||
export class PartCreator {
|
||||
constructor(getAutocompleterComponent, updateQuery, room, client) {
|
||||
this._room = room;
|
||||
this._client = client;
|
||||
this._autoCompleteCreator = (updateCallback) => {
|
||||
export function autoCompleteCreator(updateQuery, getAutocompleterComponent) {
|
||||
return (partCreator) => {
|
||||
return (updateCallback) => {
|
||||
return new AutocompleteWrapperModel(
|
||||
updateCallback,
|
||||
getAutocompleterComponent,
|
||||
updateQuery,
|
||||
this,
|
||||
partCreator,
|
||||
);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export class PartCreator {
|
||||
constructor(autoCompleteCreator, room, client) {
|
||||
this._room = room;
|
||||
this._client = client;
|
||||
this._autoCompleteCreator = autoCompleteCreator(this);
|
||||
}
|
||||
|
||||
createPartForInput(input) {
|
||||
|
|
Loading…
Reference in New Issue