-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔨 refactor(index.js): refactor VueFootprintsMixin and useFootprints f…
…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
1 parent
e3dd71b
commit aa496f2
Showing
6 changed files
with
77 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
}, | ||
}); | ||
}, | ||
}; |