Patternslib/Patterns

pat-sortable: Improve detection added/removed items

Opened this issue · 0 comments

thet commented

In pat-sortable we currently have some detection items which are added‌. This is done via the pat-update JavaScript event and via another event thrown by pat-inject. This covers all core-Patternslib use cases.

But this method for detecting new additions has some problems:

  • It's bound to Patternslib internals. It doesn't work if items are added from outside. We currently have a use-case in Mockup, where a svelte application is adding items to a container and these items should be sortable. We could also throw one of the events mentioned above, but this again make use of Patternslib internals and is not a generic solution which would work in any case.
  • There is currently no re-initialization on item removal.

These problems can be fixed by making use of MutationObservers which would filter for added or removed items matching the selector. We could further filter for only direct descendants of the Pattern element itself as we are doing it with the current implementation of pat-sortable.