open-index/open-npm huggingface dataset:
npm package: @spicyjs/reactor
Description: SpicyJS is a buildless microframework with a VanillaJS mental model that consists of a few tiny packages:
Latest version: 1.0.9

# SpicyJS

SpicyJS is a buildless microframework with a VanillaJS mental model that consists of a few tiny packages:

- @spicyjs/core: a JS library that takes the pain out of creating, updating, and attaching listeners to elements. (~1kb uncompressed)
- @spicyjs/reactor: a Reactive library that binds data to nodes (~1kb before gzip uncompressed)
- @spicyjs/router: a lightweight router for SPA's (~2kb before gzip uncompressed)

## Why

Reactiviy allows for fast, low boilerplate DOM updates. A reactivity system helps to avoid bad practices like using DOM as state. Spicy reactivity is proxy based and only targets the DOM elements you specify. There is no virtual DOM, queue flush or render flow. Changes are propagated immediately to the DOM.

## Installation

```bash
npm i @spicyjs/reactor;
```

Reactivity is Proxy based. You create a reactor by invoking the reactor function, similar to a Vue ref. The resulting variable is a function with a value property.

If invoked as a function, a side effect is added. A side effect may be a text node, an HTMLElement, or a function.

Note that objects and arrays require some special handling if accessed within their own effects.

```ts
import spicy from "@spicyjs/core";
import { reactor } from "@spicyjs/reactor";

const { div, button, span, input, label } = spicy;

const count = reactor(0);
const increment = () => count.value++;

export const counter = () =>
	div(span(count()), button("increment", { click: increment }));

const firstName = reactor("");
const lastName = reactor("");
const fullName = reactor(() => `${firstName.value} ${lastName.value}`);

//Objects should be accessed inside their own effects with 'raw', do not update objects inside their own effects
const people = reactor(["steve", "jeff", "ronald"]);
people(() => {
	const items = people.raw.map((person) => li(person));
	//etc
});

//register side effect
const effect = fullName(() => console.log("full name updated!"));

// cleanup
// fullname.removeEffect(effect);
// OR
// fullName.destroy();
// lastName.destroy(); //etc

export const fullNameGenerator = () =>
	div(
		span(fullName()),
		label({ for: "firstname" }, "First Name"),
		input({
			id: "firstname",
			input: ($event) => (firstName.value = $event.target.value),
		}),
		label({ for: "lastname" }, "Last Name"),
		input({
			id: "lastname",
			input: ($event) => (lastName.value = $event.target.value),
		})
	);
```

As noted in the example, to keep the package size small, object methods have not been enumerated and checked against inside reactors. Accessing array methods inside an effect will trigger a call stack exceeded error. To access objects inside their own effects, refer to them with `.raw`.

Full type:

```ts
type Reactor = (initialState: string | bool | number | (() => void)) => ((
	effect: HTMLElement | Text | (() => void)
) => effect) & {
	value: typeof initialState | ReturnType<typeof initialState>;
};
```
npm package: @spicyjs/router
Description: SpicyJS is a buildless microframework that consists of a few tiny packages. Like all spicy packages, the router can be used without the other packages.
Latest version: 1.0.2

# SpicyJS Router

SpicyJS is a buildless microframework that consists of a few tiny packages. Like all spicy packages, the router can be used without the other packages.

- @spicyjs/core: a JS library that takes the pain out of creating, updating, and attaching listeners to elements.
- @spicyjs/reactor: a Reactive library that binds data to nodes
- @spicyjs/router: a lightweight router for SPA's

## Why

When developing web applications, its often a better experience to refresh only a portion of the page, creating an SPA. This router aims to be small and will get smaller as new navigation oriented browser APIs are adopted.

## Installation

```bash
npm i @spicyjs/router
```

## Usage

```js
import { createRouter, go, beforeEach, afterEach, getCurrentRoute } from "@spicyjs/router";

const outlet = document.createElement('div');
outlet.className = 'router-outlet'
document.body.append(outlet);

beforeEach(async () => {
	await checkSomething();
	//display a loading indicator
})

afterEach(() => {
	//hide the loading indicator
})

//create the router
await router.createRouter([
	{
		name: "default",
		path: "/",
		handler: async () => {
			await importantStuff();
			return document.createElement('div');
		},
	},
	{
		target: '.a-selector',//defaults to .router-outlet, this can also be an element or a function that returns an element
		name: "about",
		path: "/about/:id",
		handler: (params, query) => document.createElement('span'),
		before: () => {
			if(!loggedIn) {
				router.go({ name: 'default' })
				return false;
			}
		},
		after: () => {
			console.log('you navigated, yay!')
		}
	},
]);

//navigation
await go({ name: "about", params: { id: "123" }, query: { search: "bob" } });
await go({ path: "/" );
```