Custom
The doc for options in the readme describes 3 return values for onMove corresponding to the special behaviors (false, 1 and -1): https://github.com/SortableJS/Sortable/tree/88838bfa5647e278f4cf87fdd4c3e34cd24fb33c#options
Reading the source code at
|
after = direction === 1; |
|
|
|
let moveVector = onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, after); |
|
|
|
if (moveVector !== false) { |
|
if (moveVector === 1 || moveVector === -1) { |
|
after = (moveVector === 1); |
|
} |
tells me that there is a 4th behavior: for any other returned value (for instance when you don't return anything), the library manages the insertion position automatically based on the direction (exactly as done when you don't specify a
onMove callback).
I opened a PR at DefinitelyTyped/DefinitelyTyped#45684 to update the type definitions to change the return type to false | 1 | -1 | void, to account for this behavior (so that the typechecker does not complain when returning nothing). but the maintainers answered saying they prefer to stick to the documented API.
Is this behavior when returning nothing an official one ? Suggested answers for preventing the move to certain positions without forcing the insertion side are relying on this, either returning nothing or returning true depending on the snippets (see #1019 and #1500 for such examples).
What should be the official signature for this callback ?
false | 1 | -1 (current type definition, preventing this behavior)
false | 1 | -1 | void allowing to return nothing to keep the automatic insertion position based on the direction
boolean | 1 | -1 | void allowing to return either true or nothing to keep the automatic insertion position
Based on the decision, it would be great to update the readme to reflect that in the doc (I can submit a PR once I know which variant the maintainers want)
Custom
The doc for options in the readme describes 3 return values for
onMovecorresponding to the special behaviors (false,1and-1): https://github.com/SortableJS/Sortable/tree/88838bfa5647e278f4cf87fdd4c3e34cd24fb33c#optionsReading the source code at
Sortable/src/Sortable.js
Lines 1247 to 1254 in 88838bf
onMovecallback).I opened a PR at DefinitelyTyped/DefinitelyTyped#45684 to update the type definitions to change the return type to
false | 1 | -1 | void, to account for this behavior (so that the typechecker does not complain when returning nothing). but the maintainers answered saying they prefer to stick to the documented API.Is this behavior when returning nothing an official one ? Suggested answers for preventing the move to certain positions without forcing the insertion side are relying on this, either returning nothing or returning
truedepending on the snippets (see #1019 and #1500 for such examples).What should be the official signature for this callback ?
false | 1 | -1(current type definition, preventing this behavior)false | 1 | -1 | voidallowing to return nothing to keep the automatic insertion position based on the directionboolean | 1 | -1 | voidallowing to return eithertrueor nothing to keep the automatic insertion positionBased on the decision, it would be great to update the readme to reflect that in the doc (I can submit a PR once I know which variant the maintainers want)