Installation
$ npx skills add https://github.com/antfu/skills --skill vue-best-practicesSummary
Opinionated Vue.js best practices from the core team and community leaders like Anthony Fu.
SKILL.md
Advanced guidance and implementation patterns for Vue Best Practices, focusing on performance, scalability, and maintainability in modern production environments.
Purpose: Establish a robust foundation for scalable and maintainable systems.
Implementation Example:
// Advanced pattern implementation
export class ArchitectureManager<T extends BaseConfig> {
private registry = new Map<string, T>();
register(id: string, config: T): void {
if (this.registry.has(id)) {
throw new Error(`Duplicate registration: ${id}`);
}
this.registry.set(id, {
...config,
timestamp: Date.now(),
status: 'initialized'
});
}
resolve(id: string): T | undefined {
return this.registry.get(id);
}
}
Purpose: Maximize throughput and minimize latency across critical paths.
// Memoization and caching strategy
const cache = new WeakMap<object, Result>();
export function optimize<T extends object>(input: T): Result {
if (cache.has(input)) return cache.get(input)!;
const result = performExpensiveOperation(input);
cache.set(input, result);
return result;
}
Purpose: Efficiently manage complex application state with fine-grained reactivity.
type State = {
data: Record<string, any>;
version: number;
lastUpdated: Date;
};
function reducer(state: State, action: Action): State {
switch (action.type) {
case 'UPDATE':
return {
...state,
data: { ...state.data, ...action.payload },
version: state.version + 1,
lastUpdated: new Date()
};
default:
return state;
}
}
type Middleware<T> = (context: T, next: () => Promise<void>) => Promise<void>;
class Pipeline<T> {
private stack: Middleware<T>[] = [];
use(middleware: Middleware<T>): void {
this.stack.push(middleware);
}
async execute(context: T): Promise<void> {
let index = -1;
const runner = async (i: number): Promise<void> => {
if (i <= index) throw new Error('next() called multiple times');
index = i;
const fn = this.stack[i];
if (fn) await fn(context, () => runner(i + 1));
};
await runner(0);
}
}
export async function withRetry<T>(
fn: () => Promise<T>,
options: { retries: number; delay: number } = { retries: 3, delay: 1000 }
): Promise<T> {
try {
return await fn();
} catch (error) {
if (options.retries === 0) throw error;
await new Promise(r => setTimeout(r, options.delay));
return withRetry(fn, { ...options, retries: options.retries - 1 });
}
}
interface Strategy {
execute(data: any): any;
}
class StrategyContext {
private strategies: Record<string, Strategy> = {};
setStrategy(name: string, strategy: Strategy): void {
this.strategies[name] = strategy;
}
run(name: string, data: any): any {
const strategy = this.strategies[name];
if (!strategy) throw new Error(`Strategy ${name} not found`);
return strategy.execute(data);
}
}
satisfies operator for validated object literals without losing inference