From 66bcd41575c0d26b0d94fef4150bc292d2320530 Mon Sep 17 00:00:00 2001 From: Bendwarn Date: Thu, 13 Jan 2022 14:50:42 +0800 Subject: [PATCH 1/2] feat(directive): use argument to receive options --- src/directives/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/directives/index.ts b/src/directives/index.ts index 7b425cb..a02b121 100644 --- a/src/directives/index.ts +++ b/src/directives/index.ts @@ -23,6 +23,7 @@ export const drag = () => { const controller = useDrag(binding.value, { domTarget: el, manual: true, + ...binding.arg as {} }) controller.bind() @@ -53,6 +54,7 @@ export const move = () => { const controller = useMove(binding.value, { domTarget: el, manual: true, + ...binding.arg as {} }) controller.bind() @@ -83,6 +85,7 @@ export const hover = () => { const controller = useHover(binding.value, { domTarget: el, manual: true, + ...binding.arg as {} }) controller.bind() @@ -113,6 +116,7 @@ export const pinch = () => { const controller = usePinch(binding.value, { domTarget: el, manual: true, + ...binding.arg as {} }) controller.bind() @@ -143,6 +147,7 @@ export const wheel = () => { const controller = useWheel(binding.value, { domTarget: el, manual: true, + ...binding.arg as {} }) controller.bind() @@ -173,6 +178,7 @@ export const scroll = () => { const controller = useScroll(binding.value, { domTarget: el, manual: true, + ...binding.arg as {} }) controller.bind() From 15f372ae118c8c0034682029153fefcfd7fc46d2 Mon Sep 17 00:00:00 2001 From: Bendwarn Date: Wed, 1 Jun 2022 16:56:42 +0800 Subject: [PATCH 2/2] feat(directive): pass object if option needed --- src/directives/index.ts | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/directives/index.ts b/src/directives/index.ts index a02b121..46ca9d9 100644 --- a/src/directives/index.ts +++ b/src/directives/index.ts @@ -20,10 +20,12 @@ export const drag = () => { el.gestures = {} } - const controller = useDrag(binding.value, { + const config = binding.value.config ?? {} + const handler = binding.value.handler ?? binding.value + const controller = useDrag(handler, { domTarget: el, manual: true, - ...binding.arg as {} + ...config, }) controller.bind() @@ -31,7 +33,7 @@ export const drag = () => { el.gestures.drag = controller } - const unregister: DirectiveHook = (el, binding, node) => { + const unregister: DirectiveHook = (el) => { if (!el.gestures || !el.gestures.drag) return el.gestures.drag.clean() @@ -51,10 +53,12 @@ export const move = () => { el.gestures = {} } - const controller = useMove(binding.value, { + const config = binding.value.config ?? {} + const handler = binding.value.handler ?? binding.value + const controller = useMove(handler, { domTarget: el, manual: true, - ...binding.arg as {} + ...config, }) controller.bind() @@ -82,10 +86,12 @@ export const hover = () => { el.gestures = {} } - const controller = useHover(binding.value, { + const config = binding.value.config ?? {} + const handler = binding.value.handler ?? binding.value + const controller = useHover(handler, { domTarget: el, manual: true, - ...binding.arg as {} + ...config, }) controller.bind() @@ -113,10 +119,12 @@ export const pinch = () => { el.gestures = {} } - const controller = usePinch(binding.value, { + const config = binding.value.config ?? {} + const handler = binding.value.handler ?? binding.value + const controller = usePinch(handler, { domTarget: el, manual: true, - ...binding.arg as {} + ...config, }) controller.bind() @@ -144,10 +152,12 @@ export const wheel = () => { el.gestures = {} } - const controller = useWheel(binding.value, { + const config = binding.value.config ?? {} + const handler = binding.value.handler ?? binding.value + const controller = useWheel(handler, { domTarget: el, manual: true, - ...binding.arg as {} + ...config, }) controller.bind() @@ -175,10 +185,12 @@ export const scroll = () => { el.gestures = {} } - const controller = useScroll(binding.value, { + const config = binding.value.config ?? {} + const handler = binding.value.handler ?? binding.value + const controller = useScroll(handler, { domTarget: el, manual: true, - ...binding.arg as {} + ...config, }) controller.bind()