Skip to content

Commit

Permalink
Fixed alias with name-less components
Browse files Browse the repository at this point in the history
  • Loading branch information
Accudio committed Oct 2, 2022
1 parent fda8ff8 commit a559ad7
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
5 changes: 4 additions & 1 deletion dist/async-alpine.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var visible = (component, requirement) => {
var visible_default = visible;

// src/core/async-alpine.js
var internalNamePrefix = "__internal_";
var AsyncAlpine = {
Alpine: null,
_options: {
Expand Down Expand Up @@ -187,6 +188,8 @@ var AsyncAlpine = {
});
},
async _download(name) {
if (name.startsWith(internalNamePrefix))
return;
this._handleAlias(name);
if (!this._data[name] || this._data[name].loaded)
return;
Expand Down Expand Up @@ -243,7 +246,7 @@ var AsyncAlpine = {
},
_parseName(attribute) {
const parsedName = (attribute || "").split(/[({]/g)[0];
const ourName = parsedName || "_a-" + this._index;
const ourName = parsedName || `${internalNamePrefix}${this._index}`;
return ourName;
}
};
5 changes: 4 additions & 1 deletion dist/async-alpine.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var visible = (component, requirement) => {
var visible_default = visible;

// src/core/async-alpine.js
var internalNamePrefix = "__internal_";
var AsyncAlpine = {
Alpine: null,
_options: {
Expand Down Expand Up @@ -174,6 +175,8 @@ var AsyncAlpine = {
});
},
async _download(name) {
if (name.startsWith(internalNamePrefix))
return;
this._handleAlias(name);
if (!this._data[name] || this._data[name].loaded)
return;
Expand Down Expand Up @@ -230,7 +233,7 @@ var AsyncAlpine = {
},
_parseName(attribute) {
const parsedName = (attribute || "").split(/[({]/g)[0];
const ourName = parsedName || "_a-" + this._index;
const ourName = parsedName || `${internalNamePrefix}${this._index}`;
return ourName;
}
};
Expand Down
2 changes: 1 addition & 1 deletion dist/async-alpine.script.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "async-alpine",
"version": "0.5.2",
"description": "Load Alpine Componenets asyncronously. Allows for code splitting and lazy loading components!",
"version": "0.5.3",
"description": "Load Alpine Componenets asynchronously. Allows for code splitting and lazy loading components!",
"author": "Alistair Shepherd <[email protected]>",
"license": "Apache-2.0",
"keywords": [],
Expand Down
5 changes: 4 additions & 1 deletion src/core/async-alpine.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as strategies from './strategies/index.js';

const internalNamePrefix = '__internal_';

const AsyncAlpine = {
Alpine: null,

Expand Down Expand Up @@ -200,6 +202,7 @@ const AsyncAlpine = {
*/
// check if the component has been downloaded, if not trigger download and register with Alpine
async _download(name) {
if (name.startsWith(internalNamePrefix)) return;
this._handleAlias(name);
if (!this._data[name] || this._data[name].loaded) return;
const module = await this._getModule(name);
Expand Down Expand Up @@ -302,7 +305,7 @@ const AsyncAlpine = {
// take x-data content to parse out name 'output("test")' becomes 'output'
_parseName(attribute) {
const parsedName = (attribute || '').split(/[({]/g)[0];
const ourName = parsedName || '_a-' + this._index;
const ourName = parsedName || `${internalNamePrefix}${this._index}`;
return ourName;
},
};
Expand Down
1 change: 1 addition & 0 deletions tests/inline-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import Alpine from 'https://cdn.skypack.dev/alpinejs';
import AsyncAlpine from '/dist/async-alpine.esm.js';
AsyncAlpine.init(Alpine)
AsyncAlpine.alias('/components/[name].js')
AsyncAlpine.start()
Alpine.start()
</script>
Expand Down

0 comments on commit a559ad7

Please sign in to comment.