npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@emberx/router

v0.0.14

Published

This is a futuristic take on the router of ember.js, which is the most advanced and mature routing solution I've seen so far in frontend development. It supports named routes, queryParameters, dynamic link segments, redirections, promise-aware route-templ

Downloads

26

Readme

@emberx/router: Fast, advanced, flexible routing library for browsers and node.js

This is a futuristic take on the router of ember.js, which is the most advanced and mature routing solution I've seen so far in frontend development. It supports named routes, queryParameters, dynamic link segments, redirections, promise-aware route-template render delayin for SSR, parent-children route relationships. The router is fully testable with visit and currentURL helpers for @emberx/test-helpers.

// in index.ts:

import startRouter from './start-router';

const Router = startRouter();

export default Router.visit(`${document.location.pathname}/${document.location.search}`);

// ===================================================
// in ./start-router.ts:

import Router from '@emberx/router';
import IndexRoute from './routes/index/route.ts';
import PostsRoute from './routes/posts/route.ts';
import PostsIndexRoute from './routes/posts/index/route.ts';
import PostsPostRoute from './routes/posts/post/route.ts';

Router.addServices({
  intl: new LocaleService(),
});

let router = Router.start([
  {
    path: '/',
    name: 'index',
    route: IndexRoute
  },
  {
    path: '/posts',
    name: 'posts',
    route: PostsRoute,
    indexRoute: PostsIndexRoute
  },
  {
    path: '/posts/:slug',
    name: 'posts.post',
    route: PostsPostRoute
  },
  {
    path: '/posts/:blog_post_id/comments',
    name: 'posts.post.comments',
    route: PostsPostCommentsRoute
  },
]);

export default router;

// ===================================================
// in ./routes/index/route.ts:

import { Route, hbs, service } from '@emberx/router';
import { WelcomeBanner } from './components/welcome-banner';
import translate from './helpers/translate';
import RSVP from 'rsvp';

export default class PostsPostRoute extends Route {
  @service intl;

  static model(params, transition) {
    return RSVP.hash({ comments: fetchComments() }); // NOTE: RSVP.hash() returns a promise that waits for promises inside the hash
  }

  static includes = { WelcomeBanner, translate };

  static template = hbs`
    <WelcomeBanner />

    <h5>{{translate "post-page.welcome"}}</h5>
    <LinkTo @route="posts" @model={{11}} data-test-preview-link>All posts</LinkTo>
    <LinkTo @route="posts.post" @query={{hash preview=true}} @model={{11}} data-test-preview-reviewed-comments-link>View post 11</LinkTo>
    <LinkTo @route="posts.post" @query={{hash preview=true asUser=22}} @model={{12}} data-test-preview-reviewed-comments-link>View post 12 in preview mode by user 22</LinkTo>
    <LinkTo @route="posts.post" @query={{hash priviledge="admin"}} @model={{11}} data-test-preview-pending-comments-link>View this post in admin priviledge mode</LinkTo>

    <LinkTo @route="posts.post.comments" @model={{11}} data-test-preview-all-comments-link>See comments in detail</LinkTo>

    {{#each this.model.comments as |comment index|}}
      <div data-test-comment="{{index}}">
        <p>{{comment.content}} | <span class="{{comment.status}}">{{comment.status}}</span></p>
        <p>{{comment.postedAt}}</p>
      </div>
    {{/each}}

    {{yield}} <!-- PostsPostCommentRoute can use this route in its template and extend it thanks to yield -->

    <button {{on "click" this.changeLocale}}>{{translate "buttons.change-locale"}}</button>
  `;

  @action
  async changeLocale() {
    await this.intl.changeLocaleToRandomLocale();
    console.log('locale changed to:', this.intl.currentLocale);
  }
}