motion-v
Version:
<h1 align="center"> <img width="35" height="35" alt="Motion logo" src="https://github.com/user-attachments/assets/00d6d1c3-72c4-4c2f-a664-69da13182ffc" /><br />Motion for Vue</h1>
21 lines (20 loc) • 872 B
JavaScript
import { inject, provide } from "vue";
function createContext(providerComponentName, contextName) {
const symbolDescription = typeof providerComponentName === "string" && !contextName ? `${providerComponentName}Context` : contextName;
const injectionKey = Symbol(symbolDescription);
const injectContext = (fallback) => {
const context = inject(injectionKey, fallback);
if (context === void 0) throw new Error(`Injection \`${injectionKey.toString()}\` not found. Component must be used within ${Array.isArray(providerComponentName) ? `one of the following components: ${providerComponentName.join(", ")}` : `\`${providerComponentName}\``}`);
return context;
};
const provideContext = (contextValue) => {
provide(injectionKey, contextValue);
return contextValue;
};
return [
injectContext,
provideContext,
injectionKey
];
}
export { createContext };