Skip to content

Commit

Permalink
🔨 refactor(index.js): refactor VueFootprintsMixin and useFootprints f…
Browse files Browse the repository at this point in the history
…unctions

The VueFootprintsMixin and useFootprints functions have been refactored to improve readability and maintainability. The e function has been extracted from the VueFootprintsMixin and is now used in the computed property of the useFootprints function. This change improves code reuse and reduces duplication.

🎉 feat(composables.js, core.js, index.js, mixin.js): add support for footprints
This commit adds support for footprints, which are a way to track the user's navigation history. The `useFootprints` composable is added to retrieve the footprints for a given route and options. The `getFootprints` function is added to the `core.js` file to calculate the footprints based on the matched routes and options. The `VueFootprintsMixin` is added to the `mixin.js` file to provide a global `$footprints` computed property that can be used in any component. Finally, the `index.js` file is updated to export the `VueFootprintsMixin` and `useFootprints` for use in other parts of the application.
  • Loading branch information
jofftiquez committed May 11, 2023
1 parent e3dd71b commit aa496f2
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 49 deletions.
63 changes: 36 additions & 27 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
'use strict';
"use strict";

var index = {
install: function install(app, options) {
app.mixin({
computed: {
$footprints: function $footprints() {
var _this$$route$matched,
_this = this;
return (_this$$route$matched = this.$route.matched) === null || _this$$route$matched === void 0 ? void 0 : _this$$route$matched.map(function (r) {
var _r$meta;
if (!((_r$meta = r.meta) !== null && _r$meta !== void 0 && _r$meta.footprint)) return null;
var active = _this.$route.name === r.name;
var returnRoute = options !== null && options !== void 0 && options.returnRoute ? route : {
name: r.name,
path: r.path,
meta: r.meta
};
return {
footprint: r.meta.footprint,
active: active,
route: returnRoute
};
}).filter(Boolean);
var t = require("vue");
var e = function e(t, _e) {
var _t$matched;
return (_t$matched = t.matched) === null || _t$matched === void 0 ? void 0 : _t$matched.map(function (o) {
var _o$meta;
if (!((_o$meta = o.meta) !== null && _o$meta !== void 0 && _o$meta.footprint)) return null;
var r = t.name === o.name,
n = _e !== null && _e !== void 0 && _e.returnRoute ? t : {
name: o.name,
path: o.path,
meta: o.meta
};
return {
footprint: o.meta.footprint,
active: r,
route: n
};
}).filter(Boolean);
},
o = {
install: function install(t, o) {
t.mixin({
computed: {
$footprints: function $footprints() {
return e(this.$route, o);
}
}
}
});
}
});
}
};
exports.VueFootprintsMixin = o, exports.useFootprints = function (o, r) {
return {
footprints: t.computed(function () {
return e(o, r);
})
};
};
module.exports = index;
11 changes: 11 additions & 0 deletions src/composables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getFootprints } from './core';
import { computed } from 'vue';

export const useFootprints = (route, options) => {
const footprints = computed(() => {
return getFootprints(route, options);
});
return {
footprints,
};
};
12 changes: 12 additions & 0 deletions src/core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const getFootprints = (route, options) => {
return route.matched?.map(r => {
if (!r.meta?.footprint) return null;
const active = route.name === r.name;
const returnRoute = options?.returnRoute ? route : { name: r.name, path: r.path, meta: r.meta };
return {
footprint: r.meta.footprint,
active,
route: returnRoute,
};
}).filter(Boolean);
};
Empty file added src/core.test.js
Empty file.
27 changes: 5 additions & 22 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
export default {
install: (app, options) => {
app.mixin({
computed: {
$footprints () {
return this.$route.matched?.map(r => {

if (!r.meta?.footprint) return null;
import { VueFootprintsMixin } from './mixin';
import { useFootprints } from './composables';

const active = this.$route.name === r.name;
const returnRoute = options?.returnRoute ? route : { name: r.name, path: r.path, meta: r.meta };

return {
footprint: r.meta.footprint,
active,
route: returnRoute,
};

}).filter(Boolean);
},
},
});
},
export {
VueFootprintsMixin,
useFootprints,
};
13 changes: 13 additions & 0 deletions src/mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getFootprints } from './core';

export const VueFootprintsMixin = {
install: (app, options) => {
app.mixin({
computed: {
$footprints () {
return getFootprints(this.$route, options);
},
},
});
},
};

0 comments on commit aa496f2

Please sign in to comment.