vue3-dnd
Version:
Drag and Drop for Vue Composition API
24 lines (23 loc) • 1.05 kB
JavaScript
import { reactive, set, unref, watchEffect } from "vue-demi";
import equal from "fast-deep-equal";
export function useConnector(callback, defaultOptions) {
var _state = reactive({
el: null,
options: unref(defaultOptions)
});
watchEffect(function() {
callback(_state);
}, {
flush: "post"
});
var connector = function(element, options) {
set(_state, "el", element);
// Because of the special nature of vue, when it calls setRef, it will pass in two parameters. Therefore, when we pass connect as a setRef function, we may receive a non-ideal options. For this reason, we assume that when there are options in the spec, The options passed in by Connect are no longer adopted to ensure that the options of spec always take precedence over the options of connect
var _options = unref(defaultOptions) || options;
if (!equal(_state.options, _options)) {
set(_state, "options", _options);
}
return unref(element);
};
return connector;
}