Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | 2x 2x 9x 9x 28x 9x 11x 19x 13x 19x 12x 75x 75x 75x 75x 30x | /* * Next Avenues * * (c) Samuel Joos * * Based on the work of * (c) Harminder Virk <virk@adonisjs.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * Route store is used to store registered routes as an * array. It is a singleton store to be exported and * used by an part of the application to store * routes. * * * @class RouteStore * @static */ class Store { constructor() { this._routes = []; this.releaseBreakpoint(); } /** * @description * Add a breakpoint to routes. All routes after the * breakpoint will be recorded seperately. Helpful * for @ref(Route/group). * * Also only one breakpoint at a time is allowed. * * @function breakpoint * * @param {string} name Breakpoint name. */ breakpoint(name = null) { this._breakpoint.enabled = true; this._breakpoint.name = name; } /** * @description * Returns a boolean indicating whether breakpoint * is enabled or not. * * @function hasBreakpoint * * @returns {boolean} */ hasBreakpoint() { return this._breakpoint.enabled; } /** * @description * Returns the routes recorded during * breakpoint. * * @function breakpointRoutes * * @returns {Array} */ breakpointRoutes() { return this._breakpoint.routes; } /** * @description * Release the breakpoint. * * @function releaseBreakpoint */ releaseBreakpoint() { this._breakpoint = { enabled: false, routes: [], name: null }; } /** * @description * Add a route to the store. * This function is used by [Router.add](https://github.com/samueljoos/next-avenues/blob/master/docs/router.md#routeraddroute-page) * Also see [Route](https://github.com/samueljoos/next-avenues/blob/master/docs/route.md) * * @function add * * @param {Route} route Route instance. */ add(route) { if (this.hasBreakpoint()) { this._breakpoint.routes.push(route); } this._routes.push(route); } /** * @description * Remove route from the store. * * @function remove * * @param {Route} routeToRemove Route instance. */ remove(routeToRemove) { const removeCallback = (route, index) => { if (route === routeToRemove) { delete this._routes[index]; } }; this._routes.forEach(removeCallback); if (this.hasBreakpoint()) { this._breakpoint.routes.forEach(removeCallback); } } /** * @description * Clear all the routes store so far. * * @function clear */ clear() { this._routes = []; } /** * @description * Find a route with name or it's url * * @function find * * @param {string} routeNameOrHandler Route name or path template. * @param {string} domain For domain matching not used for subdomain matching. * * @returns {Object|Null} */ find(routeNameOrHandler, domain) { return this._routes.find(route => { const isName = route.name === routeNameOrHandler; const isRoute = route._route === routeNameOrHandler; const isDomain = route._domain === domain; return (route._domain && route.domainKeys.length === 0) ? isDomain && (isName || isRoute) : (isName || isRoute); }); } /** * @description * Returns a list of stored routes. * * @function list * * @returns {Array} */ list() { return this._routes; } } export default new Store(); |