Skip to content

Commit

Permalink
[add] API Document configuration
Browse files Browse the repository at this point in the history
[fix] several details
  • Loading branch information
TechQuery committed Dec 31, 2019
1 parent 027f428 commit 2d43988
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 41 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules/
package-lock.json
dist/
.cache/
.rts2_cache_*/
.rts2_cache_*/
docs/
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
test/
dist/
.rts2_cache_*/
Contributing.md
Contributing.md
docs/
.travis.yml
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
branches:
only:
- v2

language: node_js
node_js:
- lts/*
cache:
directories:
- node_modules

install:
- npm install
script:
- npm run build
- echo '' > docs/.nojekyll
deploy:
provider: pages
on:
branch: v2
skip_cleanup: true
local_dir: docs/
token: ${TOKEN}
6 changes: 5 additions & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

[![NPM](https://nodei.co/npm/cell-router.png?downloads=true&downloadRank=true&stars=true)][4]

## Demo

https://web-cell.dev/scaffold/

## Feature

- [x] **Router Component** as a **Page Container**
Expand Down Expand Up @@ -102,7 +106,7 @@ export default class PageRouter extends HTMLRouter {
```

[1]: https://www.webcomponents.org/
[2]: https://github.com/EasyWebApp/WebCell/tree/v2
[2]: https://web-cell.dev/
[3]: https://mobx.js.org/
[4]: https://nodei.co/npm/cell-router/
[5]: ./test/source/page/NestedRouter.tsx
33 changes: 19 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cell-router",
"version": "2.0.0-rc.2",
"version": "2.0.0-rc.3",
"license": "LGPL-3.0",
"description": "Web Component Router based on WebCell & MobX",
"keywords": [
Expand All @@ -24,37 +24,42 @@
"main": "dist/cell-router.umd.js",
"module": "dist/cell-router.js",
"peerDependencies": {
"mobx": "^5.14.0",
"mobx-web-cell": "^0.2.3",
"web-cell": "^2.0.0-beta.6"
"mobx": "^5.15.1",
"mobx-web-cell": "^0.2.5",
"web-cell": "^2.0.0-rc.12"
},
"devDependencies": {
"@types/jest": "^24.0.22",
"@types/jest": "^24.0.25",
"@types/jsdom": "^12.2.4",
"@types/puppeteer-core": "^1.9.0",
"fs-match": "^1.3.5",
"husky": "^3.0.9",
"husky": "^3.1.0",
"jest": "^24.9.0",
"jsdom": "^15.2.1",
"koapache": "^1.0.6",
"lint-staged": "^9.4.2",
"lint-staged": "^9.5.0",
"microbundle": "^0.11.0",
"mobx": "^5.15.0",
"mobx-web-cell": "^0.2.3",
"mobx": "^5.15.1",
"mobx-web-cell": "^0.2.5",
"parcel-bundler": "^1.12.4",
"prettier": "^1.19.0",
"prettier": "^1.19.1",
"puppeteer-core": "^1.20.0",
"ts-jest": "^24.1.0",
"typescript": "^3.7.2",
"web-cell": "^2.0.0-rc.0"
"snabbdom": "^0.7.4",
"ts-jest": "^24.2.0",
"typedoc": "^0.15.6",
"typescript": "^3.7.4",
"web-cell": "^2.0.0-rc.12"
},
"scripts": {
"debug": "cd test/ && parcel source/index.html",
"lint": "lint-staged",
"pack-test": "cd test/ && parcel build source/index.html",
"set-chrome": "app-find chrome -c",
"test": "npm run lint && npm run pack-test && jest --testTimeout 6000 --forceExit",
"build": "microbundle --external web-cell,mobx --globals web-cell=WebCell --name CellRouter",
"pack-dist": "microbundle --external web-cell,mobx --globals web-cell=WebCell --name CellRouter",
"pack-docs": "typedoc --name \"Cell Router\" --out docs/ source/",
"build": "npm run pack-dist && npm run pack-docs",
"help": "npm run pack-docs && web-server docs/ -o",
"prepublishOnly": "npm test && npm run build"
},
"prettier": {
Expand Down
42 changes: 20 additions & 22 deletions source/utility.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
import { createCell } from 'web-cell';

export function parsePathData(URI: string) {
const [path, data] = URI.split('?'),
params = {};
// @ts-ignore
for (let [key, value] of Array.from(new URLSearchParams(data).entries())) {
const item = params[key];

try {
value = JSON.parse(value);
} catch (error) {
/**/
}

if (!(item != null)) {
params[key] = value;
continue;
}

if (!(item instanceof Array)) params[key] = [item];

params[key].push(value);
const params = {},
[path, data] = URI.split('?');

const searchParams = new URLSearchParams(data);

for (const key of searchParams.keys()) {
const value = searchParams.getAll(key).map(item => {
try {
return JSON.parse(item);
} catch (error) {
return item;
}
});

params[key] = value.length < 2 ? value[0] : value;
}

return { path, params };
Expand Down Expand Up @@ -48,6 +43,9 @@ export function matchRoutes(list: Route[], path: string) {
typeof item === 'string'
? path.startsWith(item)
: item.exec(path)
)
return <Component {...parsePathData(path)} />;
) {
const data = parsePathData(path);

return <Component {...data.params} path={data.path} />;
}
}
8 changes: 6 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"compilerOptions": {
"target": "es5",
"module": "ES6",
"moduleResolution": "Node",
"downlevelIteration": true,
"experimentalDecorators": true,
"jsx": "react",
"jsxFactory": "createCell"
"jsxFactory": "createCell",
"lib": ["DOM", "DOM.Iterable"],
"target": "ES5"
},
"include": ["source/**/*"]
}

0 comments on commit 2d43988

Please sign in to comment.