edge-master
Version:
A Micro Framework for Edges
37 lines (36 loc) • 797 B
JavaScript
/**
* 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();
}