Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] .isInitialized() instead of making developers figure out that they must use internal .el variable? #2407

Open
hchiam opened this issue Nov 11, 2024 · 1 comment

Comments

@hchiam
Copy link

hchiam commented Nov 11, 2024

Is your feature request related to a problem? Please describe.
I found it unclear how to tell whether my object is initialized or not and only recently found that checking whether the object has mySortableObject?.el works, as opposed only checking if mySortableObject exists.

Describe the solution you'd like
Maybe some named helper function with a name like .isInitialized() or isUsingSortable()?

Describe alternatives you've considered
Otherwise it might be helpful to document that doing mySortableObject?.el is a better check than only mySortableObject (besides it being reported in this issue itself).

Additional context

let mySortableObject = null;
/* ... */
if (isUsingSortable()) {
  mySortableObject.destroy();
} else {
  mySortableObject = new Sortable(element, options);
}

function isUsingSortable() {
  return mySortableObject?.el;
}
@hchiam
Copy link
Author

hchiam commented Nov 11, 2024

I only thought of this because I was getting an error about this.el being null when I had code trying to run mySortableObject.destroy(); twice because the logic was treating isInitialized = mySortableObject as the check, when really it should be isInitialized = mySortableObject.el, but this.el looks like an internal variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant