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

router-as-view

v2.1.3

Published

Router view for React

Downloads

9

Readme

Router as a View in React

Location bar is a view of store

This project is based on react, immutable and actions-recorder.

Demo http://repo.react-china.org/router-as-view

Initial idea

Router is part of MVC and we can certainly divide it into M, C and V for better managements. It's like react-redux-router but designed based on actions-recorder.

Ideas behind it: Router is a View

Usage

npm i --save router-as-view

Router DSL is defined in an immutable Map:

Addressbar = require 'router-as-view'
pathUtil = require 'router-as-view/lib/path'

routes = Immutable.fromJS
  home: [] # means / or /home
  demo: [] # means /demo
  team: ['teamId'] # means /team/:teamId
  room: ['roomId'] # means /room/:roomId
  '中文': ['中文'] # means /中文/:中文

# oldAddress = "#{location.pathname}#{location.search}" # for history API
oldAddress = location.hash.substr(1) # to remove sharp mark
router = pathUtil.parseAddress oldAddress, routes
store = store.set 'router', router

Notice that 2 of the paths are different:

  • home is generated when / or /home is found
  • 404 is generated when no router is found

M part, add initial router object in store. It looks like:

name: 'team'
data:
  teamId: '12'
query:
  isPrivate: 'true'
router: # nested router is parsed from address directly
  name: 'room'
  data:
    roomId: '34'
  query: {}
  router: null

Parameters and querystrings are supported. Get this from store and render the page.

"V" part, mount Addressbar component to manipulate History API:

Addressbar
  router: store.get('router')
  routes: routes
  onPopstate: (info, event) ->
    # figure out the new router object and dispatch a `router/go` action
  inHash: true # fallback to hash from history API
  skipRendering: false # true to allow model/view inconsistency during loading

"C" part, connect action to store:

switch actionType
  when 'router/go' # <--- bind this action
    router.go store, actionData
  else
    console.warn ":Unknown action type: #{actionType}"
    store

Read src/ for details.

Notice

  • keep in mind that router-as-view is totally based on immutable-js.
  • if you need to route asynchronously, try set skipRendering to true during loading
  • undefined value is eliminated on purpose, fire an issue if you think differenly.

License

MIT