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

plicit

v1.0.9

Published

<div align="center" style="text-align: center;"> <img width="150" src="logo.png"/> <h1>Plicit</h1> <i>A framework for building web user interfaces with explicitly defined reactivity</i> </div>

Downloads

15

Readme


Some unique features:

  • You have full control over the reactivity.

    You decide if a singe property / attribute should be reactive, or if an entire component should be reactive.

  • Reactivity is separated from the rendering.

    You can use reactivity "outside" of the component hierarchy.

  • Asynchronous components and synchronous components are treated the same.

    You don't need to treat async components in some special way... ( No <Suspense> needed! )


Reactivity

Explicit Reactivity

While some implicit reactivity is supported, this framework aims to provide full control over the reactivity by giving you the ability to be explicit about it.

An example:

const Counter = () => {
  const count = signal<number>(0)
  
  return (
    <div>
      <span>The counter is </span>
      { computedSignal(() => <span>{count.get()}</span>) } 
      <button on={{ click: () => count.set(x => x + 1) }}>increment</button>
    </div>
  )
}

Here, we are explicitly saying the only one of the <span> elements should react to changes. However, the dependencies are automatically tracked.


To summarize, we explicitly define an element to be reactive by wrapping it in a function.
Dependencies of a signal are automatically tracked.

Asynchronous Reactivity

Plicit has been developed with asynchronicity in mind.
Components can be async, as well as VDOM children.

Async Components

const HelloWorld = async () => {
  await sleep(1000); // or do an API request or something :)
  return <div>Hello world!</div>;
}

const App = () => {
  return <div>
    <HelloWorld/>
  </div>
}

Here, the <HelloWorld> component will begin rendering once the sleep() promise has been resolved.

You can also define a "placeholder" to render while the component is loading:

const App = () => {
  return <div>
    <HelloWorld asyncFallback={() => <span>Please wait...</span>}/>
  </div>
}

Here's a good place to put a spinner or some other cool animation!

Async VDOM children

const App = () => {
  return <div>
    {
      asyncSignal(async () => {
        await sleep(1000);
        return <div>Hello world!</div>
      }, { fallback: () => <span>Please wait...</span> })
    }
  </div>
}

This will give you a similar result as the previous example,
but instead of an async component, we're using an async signal.

Signals

As you might have noticed from the examples, signals are used for reactive states.
If you're not familiar with signals: a signal is basically a container for some data and it will automatically track other functions (or signals) who depends on it.

Signals in Plicit

Signals in Plicit might differ a bit from other implementations, so let's go through some examples.

Basic Counter
const counter = signal(0);

// This will be triggered everytime the counter is changed.
effect(() => console.log(counter.get()))

counter.set((count) => count + 1)
Computed

There is also something called computed signals in Plicit, it's just a signal that transforms the value of another signal.

const name = signal<string>('John Doe');

// will update everytime `name` is changed
const reversedName = computedSignal(() => Array.from(name.get()).reverse().join(''));

// A computed signal can also be defined like this:
const reversedName = signal(() => name.get().reverse(), { isComputed: true });
Async

An async signal works just like a regular signal, however it's able to be updated asynchronously.

const products = asyncSignal<Product[]>(async () => {
  const response = await fetch('https://somedomain.com/your/api/endpoint');
  return await response.json();
});

// You can check whether or not the signal has finished, either by inspecting it's state,
// or by having another signal react to it's changes.
// However, inspecting it's state is not reactive.

// Reactive, will be triggered when the promise is resolved
const productNames = computedSignal(() => {
  return (products.get() || []).map(product => product.name)
})

// Not reactive
if (products.state === ESignalState.RESOLVED) { doSomething() }

You can also provide a fallback value and the signal will return this value if it hasn't been resolved yet

const products = asyncSignal<Product[]>(async () => {
  const response = await fetch('https://somedomain.com/your/api/endpoint');
  return await response.json();
}, { fallback: [] });

Getting Started

Simply run:

npx plicit-cli myapp && cd myapp && npm i && npm run dev

Now your app should be up and running!