{"_id":"@akc42/distributed-router","_rev":"4-3fa8f404ed2115446a88b9d7a2b77826","name":"@akc42/distributed-router","dist-tags":{"latest":"1.1.2"},"versions":{"1.0.2":{"name":"@akc42/distributed-router","version":"1.0.2","description":"A Distributed Client Side Router","devDependencies":{"jest":"^26.5.2","@babel/core":"^7.11.6","@babel/preset-env":"^7.11.5","babel-jest":"^26.5.2"},"scripts":{"test":"jest"},"author":{"name":"Alan Chandler"},"license":"GPL-3.0-or-later","main":"location.js","directories":{"test":"tests"},"dependencies":{},"repository":{"type":"git","url":"git+https://github.com/akc42/distributed-router.git"},"keywords":["client","router","distributed","custom-elements"],"bugs":{"url":"https://github.com/akc42/distributed-router/issues"},"homepage":"https://github.com/akc42/distributed-router#readme","gitHead":"efdba78c520ba0b7d1cf3280838718134fa3209d","_id":"@akc42/distributed-router@1.0.2","_nodeVersion":"12.18.2","_npmVersion":"6.14.5","dist":{"integrity":"sha512-9h+rqgtbpa8kIg8FiOnatKgpUIJ0ImlUQbWUrpsB6fDz7HA+B+UlfcH4PM8TunJaGPTYmRz6XIgAjBgKd0btrg==","shasum":"cb7a1d73a9c9b69dc4306556158496dddf75fbde","tarball":"https://registry.npmjs.org/@akc42/distributed-router/-/distributed-router-1.0.2.tgz","fileCount":8,"unpackedSize":69857,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJffsxvCRA9TVsSAnZWagAAYkUQAKTp7a4DBOd2PXe5Hxx1\n6YnE+NK97ukMao3SD60pAhN5bdo0BU8telh/h+SxmrYBUlaWaN+FbV0ItZFF\nmEPXG9bIP6XSG44SQGSAZso6K8wbLALPUx1nG7TSwClGGAtPkjh5brnqNbsB\n1SvBMucxYZs/aPitnlQp/rSwCIrYlHS/4NZqDn8XdWhQP8yntXRzQh9PJXuA\nNc1INMmSLbg7rlOFt1mzIlTOnnVpu4AWpBxXzADj+WTwZqxU86M1gXDSkCbD\nWRCtAgdSgLZuMyrrNpLUXminEWCBC3j7ND14jXPfLVpA6I5d8a4DeGaLe4Od\ncQw6hrjhWEY9uLW/2cZ9YVgBLvh8KnvXgWFmUmDqScdXrYom9KBF2dnHMQ6g\nstz40P1XgsDBONJFENWPi2DR0VKND9BjCPtPANwcd2aurykj/q1lQ4NaHOl9\n3kRX2FqawS0eVYegkBWsOKsQp8zFnxYKDZAD8Nsuf97cd9PCYSSNjeMKXvkB\nEwJiJKy65xuDB+sjGdRVzCJm1ZSuUpCy6k/nDVGaXvVv+EsOqk1+ff9R0f9/\nUFMymvDHd0MQR/uPG4k82dskDluGqjhWBOhg/hiy9+X61Fp10JWQnKrYEQQy\nVnG1unXpe0jUSiQpd+aPv7T2guuclWNmbg859UO3TGJjIMwN69QPIDQwaGBU\nnLe6\r\n=xGzo\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDpQorOIJ3mJjEjdu3fdFqlb09fwkhA6Xk7v9agktSavwIhAP6jHGUpVtLMaVCfr2EofSPRT4JGkcS4fiH6cvJiXJ8s"}]},"maintainers":[{"name":"akc42","email":"alan@chandlerfamily.org.uk"}],"_npmUser":{"name":"akc42","email":"alan@chandlerfamily.org.uk"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/distributed-router_1.0.2_1602145391448_0.3159760028767551"},"_hasShrinkwrap":false},"1.1.0":{"name":"@akc42/distributed-router","version":"1.1.0","description":"A Distributed Client Side Router","devDependencies":{"jest":"^26.5.2","@babel/core":"^7.11.6","@babel/preset-env":"^7.11.5","babel-jest":"^26.5.2"},"scripts":{"test":"jest"},"author":{"name":"Alan Chandler"},"license":"GPL-3.0-or-later","main":"location.js","directories":{"test":"tests"},"dependencies":{},"repository":{"type":"git","url":"git+https://github.com/akc42/distributed-router.git"},"keywords":["client","router","distributed","custom-elements"],"bugs":{"url":"https://github.com/akc42/distributed-router/issues"},"homepage":"https://github.com/akc42/distributed-router#readme","gitHead":"d5d190363a586a671a4fff2ba95b52694b77902c","_id":"@akc42/distributed-router@1.1.0","_nodeVersion":"14.15.0","_npmVersion":"6.14.8","dist":{"integrity":"sha512-/nr4Efi2kbfshCrNtas9/CC56w/Da0F6v4H5UuCBhJ4T6KvDvJPb8W0H+okkR0tO21l0cnHnoG794xsNK8wB5Q==","shasum":"68acaf4cdaa7d747101426da71f037591a891d22","tarball":"https://registry.npmjs.org/@akc42/distributed-router/-/distributed-router-1.1.0.tgz","fileCount":8,"unpackedSize":69770,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfx64FCRA9TVsSAnZWagAAn3cP/2MlUNS1c3j1KwESmF3m\ndqWy9xxz2XMxq55BTVrCw8jfmczBIv8+J2BOD9MrWy1Pkpm47pyXXbcitJo9\nv33cvN9/QKhYvRXdcuQtt4tFWpsDPOulAJkKYiouoMZohRYgIzX7hp7fzHBz\nHGAFpVJ2XLLRDALOqqdGOguevYpdBCvzgQw8PKN2IHEDtVOFA4yisT4lxm4V\n3pCM0zh3KA27FFsqMtk5Z7FIV1rlQiuwhjzTJUjFaPba2R2bZsVH+bwU1Jjf\nK1e9NYBOzpK4MGpk5lTj7+llvQMVOwce3FkyIlU2enUftPRYEN2M6T/qHtcm\nKWWIaH3qG4XZBsYe5ZCSWx6P4dyJ2RK+apFp0N/S9JZ/XwEpXYlFfE4VloaF\nCkf4N3hekhXQRx8BD9H4knd0hIwggZpEUyqescZTiHsiRQHSj37oDo3ZvrE3\n2AKKGP30ebN8VWgxdNPHI7BAzK5bnvy37WoJL37lJ6Ig8iOf67GCANu3IbPU\nLD7uuq+qjShw09u5OsDgTjPJeGVeUK8qa9rZLkwdelT4c5GVtPL+myHl0dTu\nndFILw+p8VrD6MQF9Iq4MT0czp1mwv2AcKKweG9UuPIuh09oIWiyxZoIKQhi\ntr88HVmcLP3LDRMbSf3ygPTvvgWGBMNKtmCCXJS2Jdo78gS6EUyhDMYyFbwU\nJU0L\r\n=1Rpf\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDUD/RMiEJ2G0DY9KULql0TkMzGE2RYocmV8EmdHtEllwIhAOLpvPIRrGtwxvQgp4BM1xI2vUo5nqak9spi8WVcymH7"}]},"_npmUser":{"name":"akc42","email":"alan@chandlerfamily.org.uk"},"maintainers":[{"name":"akc42","email":"alan@chandlerfamily.org.uk"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/distributed-router_1.1.0_1606921732513_0.05678173989216395"},"_hasShrinkwrap":false},"1.1.1":{"name":"@akc42/distributed-router","version":"1.1.1","description":"A Distributed Client Side Router","devDependencies":{"jest":"^26.5.2","@babel/core":"^7.11.6","@babel/preset-env":"^7.11.5","babel-jest":"^26.5.2"},"scripts":{"test":"jest"},"author":{"name":"Alan Chandler"},"license":"GPL-3.0-or-later","main":"location.js","directories":{"test":"tests"},"dependencies":{},"repository":{"type":"git","url":"git+https://github.com/akc42/distributed-router.git"},"keywords":["client","router","distributed","custom-elements"],"bugs":{"url":"https://github.com/akc42/distributed-router/issues"},"homepage":"https://github.com/akc42/distributed-router#readme","gitHead":"6c5eed12bb871d63fce396d8e3895b2f17bd3387","_id":"@akc42/distributed-router@1.1.1","_nodeVersion":"14.16.0","_npmVersion":"6.14.11","dist":{"integrity":"sha512-+ix/oNa+5fyRdEQAgZxQ8YKgKt2h7/iPeX8up/TVbSGeAqK301Zf6UiTCB4wItybRJ7XOgm1gkUg5wOagyI4ng==","shasum":"4b1408dfe289a3dad3f9f8cca522fe2b291047e1","tarball":"https://registry.npmjs.org/@akc42/distributed-router/-/distributed-router-1.1.1.tgz","fileCount":8,"unpackedSize":69872,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgbcVQCRA9TVsSAnZWagAAvAAP/i13itgEQwF6LIpPkIwQ\noSOp1SPvqurYNMQNi6gX5L2UtAZWEiLTPXNMmQZ9TVZU+Z/hNf2JrPdwUgR3\nJ13XCLsoq1oMzWQuCh6aK4LBjoTD+cS7F8O9Q3EIua/qWkAIgV1EbLCrskhA\nBZXyPDHZRm9oMW19hGiL+hU2LABMh+SV2cAsYaVUW78oxk75W5XSy/CSGg5a\nSLthm4B6L8BaSWd2DMyTf4dkh03zbAYv9ya+hW/0MC+vlBWW6R8KVHhhvTmR\nDfQAgOzjadCruouoJklBUZndUJNZ4ioIiTDsAJLWtbzgU0M87vqOLAaItotn\nmHqEVjDRC3kOBHz1giVnFDFuKIG04axwWTdKySRKl/CnwQ57AQYUhBIX6jzC\nSvuuCv4uqL9hedmdxL8r+jhJVus3KjoG/YKnAjvzZfMYkS+0e+tmtvxsEWUf\nUdA6++nHbjQzcJG2l4vIqj3Y8oUNm7VfPvnpfvGiq+VUwKxx0p/DZc4doDlu\nDK6orluftO5MmrU/F+pfQP+bwRsUjvqyYtl1J22HqJ6VH073fSUBhm55PU+/\nNLWgJ93lie/0u4tGfxup/GB/2lSqtEX3yb4GVvlkNsDsvxwkVfVHks22eC1W\nhYdFC6jIiLEjwcScYvxeV+mzv2YLQCJR3eNlgrQ2gq/Wks8WTpA9btPoo41w\npX9l\r\n=ZPqk\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC5dMgE5SG7mvqt6k3B9IXzi/bNF1z6R9qvoS/atqyMugIhAJVSea/IPz4wDS/AOhgnnyhl7m1bYbrO7sd4BFGWZnEb"}]},"_npmUser":{"name":"akc42","email":"alan@chandlerfamily.org.uk"},"maintainers":[{"name":"akc42","email":"alan@chandlerfamily.org.uk"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/distributed-router_1.1.1_1617806672374_0.490594028438635"},"_hasShrinkwrap":false},"1.1.2":{"name":"@akc42/distributed-router","version":"1.1.2","description":"A Distributed Client Side Router","devDependencies":{"jest":"^26.5.2","@babel/core":"^7.11.6","@babel/preset-env":"^7.11.5","babel-jest":"^26.5.2"},"scripts":{"test":"jest"},"author":{"name":"Alan Chandler"},"license":"GPL-3.0-or-later","main":"location.js","directories":{"test":"tests"},"dependencies":{},"repository":{"type":"git","url":"git+https://github.com/akc42/distributed-router.git"},"keywords":["client","router","distributed","custom-elements"],"bugs":{"url":"https://github.com/akc42/distributed-router/issues"},"homepage":"https://github.com/akc42/distributed-router#readme","gitHead":"6c5eed12bb871d63fce396d8e3895b2f17bd3387","_id":"@akc42/distributed-router@1.1.2","_nodeVersion":"16.16.0","_npmVersion":"8.11.0","dist":{"integrity":"sha512-y8cGpjiVzFhx14igh9KMVyTb1fQ0H85drZ2ERDtu0fMDvQOwuwv8lIl6s17RV73ShxGixpS/x3+F2PVzCPk3uw==","shasum":"a0fc14cd46a6e63e8ae36c6f089db305515ea302","tarball":"https://registry.npmjs.org/@akc42/distributed-router/-/distributed-router-1.1.2.tgz","fileCount":8,"unpackedSize":70209,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD7Zh+oBVR586nXN/5KHTgLy2KMqbQeo7Pd1eARUvgB/AIhAIDBOHiZpnW92kM5tFVQC79PH0e/efa2pPyHRF3la4Op"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjIclgACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq18hAAgmbu3DvWVRKaETnT1sBH+FpC9YDchyGoUThtLfZoyG4hF69z\r\naa1q0OXnCeoI2/g2T6QOKPPNssjgcVzIeVjAtpc8osCqK9A1CyES6hRzL8+x\r\nvEdwoLk6nRQQ6HlpIJn1nrjgDAadCeyAziNoV5XBoN57VwBQrq5+2t9oWWBT\r\n0wkAgd4YUwCZho5kEwberCXX3KFAlLqGa97BPBVLVkyU2sIcVfbwQNMwuH8D\r\nbeXclZpu65yA4dxSWH9zSqY8TO0v9Fgq6vRg8gZnjcY7IL5MSLkes3Tr/pJH\r\nKTYvefZt6djGMwsC8ZPyIjgI5zDwQKEjPHK0m1gjs2MA/9F7SqAnK1ukInf8\r\nrqdEGQFNdInWewMNxnbZnZUja1F4vBogL3ER6NTKbhm/AIDwAzV/a2u3o0mL\r\nZ+UTCiDkNfXTiWA0rRhzElkDR9gExnkq/q1gWBQIoyZzIdkcCKMAYC+cFKTZ\r\nstN3Kftc0D9X47mDvbEKQkWlGqzfE3Zm7IN9FA/EfSRMsEewfzHD13WT4wUM\r\ndBpqTvuK25j55QtktRp1Yi72OlNTmZxCsB1p1ttCpiEHChJieetM4Yny1snO\r\nBFVD1axpwpxDRSQqeNQo6cwLQSNJBA1IeP8gy02D92KDnKhz8G2on84GkRsr\r\nWMhUg+RWg7XAn+l/lKh155EjPOaOMsLrREA=\r\n=0All\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"akc42","email":"alan@chandlerfamily.org.uk"},"maintainers":[{"name":"akc42","email":"alan@chandlerfamily.org.uk"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/distributed-router_1.1.2_1663158624274_0.4760460177857635"},"_hasShrinkwrap":false}},"time":{"created":"2020-10-08T08:23:11.393Z","1.0.2":"2020-10-08T08:23:11.573Z","modified":"2022-09-14T12:30:24.505Z","1.1.0":"2020-12-02T15:08:52.766Z","1.1.1":"2021-04-07T14:44:32.596Z","1.1.2":"2022-09-14T12:30:24.433Z"},"maintainers":[{"name":"akc42","email":"alan@chandlerfamily.org.uk"}],"description":"A Distributed Client Side Router","homepage":"https://github.com/akc42/distributed-router#readme","keywords":["client","router","distributed","custom-elements"],"repository":{"type":"git","url":"git+https://github.com/akc42/distributed-router.git"},"author":{"name":"Alan Chandler"},"bugs":{"url":"https://github.com/akc42/distributed-router/issues"},"license":"GPL-3.0-or-later","readme":"# distributed-router\nDistributed Client Side Router for use with a hierarchy of custom components in an Single Page Application\n\nThis is a series of javascript modules that you can link together to form a distributed client router system.  It links \nthe browsers URL bar into a chained list of `Routee` objects that process a part of the segmented url.  It takes in a `route` object\nand passes out a `subRoute` object.  These are chained together, the subRoute at one level being fed into route of the next level down\nthe hierarchy.  \n\nAt the top level is a pair of functions `connectUrl` and `disconnectUrl`.  Which ever element will be your master controller (I generally \nhave a `<main-app>` element which has a `<session-manager>` and `<page-manager>`, both of which are controlling pages.  A `<session-manager>` \npage doesn't reflect in the url bar at all as the user navigates the sign in process.  But once authorised, the `<page-manager>` takes over\nand controls which page is displayed based on the url.  So it is the `<page-manager>` custom element that calls `connectUrl` in its `connectedCallback`\nfunction, and `disconnectUrl` in its `disconnectedCallback` function.  `connectUrl` uses a callback function as its only parameter and this callback\nfunction gets called on url change, passing the top level `route` object.\n\nThe next piece in this arrangement is a router.  This is a class called `Route` and is instanciated with one required parameter and one \noptional parameter. The required parameter is a string containing \"/\" separated segments, which must either literally match the part of \nthe url, or can start with a \":\" character followed by a name, in which case we assume that that part of the url should be interpreted \nas a parameter.  We process a new `route` (however we receive it - either via the `connectUrl` callback, or being passed into a custom \nelement via a property/attribute) by calling the `routeChange` method, this returns a `route` object which the part of the url segment \nchecked against the specification provdied in the `new Route()` call. `route` has an `active` property to determine if it matched and \na `params` property the value of any of the \":\" segments. Any queryString is also decoded and placed in the `query` property of objects.\n\nIf the `active` propery of a route is false, the subRoute will also have an `active` value of false.  A `query` property is always passed \nstraight through and it is up to the application to decided how and when to use it.\n\nThe optional second parameter to the `new Route()` call is a matching string for the previous route up the chain.  It consists of a string\nwhich contains a single \":\" character.  The left of the \":\" character is a parameter name, and to the right a parameter value.  The incoming\nroute's `params` property must contain the \"name\" and it must have the value \"value\" for the subRoute to be active (as well as matching the url).\n\nThis is usually used with something like this\n```\n const topLevel = new Route('/:page');\n const firstLevel = new Route('/:id', 'page:appointments');\n connectUrl(route => {\n    const subRoute = topLevel.routeChange(route);\n    if (subRoute.active) {\n      ...\n\n      const subSubRoute = firstLevel.routeChange(subRoute);\n      if (subSubRoute.active) {\n        readDatabaseRecord(subSubRoute.params.id)\n      }\n      ...\n    }\n });\n \n```\n(I have simplified what happens - subRoute would probably be passed in as the `route` property to a custom element which might at some point want\nread a database record based on id).\n\nIn this example we only want to read the (lets say) the appointment record from the database if the `<appointment-manager>` element had been activated\nwith a url of the form \"/appointements/53\" and not (say) when the url was \"/user/53\", when the `<user-manager>` element is in the dom and the `<appointment-manager>` is still in the dom, but not doing anything.  The other obvious question is why not do this:-\n\n```\n const firstLevel = new Route('/appointments/:id');\n connectUrl(route => {\n    const subRoute = topLevel.routeChange(route);\n    if (subRoute.active) {\n      ...\n\n      const subSubRoute = firstLevel.routeChange(subRoute);\n      if (subSubRoute.active) {\n        readDatabaseRecord(subSubRoute.params.id)\n      }\n      ...\n    }\n });\n\n```\nand the answer to that is that I have an element `<route-manager>` which in fact something like `<page-manager>` extends\nwhich then allows me to do (in `lit-element`s `render` function)\n```\n    ${ {\n      home: html`<app-home></app-home>`,\n      user: html`<app-user managed-page .route=${this.subRoute}></app-user>\n      appointments: html`<app-appointments managed-page .route=${this.subRoute}></app-appointments`\n        }[this.page]\n     }\n```\n\nThe route manager users `new Route('/:page')` to translate the incoming `route` to the `page` property.\n\nInternally the `Route` class uses a `route-changed` event which this overall module listens to on the window and this can be used to change the url.\nthe `Route` class has three properties that can be set and which can change the url.\n\n- `connection` which if set `true` join the input and output of the route managed by this instance provided only that the route doesn't have any \":\" segment,\n   and change the url accordingly.  If set to `false` it will always make the output disconnected.\n- `params` which when set with an object which maps the properties of an active `params` in the `subRoute` will change the url - so for instance in the example\n   above calling `firstlevel.params = {id: 20}` will change the url to `/appointments/20`.\n-  `query` we can set a query set of parameters and these will then change the url to have those query parameters.\n\nOther modules that wish to change the url can do so, but they need to dispatch a `location-altered` event in the window. A helper \nclass `LocationAltered` can generate it for you, so to change the location do:-\n```\n  history.pushState({}, null, '/user/23');\n  window.dispatchEvent(new LocationAltered());\n```\n\n\n\n\n\n    \n \n\n\n","readmeFilename":"README.md"}