Skip to content

Commit

Permalink
feat(router): working route change from set context
Browse files Browse the repository at this point in the history
affects: @tao.js/router, patois.web

tao-router able to update the route path when a subscribed taople is set using data from the taople
  • Loading branch information
eudaimos committed Oct 9, 2018
1 parent 02dbefb commit 8ecf235
Show file tree
Hide file tree
Showing 7 changed files with 367 additions and 41 deletions.
9 changes: 5 additions & 4 deletions examples/patois.web/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import initialAppCtx from './tao-init';
import Router, { route } from '@tao.js/router';
import Router from '@tao.js/router';

Router(TAO, {
initAc: initialAppCtx
Expand All @@ -16,13 +16,14 @@ TAO.addInlineHandler({ t: 'Router', a: 'Init', o: 'Portal' }, () => {
// Routes: ['/', '/space'],
// Configure: [
Routes: [
{ Route: '/', Add: new AppCtx('Space', 'List') },
{ Route: '/', Add: { term: 'Space', action: 'List' } },
{
Route: {
path: route`/${'t'}/${'term._id'}`,
path: '/{t}/{term._id}',
// path: route`/${'t'}/${'term._id'}`,
lowerCase: true
},
Add: new AppCtx('', 'View')
Add: { action: 'View' }
}
]
});
Expand Down
72 changes: 56 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 86 additions & 0 deletions packages/tao-router/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# tao-router

## node console testing

```sh
> let re = /\{([\w|\.]+)}/gm
undefined
> re
/\{([\w|\.]+)}/gm
> let path = /{t}/path/{term.id}/{action.go}/
let path = /{t}/path/{term.id}/{action.go}/
^

SyntaxError: Invalid regular expression flags

> let url = '/{t}/path/{term.id}/{action.go}/
let url = '/{t}/path/{term.id}/{action.go}/
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

SyntaxError: Invalid or unexpected token

> let earl = '/{t}/path/{term.id}/{action.go}/'
undefined
> earl
'/{t}/path/{term.id}/{action.go}/'
> re.match(earl)
TypeError: re.match is not a function
> re.test(earl)
true
> re.exec(earl)
[ '{term.id}',
'term.id',
index: 10,
input: '/{t}/path/{term.id}/{action.go}/' ]
> re = /\({([\w|\.]+)})*/gm
SyntaxError: Invalid regular expression: /\({([\w|\.]+)})*/: Unmatched ')'
> re = /\({([\w|\.]+)\})*/gm
SyntaxError: Invalid regular expression: /\({([\w|\.]+)\})*/: Unmatched ')'
> re = /(\{([\w|\.]+)\})*/gm
/(\{([\w|\.]+)\})*/gm
> re.exec(earl)
[ '',
undefined,
undefined,
index: 0,
input: '/{t}/path/{term.id}/{action.go}/' ]
> re = /(\{([\w|\.]+)\})*/gm
/(\{([\w|\.]+)\})*/gm
> re.exec(earl)
[ '',
undefined,
undefined,
index: 0,
input: '/{t}/path/{term.id}/{action.go}/' ]
> earl.match(re)
[ '',
'{t}',
'',
'',
'',
'',
'',
'',
'{term.id}',
'',
'{action.go}',
'',
'' ]
> earl.split('/')
[ '', '{t}', 'path', '{term.id}', '{action.go}', '' ]
> earl.match(/\//g).length
5
> earl.match(/\//g).length + earl.split('/')
'5,{t},path,{term.id},{action.go},'
> earl.match(/\//g).length + earl.split('/').length
11
> earl.match(re).length
13
> re = /(\{([\w|\.]+)\})/gm
/(\{([\w|\.]+)\})/gm
> earl.match(re)
[ '{t}', '{term.id}', '{action.go}' ]
>
(To exit, press ^C again or type .exit)
>
```
64 changes: 64 additions & 0 deletions packages/tao-router/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion packages/tao-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
},
"dependencies": {
"get-value": "^3.0.1",
"history": "^4.7.2"
"history": "^4.7.2",
"path-to-regexp": "^2.4.0",
"routington": "^1.0.3",
"url-pattern": "^1.0.3"
}
}
Loading

0 comments on commit 8ecf235

Please sign in to comment.