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

hyperwrap

v1.0.11

Published

Makes React simple and functional

Downloads

18

Readme

Meet hyperwrap

Hyperwrap (inspired by hyperapp) turns react into a simple to use functional framework.

A few notes

  • In Hyperwrap there is no local state and no class components to worry about.
  • Hyperwrap makes global state management simple.
  • Hyperwrap is written in typescript.

Install

The easiest way to get going is to install the seed project using douglas.
douglas installs npm modules as ready to roll projects...

If you don't have douglas, install globally with npm i -g douglas

Install hyperwrapped-react (seed project)


douglas get hyperwrapped-react

Start

If you haven't used parcel-bundler before, then install globally with npm i -g parcel-bundler ... then ...


npm start

Basics

Hyperwrap is an app function that wraps around React.
When Hyperwrap's state changes - it rerenders React.

A typical entry index.tsx looks like...


import { app } from "hyperwrap";
import { initialState } from "./src/state/state";
import { View } from "./src/components/view/view.component";

app(initialState, View, document.getElementById('app'));

initialState is just a plain js object.
View is just a plain React functional component

Let's say our initialState is ...


{
    thing: 'not bob',
    anotherThing: 'something else'
}

The following component illustrates how to interact with state using getState and updateState...


import * as React from 'react';
import { State } from '../../../state/state';
import { getState, updateState } from 'hyperwrap';

export const Home = () => {

    const changeThing = (e: any, thing: string) => { updateState('thing', thing); };
    return (
        <div>
            <p>{getState().thing}</p>
            <button onClick={(e) => {changeThing(e, 'bob')} }>push</button>
        </div>
    );
};

Note that even though we update state.thing to 'bob', state.anotherThing remains unaffected.

Making the above pure and testable

  • We've moved changeThing to it's own module
  • We've made state and actions optional props to our functional component.
  • We've set default values for state and actions.

Our component is now a pure function. It relies entirely on what is passed into it. It doesn't create any direct side effects. This means we can inject mock values for state and actions, for easier testing.


interface Props {
    state?: State;
    actions?: { [key: string]: any }
}

const actionsCollection = {
    changeThing: changeThing
}

export const Home = (
    {state, actions}: Props = {
        state: getState(),
        actions: actionsCollection
    }
) => {
    const _state = state || getState();
    const _actions = actions || actionsCollection;
    return (
        <div>
            <p>{_state.thing}</p>
            <button onClick={(e) => {_actions.changeThing(e, 'bob')} }>push</button>
        </div>
    );
};

Updating State (Advanced)

To update state, specify the node in the state object to update, followed by the value.


updateState('deep/nested/thing', newValue);

Adding nodes - Use the above. If parent nodes aren't created yet, they will be created for you.

Deleting nodes - Make the newValue undefined. Any parent nodes will also be removed if they do not have children.

Updating without rerendering

By default hyperwrap rerenders an app on state change.

There will be times however where this is not ideal.

Instead pass the { rerender: false } flag to stop the app from rerendering...


updateState('deep/nested/thing', newValue, {rerender: false});

Updating multiple nodes at once

The following can be used to update multiple state nodes, before re-rendering...


updateMulti([
  { node: 'deep/nested/thing', updateValue: newValue1 },
  { node: 'another/deep/nested/thing', updateValue: newValue2 }
]);

Again, if you don't want to rerender after the state updates - pass the { rerender: false } flag.

e.g.


updateMulti([
  { node: 'deep/nested/thing', updateValue: newValue1 },
  { node: 'another/deep/nested/thing', updateValue: newValue2 }
], {
  rerender: false
});