From ba0c2ea4d1368715a9416744dcc900e30ce83379 Mon Sep 17 00:00:00 2001 From: Timothy Farrell Date: Thu, 19 Jul 2018 07:48:57 -0500 Subject: [PATCH] Apply standard/enforced code format with prettier. This commit marks applying prettier to the whole of git history up to this point and prettier is used to enforce format via pre-commit hook. The command used was: `git filter-branch -f --tree-filter 'prettier --no-config --single-quote --tab-width=1 --print-width=100 --use-tabs --trailing-comma=none --prose-wrap=always --write "{.,{packages,bin}/**}/*.{js,json,md}" || echo "Error formatting, possibly invalid JS"' -- --all` --- packages/router/README.md | 36 ++++++++++++++++++------------------ packages/router/package.json | 8 ++++++-- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/packages/router/README.md b/packages/router/README.md index cace371..7fba2ae 100644 --- a/packages/router/README.md +++ b/packages/router/README.md @@ -16,43 +16,43 @@ const router = Router(routeSpecArray, rootURL='#'): An array of objects with the following properties: -* `name` _string_ - an optional string that can be referred to in the `href` and `goto` instance +- `name` _string_ - an optional string that can be referred to in the `href` and `goto` instance methods. Duplicate names are not allowed. -* `path` _string_ - the path template for this route. Path templates are matched in the order of the +- `path` _string_ - the path template for this route. Path templates are matched in the order of the array. Example: `"/"` - for the root path `"/articles"` - another static path `"/article/:id"` - a path with a variable `"/:unknownRoute"` - the last route could catch erroneous routes. Unmatched urls will automatically route here. -* `vars` _object_ - an optional object mapping variable names in the path template to a regular +- `vars` _object_ - an optional object mapping variable names in the path template to a regular expression for validation -* `enter` _function_ - a function for when this route is entered. The `enter` function receives two +- `enter` _function_ - a function for when this route is entered. The `enter` function receives two parameters: - * _route instance object_ - this is a object that contains properties: + - _route instance object_ - this is a object that contains properties: - * `name` _string_ - the route name - * `vars` _object_ - an object holding any variables parsed from the path - * `path` _string_ - the path as received + - `name` _string_ - the route name + - `vars` _object_ - an object holding any variables parsed from the path + - `path` _string_ - the path as received - * _router instance object_ - (see below) + - _router instance object_ - (see below) The `enter` function may return a callback that will be called instead of the `enter` function for further navigate events that will be handled by this route (with different variables). This allows `enter` to establish a context for the route it handles. -* `exit` _function_ - an optional function that will be called before calling `enter` of the next +- `exit` _function_ - an optional function that will be called before calling `enter` of the next path. `exit` has the option to delay the call to `enter` by returning a promise. This is intended for handling transition animations. If the route's `enter` function returns a callback, `exit` will not be called if the same route receives navigation but with different variables. `exit` receives the parameters similarly to `enter`: - * _route instance object_ - for the route being exited - * _route instance object_ - for the route yet-to-be entered - * _router instance object_ - (see below) + - _route instance object_ - for the route being exited + - _route instance object_ - for the route yet-to-be entered + - _router instance object_ - (see below) ### rootURL (optional string) @@ -62,24 +62,24 @@ The url prefix of all paths. This should always be `#` unless you're nesting rou The returned instance provides these methods: -* `goto(url: string)` or `goto(pathName: string, vars: object)` +- `goto(url: string)` or `goto(pathName: string, vars: object)` Match to a route by relative url or pathName and a vars object. Navigate there. -* `href(pathName: string, vars: object)` +- `href(pathName: string, vars: object)` Build a relative url based on the name and supplied vars. -* `start(initialRoute: string)` +- `start(initialRoute: string)` Listen to `window.onhashchange` for route changes. The `initialRoute` will be passed to `goto()` if there is no current route in `window.location`. -* `stop()` +- `stop()` Cancel subscription to `window.onhashchange` -* `current()` +- `current()` Get the current _route instance object_ as was provided to the current routes `enter` function. diff --git a/packages/router/package.json b/packages/router/package.json index c3639c8..de63720 100644 --- a/packages/router/package.json +++ b/packages/router/package.json @@ -3,12 +3,16 @@ "version": "2.1.0", "description": "A slim and unopinionated router", "main": "src/index.js", - "files": ["src"], + "files": [ + "src" + ], "scripts": { "test": "node ../../bin/runTests.js ./", "pre-commit": "npm run test" }, - "keywords": ["router"], + "keywords": [ + "router" + ], "author": "Timothy Farrell (https://github.com/explorigin)", "license": "Apache-2.0", "dependencies": {