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

@foresteam/proactive

v0.1.2

Published

A frontend library, similar to React (though was intended to be more like Vue)

Downloads

1

Readme

@foresteam/proactive

A frontend library, similar to React (though was intended to be more like Vue)

I tried to replicate popular frontend frameworks, as for experiment.

It uses components and composition for its base

Accessor (aka ref)

Something simillar to Vue's computed/refs. These are basically objects with the following properties:

Accessor

  • value - the mutable variable
  • onChange - a callback, when we need to do something upon a mutation

Getter

Actually the same Accessor, but immutable and only accepts get() method in its constructor

Accessorify

Transforms values to accessors, and keeps accessors as they were. The idea is to accept values and refs to values as props in the same time.

Component

Typical component has the following structure:

  • component-name/
    • ComponentName.ts
    • ComponentName.css

Components MUST have ONE root node.

There are basically two ways to render components:

  • Wrapping them inside Renderer() and using them like common DOM nodes.
    • Does not support advanced features like passing functions/refs etc.
    • Though it does support recursive parsing (component inside another component), this might be not that well tested yet
    • May misparse something sometimes (pass string instead of boolean, for example)
    • Some tagnames just won't work/occupied, so you have to choose them carefully
  • Using their .render() function. More flexible and less buggy, yet not that fancy

Components have a single slot tag, that should be (if present) written exactly this way (see examples below):

<slot></slot>

It is a pseudo-tag, that Renderer() will write inner HTML instead of. If it is not present, it will append to the end of the component

Example

components/titled-section/TitledSection.ts

import { type IAccessor, Accessorify } from '@foresteam/proactive';
import { Component, useStyle, type VNode, type ComponentProps } from '@foresteam/proactive';

export interface Props extends ComponentProps {
	title: boolean | IAccessor<boolean>;
}

export const TitledSection = ({ title: title, ...props }: Props): VNode => {
	const title = Accessorify(title);

	const self = {
		exports: {
			// actually nonsense, but here we export accessors to the VNode
			title
		},
		...Component(/*html*/
			`
				<section class="titled">
					<h1 ref="header">${title.value}</h1>
					<slot></slot>
				</section>
			`,
			TitledSection.name,
			props
		)
	};

	// here you write uses
	// pushes refs to CSS via vars
	useCssVars(self, {
		paddingTop: Accessor('10px')
	});
	const refs = {
		header: Accessor<HTMLElement | undefined>(undefined)
	};
	// pulls DOM nodes to refs
	useRefs(self, refs);

	useOnMounted(self, root => {
		console.log(root);
		header.value.addEventListener('click', () => header.value.innerHTML = 'another header!');
	});

	return self;
};

//styles
// stylesheet doesn't have to wear the same name as the component, actually
// there can be many shylesheets, or none at all
// although they should be imported and used the following way for VScopes and CSSVars to work
import style from './TitledSection.sass?inline';
useStyle(style, TitledSection.name);

components/titled-section/TitledSection.sass

// __vscope is a pseudo-selector substituted with node UUID in runtime, so it provides scoped styling to some extent
.__vscope
	// vcss is a pseudo-function, substituted with a var in runtime. The name of its argument is the same as of JS var
	padding-top: vcss(paddingTop)

App.ts

import { TitledSection } from './components/titled-section/TitledSection';
import { Getter } from '@foresteam/proactive';

const app = document.querySelector<HTMLDivElement>('#app');
if (!app)
	throw new Error();

const mount = () => app.innerHTML = Renderer(/*html*/
	`
		<titled-section title="Title!">Some text inside "slot" pseudo-tag</titled-section>
		${TitledSection({ title: 'Another title!' }).render()}
	`,
	{
		'titled-section': TitledSection as TComponent,
	}
);

// here we can define some variables that we need

mount();