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

trackr-objects

v1.0.0

Published

Turns JavaScript objects and arrays into reactive resources for Trackr.

Downloads

35

Readme

Trackr Objects

npm David Build Status

This library provides basic reactive data types for use with Trackr.

Install

Install via NPM.

npm install trackr-objects --save

Usage

Trackr Objects provides three base classes, Map, List and Variable. These aim to be reactive replacements for their native JavaScript counterparts, providing robust and efficient reactive support for functional applications.

Variable

This is a very simple class that emulates the regular var in JavaScript. Call the constructor with the initial value to create.

import {Variable} from "trackr-objects";

const val = new Variable("my value");

It is very easy to get and set data on a reactive variable.

val.get(); // gets data
val.set("new value"); // sets the data

Map

The Map class is similar to a normal JavaScript object, it assigns values to unique keys. To create a new map, call the constructor with some base data.

import {Map as ReactiveMap} from "trackr-objects";

const data = new ReactiveMap({ foo: "bar" });

There are several methods for retrieving data from the map reactively.

data.get("foo"); // gets value at key
data.has("foo"); // boolean for if key is in map
data.keys(); // an array of all keys in map
data.toJSON(); // a plain javascript object representing all data

There are also several methods for setting data on the map reactively.

data.set("foo", "new value"); // sets value at key
data.delete("foo"); // deletes key from map
data.clear(); // deletes all data from the map

List

The List class aims to duplicate the functionality of the JavaScript array. To create, pass the constructor an array with initial data.

import {List} from "trackr-objects";

const list = new List([ "a", "b", "c" ]);

Lists have almost all of the same methods as arrays, making them easy drop-ins.

list.push("another value");
list.sort();
list.forEach(function(){});

To retrieve and set data at a specific index in a list, use the .get() and .set() methods.

let first = list.get(0);
list.set(2, { foo: "bar" });

Object Property Tracking

You can easily track indivdual properties on existing objects with the trackProperty() method. Simply pass in an object and string for the property to track and the property will be made transparently reactive.

import Trackr from "trackr";
import {trackProperty} from "trackr-objects";

let data = {};
trackProperty(data, "foo", "bar");

Trackr.autorun(function() {
	console.log(data.foo);
});

// later, change the value and it will be logged
data.foo = "boom";