buttonwoodcx / bcx-aurelia-reorderable-repeat

An Aurelia repeater supports drag & drop reordering automatically.
https://buttonwoodcx.github.io/doc-bcx-aurelia-dnd/reorderable-repeat
MIT License
19 stars 5 forks source link

Plugin does not work with aurelia when using dist >= es2015 #25

Closed josundt closed 2 years ago

josundt commented 2 years ago

I have an app using aurelia 1.0 with webpack/aurelia-webpack-plugin.

The aurelia-webpack-plugin has a dist setting that lets you decide which distribution/transpiled ES target from the aurelia packages/plugins to pick when bundling.

Aurelia uses the following convention for subfolder layout in their own packages and also recommend this for plugin creators::

The aurelia-webpack-plugin dist setting lets you choose which target to include when bundling. This works for aurelia-* packages and should also work for aurelia plugins that follow the package folder layout convention.

I recently tried to change the aurelia-webpack-plugin setting from native-modules to es2017, but then the reorderable-repeat plugin failed. Everything else actually works like charm.

I found that the reason is that the reorderable-repeat plugin is only transpiled to es5, and the code also expects the aurelia AbstractRepeater to be using the prototype pattern (not es2015+ class) when the ReorderableRepeat attempts to extend it. This would not have been a problem if the ReorderableRepeat was transpiled to es2015+ with Babel.

Transpiled code from reorderable-repeat.js:

function ReorderableRepeat(ea, taskQueue, bindingEngine, dndService, viewFactory, instruction, viewSlot, viewResources, observerLocator, strategyLocator, groupMap) {
    var _this;

    // This line fails:
    _this = _AbstractRepeater.call(this, {
      local: 'item',
      viewsRequireLifecycle: (0, _aureliaTemplatingResources.viewsRequireLifecycle)(viewFactory)
    }) || this;

Proposed solution:

I would really appreciate if you could look into this. It should not be a to big effort to extend the lifespan of this useful plugin 👍

3cp commented 2 years ago

Thx for the interesting finding! This could affect some other plugins if they extend core classes.

3cp commented 2 years ago

Tested v1.5.0, works with or without dist rewrite now.

I skipped two dist folders (amd, system) because nobody needs to use them.

josundt commented 2 years ago

Tested upgrading and now everything works like charm! Thanks for the extremely low response time! 🙂 I find it heart warming whenever I witness open source projects where maintenance is taken seriously!