UNPKG

ractive-state-router

Version:

A RactiveJS-based rendering layer for the abstract-state-router

23 lines (19 loc) 553 B
module.exports = function makeStateIsActiveDecorator(stateRouter) { return function activeDecorator(node, stateName, options, className = `active`) { function applyCurrentState() { if (stateRouter.stateIsActive(stateName, options)) { node.classList.add(className) } else { node.classList.remove(className) } } stateRouter.on(`stateChangeEnd`, applyCurrentState) function teardown() { stateRouter.removeListener(`stateChangeEnd`, applyCurrentState) node.classList.remove(className) } return { teardown, } } }