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

@chanoch/clearsite-engine

v0.0.4

Published

A react website library

Downloads

4

Readme

simple-react-router

Implementation of a simple react router, with templating

This was inspired by Konstantin Tarkus's alternative to react router from You might not need React Router

In Konstantin's system, an array of routes together with the root level 'page' component that will render the root to the router. This array is used with the history component to integrate with the browser's navigation and redux to support navigation through the application.

The general workflow is that each user interaction results in a page being loaded into history followed by any mutations to state as redux middleware. This results in the page being updated

To create an application using clearsite:

  1. Define the routes
  2. Define reducers and initial state
  3. Define middleware
  4. Create your initial route
  5. Instantiate the router
  6. Load async server data

0. Setting up your application

The Single Page Application's (SPA's) HTML page is a standard react page which contains the following div to mount the application to:

        <div id="root"></div>

The HTML page must also include an import for javascript for your application. I use webpack to bundle my JS and dependencies but in general vendor js and css is imported statically into the page to benefit from CDN content delivery offloading and performance optimisation.

The webpack js files are imported statically rather than letting webpack inject them into the HTML as the index.html file is dynamicaly generated to inject configuration.

The reducers, redux middlware, and action creators are all standard redux mechanisms so you will need to define those according to the redux standards.

1. Define your routes

// Each page component is imported
import MyComponent from './MyComponentPage'

import React from 'react'

// The link between routes or paths in the application are provided in the path property for
// each object in the routes array.
const routes = [
    { path: '/menuplanner/', action: (store) => <MenuPlanner store={store} /> },
    { path: '/menuplanner/selectmenu.html', action: (store) => <ChooseRecipes  store={store}/> },
]

export default routes

2. Define reducers and initial state

A redux reducer modifies the state according to the state change which just occurred. It shouldn't have side-effects.


export function createMealPlanReducer(state, action) {
    return {
        ...state,
        mealPlan: action.mealPlan,
        action: CREATE_MEAL_PLAN
    }
}

3. Define middleware

The middlware will be injected with the state and the history object. This means that middlware can both mutate the state and navigate.

4. Create initial route

5. Instantiate the router

6. Load async data and dispatch a state change

TODOs

  1. Change the application to include a container type top level component to allow alternative mount points and passing in configuration?
  2. Link to redux tutorial
  3. Link to webpack tut on setting up a simple project
  4. Testing

Change Log

  • 0.1 to 0.2 - implemented smart defaulting to null implementations for state, middleware, and reducer, Moved routes parameter which defines valid navigation to front of list to make those related to redux optional.