Giter Site home page Giter Site logo

yerkopalma / singleton-router Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 78 KB

:anchor: Tiny singleton router for the browser

Home Page: https://www.npmjs.com/package/singleton-router

License: MIT License

HTML 18.50% JavaScript 81.50%
router routers singleton-router frontend

singleton-router's Issues

Improve bundled size

Actual size (37.1 Kb) is too heavy, should be improved.
router cost

options

  • switch minifyjs for butternut -> ~25.38Kb
  • use vanilla ES5 syntax -> ~24.72Kb
  • separate the standalone version -> bundle ~4.18Kb, web.min ~24.74Kb
  • avoid url-pattern dependency

Test the thing!

Test Suite

  • Singleton Pattern
  • Router
    • popstate
    • setStore
    • addRoute
    • setRoot
    • start
    • onPopState
    • getRoute
    • notFound
    • gotToPath
    • manageState
    • requestStateUpdate
  • Route
    • getParams
    • setParams
    • onStart

New added links don't manage route

When something like

<a data-route="/new" href="#"></a>

is added, it wont have the event listener for new navigation, so it will have default behaviour

Support priority in routes

Support these routes

const router = SingletonRouter()

router.addRoute('/', PostsView)
router.addRoute('/posts', PostsView)
router.addRoute('/posts/:post', PostView)
router.addRoute('/authors', AuthorsView)
router.addRoute('/authors/:author', AuthorView)
router.addRoute('/tags', TagsView)
router.addRoute('/tags/:tag', PostsView)
router.addRoute('/search', SearchView)
router.addRoute('/:year/:month/:day', PostsView)
router.setRoot('/')
router.start('#app')

Right now, the getRoute method, returns the first matched route, not the best matched routes, so I need to define some priority in routes.
The above example would render the PostsView for /posts/awesome-post instead of the PostView

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.