UNPKG

@modern-js-reduck/store

Version:

The meta-framework suite designed from scratch for frontend-focused modern web development.

22 lines (21 loc) 694 B
export const createPluginCore = (pluginContext) => { const lifeCycleList = []; const findHandlers = (stage) => lifeCycleList.map((liftCycle) => liftCycle[stage]).filter(Boolean); return { usePlugin: (plugin) => { lifeCycleList.push(plugin(pluginContext)); }, invokePipeline: (stage, bypassParams, ...args) => { const handlers = findHandlers(stage); let params = bypassParams; for (const handler of handlers) { params = handler(params, ...args); } return params; }, invokeWaterFall: (stage, ...args) => { const handlers = findHandlers(stage); return handlers.forEach((handler) => handler(...args)); } }; };