motion-v
Version:
<p align="center"> <img width="100" height="100" alt="Motion logo" src="https://user-images.githubusercontent.com/7850794/164965523-3eced4c4-6020-467e-acde-f11b7900ad62.png" /> </p> <h1 align="center">Motion for Vue</h1>
53 lines (52 loc) • 1.49 kB
JavaScript
import { watch } from "vue";
class FeatureManager {
constructor(state) {
this.features = [];
const { features = [], lazyMotionContext } = state.options;
const allFeatures = features.concat(lazyMotionContext.features.value);
this.features = allFeatures.map((Feature) => new Feature(state));
const featureInstances = this.features;
watch(lazyMotionContext.features, (features2) => {
features2.forEach((feature) => {
if (!allFeatures.includes(feature)) {
allFeatures.push(feature);
const featureInstance = new feature(state);
featureInstances.push(featureInstance);
if (state.isMounted()) {
featureInstance.beforeMount();
featureInstance.mount();
}
}
});
}, {
flush: "pre"
});
}
mount() {
this.features.forEach((feature) => feature.mount());
}
beforeMount() {
this.features.forEach((feature) => {
var _a;
return (_a = feature.beforeMount) == null ? void 0 : _a.call(feature);
});
}
unmount() {
this.features.forEach((feature) => feature.unmount());
}
update() {
this.features.forEach((feature) => {
var _a;
return (_a = feature.update) == null ? void 0 : _a.call(feature);
});
}
beforeUpdate() {
this.features.forEach((feature) => feature.beforeUpdate());
}
beforeUnmount() {
this.features.forEach((feature) => feature.beforeUnmount());
}
}
export {
FeatureManager
};