Slide 1

Slide 1 text

Prepared Router

Slide 2

Slide 2 text

Process of Build 1. Lexer Path 2. Generate Conditions 3. Rollup and Optimize 4. Dynamic Prediction

Slide 3

Slide 3 text

1. Lexer Path /book/:id /book/:id/:page{\\d+} /search/* separator static dynamic regex wildcard analyze the routing path 2. Generate Conditions pathParts is an array separated by separators. pathParts[1] = ‘book’ !!pathParts[2] ... /\d+/.test(pathParts[3]) ... pathParts.length > 2 ... And generate params

Slide 4

Slide 4 text

3. Rollup and Optimize if (A) { if (B) { ... } } if (C) { if (A) { ... } } optimize conditions if (A) { if (B) { ... } if (C) { ... } } if B and C are exclusive (B⊕C) if (A) { if (B) { ... }else if (C) { ... } }

Slide 5

Slide 5 text

4. Dynamic Prediction cache static path POST /books/list This is static path Routing with built matcher and cache the results const results = matcher(“POST”, “/books/list”, ...) // [/books/*, /books/list] cache(“POST”, “/books/list”, results)