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

@inyourarea/vapor-js

v0.0.46

Published

# Vapor-js A server-side renderer for segmented React applications with built-in Redux support.

Downloads

10

Readme

####Work in progress!

Vapor-js

A server-side renderer for segmented React applications with built-in Redux support.

Installation

yarn add vapor-js

Using Vapor

Vapor allows you to easily break a large React application into smaller, more manageable apps, which can have a big effect on performance.

API

createVapor

Accepts a config object and returns an object with two methods, build and exists.

Usage:

import createVapor from 'vapor-js'

const vapor = createVapor(options)

Returns:

{
    build: Function,
    exists: Function
}
Options

Options should be an object of the following shape (details below):

{
    components: Object,
    componentReducer?: Function,
    store?: Object,
    template?: string
}
components

An object lookup table for your components. Each property should be either a valid React component or a object of the following shape:

{
    component: Function,
    store?: Object,
    template?: string
}
Example:
const components = {
    Landing: require('../Landing'),
    Feed: {
        store: feedStore,
        template: feedTemplate,
        component: require('../Feed')
    }
}
componentReducer

A function that accepts a single object parameter with component, store, and props properties. The function should check the value of component to determine which state to prepare for your app's initial render.

The easiest way to prepare your state is to dispatch actions with values from props (props should be generated on the server before calling vapor.build).

The API is shown below, actual implementation is up to you:

({ component, store, props }) => state
Example

The easiest way is to use a switch/case statement:

function componentReducer ({ component, store, props }) {
    switch (component) {
        case 'Feed':
            store.dispatch(fetchFeedSuccess({ feed: props.feed }))
            return store.getState()
    }
}

Using a lookup table can reduce boilerplate:

const Feed = ({ store: { dispatch, getState }, props }) => {
    dispatch(fetchFeedSuccess({ feed: props.feed }))
    return getState()
}
const componentReducer = ({ component, store, props }) => ({ Feed })[component]({ store, props })
store

A global Redux store, useful for when multiple components need to share state. If a component has a store property the global store is ignored.

template

A global HTML template for rendering your applications into. If a component has a template property the global template is ignored.

Basic Server Example:

import express from 'express'
import vapor from './vaporSetup'

const app = express()
const port = 8080

app.use(express.static('path/to/assets'))

app.get('/', async (req, res) => {
  const component = 'Landing'
  
  if (!vapor.exists({ component })) {
    res.status(404)
    res.send('Oopsie...')
    return
  }
  
  const props = await request(options)
  const initialRender = vapor.build({ component, props })
  
  res.send(initialRender)
})

app.listen(port, () => { console.log(`Server listening on ${port}`) })