UNPKG

edge-master

Version:
37 lines (36 loc) 797 B
/** * Sets a value in the context state */ export function setState(ctx, key, value) { ctx.state.set(key, value); } /** * Gets a value from the context state */ export function getState(ctx, key) { return ctx.state.get(key); } /** * Gets a value from the context state or returns a default value */ export function getStateOr(ctx, key, defaultValue) { return ctx.state.has(key) ? ctx.state.get(key) : defaultValue; } /** * Checks if a key exists in the context state */ export function hasState(ctx, key) { return ctx.state.has(key); } /** * Deletes a value from the context state */ export function deleteState(ctx, key) { return ctx.state.delete(key); } /** * Clears all values from the context state */ export function clearState(ctx) { ctx.state.clear(); }