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

fnaf

v1.0.8

Published

Freact is not a framework

Downloads

2

Readme

FNAF

Freact is Not a Framework (or Library)

My lecturers kept saying no frameworks or libraries. I was like, "I don't know what to do." So I made this, which is specifically not a library or framework.

Do Not Use This

There is no reason to. Unless you aren't allowed to use a framework for some reason. Then you probably still shouldn't use this, but I won't stop you.

Usage

Use a babel loader in webpack to transpile the code. FNAF uses JSX, so needs the transform JSX babel plugin.

// babelrc.js
{
  "plugins": [
    [
      "@babel/plugin-transform-react-jsx",
      {
        "runtime": "automatic",
        "importSource": "/node_modules/fnaf/dist/runtime" // important
      }
    ]
  ],
  "presets": ["@babel/preset-typescript"]
}

Components should extend the FreactComponent class. FreactComponent is generic. The first generic argument should be an interface of the component props. The second argument is an interface representing the object state. See the example at the bottom of the readme.

The Name

The F stands for Freact. It is a portmanteau of Fraser (my name) and React (in which this is pathetically inspired by). The F can also stand for free, in that it is freeing me from using vanilla JS (although this is still Vanilla JS, I emphasize that this is not a framework or a library).

Example

class Root extends FreactComponent<
  {},
  { total: { count: number }; user: any }
> {
  addEffects() {
    // Creates stateful data named "user". The return array is destructured 
    // into two functions. The first function gets the value, the second is 
    // a setter used to change the state.
    const [_getUser, setUser] = this.useState("user", {});
    // The useState function accepts the name of the state, and a value 
    // representing the initial state. If this state does not yet exist, 
    // it will be given the initial.
    const [getTotal] = this.useState("total", { count: 0 });

    // will run whenever "total" changes.
    this.useEffect(() => {
      console.log(getTotal());
    }, ["total"]);

    // will run whenever the component is loaded
    this.useEffect(() => {
      (async () => {
        const data = await fetch(
          "https://random-data-api.com/api/users/random_user"
        );
        const user = await data.json();
        setUser(user);
      })();
    }, []);
  }

  render() {
    const [getTotal, setTotal] = this.useState("total", { count: 0 });
    const [getUser] = this.useState("user", {});

    const total = getTotal();
    const user = getUser();

    return (
      <div>
        <h1>Hello World</h1>
        <p>This is a paragraph</p>
        <Counter total={total} />
        <button
          className="text-xl shadow rounded bg-blue-400"
          onClick={() => setTotal({ count: total.count + 1 })}
        >
          Click me!
        </button>
        <div>
          <div>{user.first_name}</div>
        </div>
      </div>
    );
  }
}

class Counter extends FreactComponent<{ total: { count: number } }> {
  render(): HTMLElement {
    const count = this.getProp("total");
    return <div>{count?.count}</div>;
  }
}

document.getElementById("root")?.appendChild(<Root />);