gt3 / ultra-router Goto Github PK
View Code? Open in Web Editor NEWRouter for component-based web apps. Pair with React or <BYOF />.
License: MIT License
Router for component-based web apps. Pair with React or <BYOF />.
License: MIT License
confirm(ok, cancel, msg) {
return window.confirm('Are you sure you want to navigate away?') ? ok() : cancel()
}
render() {
ultra.pause(this.confirm)
return <>
}
rectify identifier regex to match two consecutive identifiers as one
check same origin in click handler
function fixedEncodeURI(str) {
return encodeURI(str).replace(/%5B/g, '[').replace(/%5D/g, ']');
}
spec('/user/:id/details')(next)
spec('/user', '/user/:id', '/user/:id/show', '/user/:id/edit')(next, err)
spec('')(next)
let c1 = checks(':id', ':date')(/\d/)
let c2 = checks(':xxx')(/\w/)
let m1 = match(<<base>>, specs, [...c1, ...c2])
let ultra = container(m1, m2, ...)(<history>)
let {stop, push, replace} = utlra
/user/abc - :id not valid, stop matching in current spec, call error of current spec
/user/007/blah - :id valid, does not match any route in current spec EXACTLY, call error of current spec
/user/007/show - :id valid, matches some route exactly, call success
/user/abc/details - matches details but fails :id validation, call error of details spec
/zzz - none of the specs match, use default
flatten values, add ids
/:year : {exact, match, passed}
/:year/:make : {exact, match, passed}
/:year/:make/:vid : {exact, match, passed}
ids: [':year',':make', ':model']
values: ['2017','bmw','m5']
additional parameters for key value pairs
user_path(Endpoint, :show, 17, admin: true, active: false)
"/users/17?admin=true&active=false"
client code tries to delete a handler (element of the set) while proxy is iterating over the same handlers
this may leave the app in unexpected state
add validator for multiple pathKeys
ultra.advice(someValidateFn, '/a/:level1', '/a/:level1/:level2')
leave out path: "/"
createListener(ultra.push.bind(null, loc))
createListener(() => getUltra().push.bind(null, loc))
use actions.some
'/:x/:y' => match({':x': checkx}, '/xxx/yyy')
function checkx(value, mappedValues) {
//value = 'xxx'
//mappedValues = {':x': 'xxx', ':y': 'yyy'}
}
before push
new RegExp(`^${substitute(literals, subs)}`, 'i')`
default style if tag == 'a' and no style prop provided
use: {cursor: 'pointer', touchAction: 'manipulation', msTouchAction: 'manipulation'}
depends on #22 (encodeURI)
URIComponentBlacklist = ([^\s#$&+,/:;=?@]*)
to
([^\s/]*) (space or forward slash)
pass matched value to strip method in PrefixSpec instead of the prefix pathkey
In all bundles:
/*@__PURE__*/
process.env.NODE_ENV
to "production"
ability to add prefix per match(er)
let specs1 = [
spec('/:id/details')(next),
spec('/', '/:id', '/:id/show', '/:id/edit')(next, err)
]
let c1 = checks(':id', ':date')(/\d/)
let c2 = checks(':xxx')(/\w/)
let m1 = match(specs1, [...c1, ...c2], prefix = '/user')
let specs2 = [
spec('/:id/details')(next),
spec('/list')(next, err)
]
let c3 = checks(':id')(/\d/)
let m2 = match(specs2, c3, prefix = '/product')
let spec3 = [ spec('/error')(next), spec('')(next) ]
let m3 = match(specs3)
let ultra = container(m1, m2, m3)(<history>)
miss(action, '/x', '/x/xx')
pass mismatchers to container, execute after rejects
props.retain = 'history' or 'qs' or 'hash'
props.retain = 'history, qs' //multi
also remove need for navAction prop
let specB = spec('/')(routeB)
let level1Checks = check(':level1')(/^.{2}$/, /^[^\]]*$/)
match(specB, level1Checks, '/:level1')
// errors on href="b]" or href="bbbbb"
/a/999
/a/999/
should produce identical match result
use defaultStyle variable, overridable by style prop
resolve reject should return timer instance
if time is active, abandon processing (rejections)
all path creation thru dispatch should go through a parser
add a leading /
spec reject
spec function should accept (next, err, fail)
container should run reject only after matchers are matched/resolved
decodeURIComponent('%') //URIError: URI malformed
use try catch:
current solution:
ultra.stop()
container(...ultra.matchers, ...newMatchers)(ultra.history)
provide simplified version:
container(...newMatchers)(ultra)
match: should accept single object instead of array
c1 = check(v1,v2,v3,rx) // => {v1: f1, v2: f2, v3: f3}
c2 = check(v4,rx2) // => {v4: f4}
let m1 = match(specs, Object.assign({}, c1, c2))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.