mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-03-17 17:10:03 +01:00
Use existing event delegation with submit
subscription for history tracking
This commit is contained in:
parent
c15e082b97
commit
3c2a3e956a
1 changed files with 9 additions and 13 deletions
|
@ -2,6 +2,7 @@ import { HistorySuggestion } from '../../utils/suggestions';
|
||||||
import { InputHistory } from './history';
|
import { InputHistory } from './history';
|
||||||
import { HistoryStore } from './store';
|
import { HistoryStore } from './store';
|
||||||
import { AutocompletableInput } from '../input';
|
import { AutocompletableInput } from '../input';
|
||||||
|
import { delegate } from 'utils/events';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores a set of histories identified by their unique IDs.
|
* Stores a set of histories identified by their unique IDs.
|
||||||
|
@ -38,20 +39,15 @@ export function listen() {
|
||||||
histories.load(input.historyId);
|
histories.load(input.historyId);
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener('submit', event => {
|
delegate(document, 'submit', {
|
||||||
if (!(event.target instanceof HTMLFormElement)) {
|
'[data-autocomplete-history-id]'(_event, target) {
|
||||||
return;
|
const input = AutocompletableInput.fromElement(target);
|
||||||
}
|
if (!input || !input.hasHistory()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const input = [...event.target.elements]
|
histories.load(input.historyId).write(input.snapshot.trimmedValue);
|
||||||
.map(elem => AutocompletableInput.fromElement(elem))
|
},
|
||||||
.find(it => it !== null && it.hasHistory());
|
|
||||||
|
|
||||||
if (!input) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
histories.load(input.historyId).write(input.snapshot.trimmedValue);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue