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 🙏

© 2025 – Pkg Stats / Ryan Hefner

reactive-assignments

v0.2.3

Published

Make javascript assignments reactive via a compiler

Readme

reactive-assignments

Make javascript assignments reactive via a compiler

This is an actively developed project. PRs, feedback, feature requests, and bug reports are always welcome here!

Installation

npm i reactive-assignments

Usage

import { compile } from 'reactive-assignments/compiler';

console.log(compile(`written code`, options));
// -> { code: `reactive code`, sourcemap: { version: 3, mappings: ';;AAA...', ... } }

See some examples for information on how the syntax works.

Compiler Options

Valid options are:

  • file (optional) - The name of the file that is being compiled.
  • sections (optional) - An array of strings specifing which tasks to run. Valid strings are 'import', 'references', 'declarations', 'assignments', or 'labels'. By default, all tasks are run
  • predefinedGlobals (optional) - An array of variables that are not to be messed with. Default is ['console']
  • runtime (optional) - The path to the reactive-assignments runtime. Default is reactive-assignments
  • sourcemap (optional) - If the compiler should generate sourcemaps or not. Default is true

Strategy

Modern javascript frameworks have become quite good at making javascript reactive. React, Vue, and Svelte are all reactive. The problem is that they are all linked to the browser. They all have some sort of templating engine, and thus can sometimes be a bit large and slow. The idea of this library is to just make plain javascript reactive. Implementations can come later.

The plan is that normal javascript gets executed normally, but when the compiler comes across this:

$: foo = bar;

The value of bar will always be bound to foo.

The following is the plan to accomplish this.

Note: To really understand the following examples, you need to be familiar with reactive-assignments stores.

Via the compiler, this code...

let foo = `bar`;

...gets compiled into this:

import $$store from 'reactive-assignments';

const foo = $$store.writableStore(`bar`);

References to the variable like this...

if (foo === 'bar') console.log(`Hello, World!`);

...are compiled like this:

if (foo.get() === 'bar') console.log(`Hello, World!`);

And this...

foo = `baz`;

...gets compiled into this:

foo.set(`baz`);

Therefore, this...

// Assuming bin has already been declared
$: bin = foo;

...can be compiled into this...

$$store.updatable(() => bin.set(foo), foo);

...and make bin reactive.

Written code:

let foo = `bar`;
let bin;

$: bin = foo;

foo = `baz`;

Compiled code:

import * as $$store from 'reactive-assignments';

const foo = $$store.writableStore(`bar`);

const bin = $$store.writableStore();
$$store.updatable(() => bin.set(foo), foo);

foo.set(`baz`);

// bin now equals 'baz' because the $$store.updatable function
// calls the first parameter everytime one of the subsequent parameters
// emits an update.

Development

Pull Requests are encouraged and always welcome!

# fork repo
git clone https://github.com/[your_username]/reactive-assignments
cd reactive-assignments
npm i
npm test # or npm test -- -w

The code can be built via the npm run build command. To watch the file system and rebuild on changes, use npm run build -- -w.

The runtime library is located in the src/runtime folder. The compiler is in the src/compiler folder.

This project uses Prettier for code formatting. Don't forget to npm run lint before you commit.

Stores API

writableStore

store = writableStore(value: any);

store is an object with four methods:

  • set(value: any) => void - Sets the store to a new value
  • get() => any - Returns the store's current value
  • update(fn: (currentValue: any) => any) => void - Will set the value of the store to whatever is returned from fn
  • subscribe(fn: (value: any) => void) => () => void - Calls fn everytime the value of the store changes. Returns a function that will unsubscribe (stop calling fn when the value changes) when called

readableStore

store = readableStore(startValue: any, actions: ({ set, update }) => void);

store is an object with all the properties as writableStore gives it, except set and update.

actions is a function that is passed in one property, an object containing the missing properties from store.

updatable

updatable(fn: () => void, ...stores)

Calls fn everytime one of the store's value changes.

If a value is passed into stores that is not a store, reactive-assignments will silently ignore it.

Returns a function that will 'unsubscribe' from the stores when called.

isStore

isStore(testValue: any): boolean

Just checks to see if testValue contains the appropriate subscribe and get methods.

License

MIT