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

waygate

v0.1.1

Published

You probably want [react-router] instead.

Downloads

5

Readme

waygate

You probably want react-router instead.

build status coverage license version downloads

Leveraging redux to power your react routing needs. The API very closely resembles react-router because familiarity is good and I personally like the declarative syntax. This exists mostly as an experiment to have all the routing state controlled by redux. For people who lean more towards the purist side of functional programming this may be appealing. Works with react-hot-loader too.

Usage

import React from 'react';
import {Provider} from 'react-redux';
import {Match, Switch, navigate} from 'waygate';

// Create a `Link` component for your app.
const Link = connect(null, {navigate})(({navigate, to, ...rest}) => (
  <a
    onClick={(ev) => {
      ev.preventDefault();
      navigate(to);
    }}
    {...rest}
  />
));

// Create a navigation tree.
const App = ({store}) => (
  <Provider store={store}>
    <Switch>
      <Match path='/' exact>
        <div>
          Foo
          <Link to='/bar'>
            Go to /bar
          </Link>
        </div>
      </Match>
      <Match path='/bar'>
        <div>Bar</div>
      </Match>
    </Switch>
  </Provider>
);

export default App;

web

Connect waygate to the HTML5 history API:

import {createStore as baseCreateStore, applyMiddleware} from 'redux';
import {createMiddleware as waygate} from 'waygate';
import reducer from '...';

const createStore = (initialState) => {
  const middleware = applyMiddleware(
    waygate(),
  );
  return baseCreateStore(reducer, initialState, middleware);
};

export default createStore;

node

Manually dispatch navigate() actions.

import ReactDOMServer from 'react-dom/server';
import {navigate} from 'waygate';
import createStore from '...';
import App from '...';

const render = (path) => {
  const store = createStore();
  store.dispatch(navigate(path));
  return ReactDOMServer.renderToString(
    <App store={store}/>
  );
};

export default render;

API

Switch

Render the first match-compatible component in a list of children. Switch does not render child Match nodes in the react tree – only their children. This allows you to perform animations and transitions with tools like react-motion.

const willLeave = () => ({opacity: 0});

const styles = (children) => React.Children.map(children, (child) => {
  return {
    key: child.key,
    style: {opacity: 1},
    data: child,
  }
});

const Transition = ({children}) => (
  <TransitionMotion
    willLeave={willLeave}
    styles={styles(children)}
    children={(styles) => {
      <div>
        {styles.map(({style: {opacity}, data: child, key}) => (
          <div style={{opacity}} key={key}>
            {child}
          </div>
        ))}
      </div>
    }}
  />
);

<Switch component={Transition}>
  <Match path='/foo' key='a' children='foo'/>
  <Match path='/bar' key='b' children='bar'/>
</Switch>

Match

Simple match component that allows path and selector based matching.

<Match path='/foo'>
  I will render when at `/foo`
</Match>

You can also pull out params from the path:

<Match path='/user/:name'>
  {({name}) => (
    <div>Hello {name}</div>
  )}
</Match>