respond-framework
Version:
create as fast you think
29 lines (26 loc) • 1.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = edit;
var _dispatchPlugins = require("../../helpers/dispatchPlugins.js");
var _before = require("./before.js");
var _reduce = require("../reduce.js");
var _debounce = require("./debounce.js");
var _end = require("../end.js");
// sync events must run before awaiting any promises for inputs to not mess up the cursor position
// note: even though this runs in an await dispatch, it's still sync, since it still happens syncronously before any awaited promises complete
function edit(state, e) {
if (!e.event.sync) return;
const {
ctx
} = state.respond;
ctx.sync = true; // prevent standard queued microtask listeners from being notified
const res = (0, _dispatchPlugins.default)(plugins, state, e);
return res instanceof Promise ? res.then(_ => ctx.sync = false) : ctx.sync = false;
}
edit.sync = true; // mark event as sync, so createPlugins can shift em to front of dispatch pipeline before potentially async events
const plugins = [_before.default, _reduce.default, state => {
state.respond.commit();
state.respond.ctx.sync = false;
}, _debounce.default, _end.default];