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

@visiwa/trucks

v1.5.0

Published

``` State Management is: * An object singleton that is monitored for changes * Methods for checking if a particular change occurred to that object ```

Downloads

351

Readme

@visiwa/trucks

State Management is:
* An object singleton that is monitored for changes
	* Methods for checking if a particular change occurred to that object

Synonyms

monitored object, country management, union management, 
frontend database, browser database, state executivities

Install

npm install @visiwa/trucks

Example

This is essentially an internal component or singleton.

However, this truck file can be imported from
anywhere in the dapp.
This state manager can be used in any framework.
However, here is a svelte implementation example.
The implementation guide can be found after.
// $lib/trucks/truck_1/index.js


import { build_truck } from '@visiwa/trucks'

const trucks = {}

/*
	This adds a truck to the trucks object as trucks [1] = ...
	Such, the truck can then be deleted with the "destroy" method.
*/
export const make = () => {
	
	/*
		Freight is the "state" or the object that is
		is monitored.
	*/
	trucks [1] = build_truck ({
		freight: {
			leaf_name: "Leaf 1",
			leaves: {
				"Leaf 1": {
					alert_note: "This is leaf 1.",
					alert_success: "",
					alert_problem_1: "",
					alert_problem_2: ""	
				},
				"Leaf 2": {
					alert_note: "waiting for the flourish",
					alert_success: "",
					alert_problem_1: "",
					alert_problem_2: ""	
				}
			}
		}
	});
	
	/*
		Changes to the freight can be monitored here:
		
			* 	original_freight: 
					is the "freight" object that was passed to:
					build_truck ({ freight });

			* 	pro_freight:
					is the proxy object that encapsulates
					the original_freight for monitoring purposes.
			
			* 	bracket: the bracket or sub-bracket where the change occurred.
			
			* 	property: the property that changed
			* 	value: the value that changed
	*/
	let monitor = trucks [1].monitor (async ({
		original_freight,
		pro_freight, 
		//
		bracket,
		//
		property, 
		value
	}) => {
		try {
			// leaf name changed
			if (bracket === original_freight && property === "leaf_name") {
				console.info ("leaf name changed");
			}
			
			// Leaf 1 alert_success changed
			if (bracket === original_freight.leaves ["Leaf 1"] && property === "alert_success") {
				console.info ("Leaf 1 alert_success changed.");
			}
		}
		catch (imperfection) {
			console.error (imperfection);
		}
	});
}

export const destroy = () => {
	delete trucks [1];
}

export const retrieve = () => {
	return trucks [1];
}


/*
	Changes to the freight can also be monitored like this.
	This adds another monitor each time "monitor" is called.
	
	An example implementation can be found below.
*/
export const monitor = (action) => {	
	return trucks [1].monitor (envelope => { action (envelope); });
}

Make and Destroy of "Truck 1" in a root component (Svelte Example)

This is a Svelte example, but this can really be used in any framework.

// Regions/Parador/Lot.svelte

import { onMount, onDestroy } from 'svelte'
import * as Truck_1 from '$lib/trucks/truck_1/index.js'

onMount (async () => {	
	Truck_1.make ()
});
onDestroy (() => {
	Truck_1.destroy ()
});

Monitor and Monitor Stop in nested component.

If "Truck_1_Freight" is modified anywhere, the modification
is going to be noticed by each "monitor".
// Regions/Parador/Locations/Veranda.svelte

import { onMount, onDestroy } from 'svelte'
import * as Truck_1 from '$lib/trucks/truck_1/index.js'

let Truck_1_Monitor;
let Truck_1_Freight;
onMount (async () => {
	Truck_1_Freight = Truck_1.retrieve ().pro_freight; 
	
	Truck_1_Monitor = Truck_1.monitor (async ({
		original_freight,
		pro_freight, 
		//
		target,
		//
		property, 
		value
	}) => {
		try {
			// watch for changes to leaf_name
			if (target === original_freight && property === "leaf_name") {
				console.info ("leaf name changed");
				
			}
		}
		catch (imperfection) {
			console.error (imperfection);
		}
	});
	
	
	//
	//	This updates "leaf_name" and alerts each
	//	monitor.
	//
	Truck_1_Freight.leaf_name = "Leaf 2"
});

onDestroy (() => {
	Truck_1_Monitor.stop ()
}); 

Monitor and Monitor Stop

Svelte Truck_1 Singleton Component

This is an easier method of adding a monitor to a component with svelte.
/*
	import * as Truck_1 from '$lib/trucks/truck_1/index.js'
	import Truck_1_Ride from '$lib/trucks/truck_1/Ride.svelte'
	let Truck_1_Freight = false

	<Truck_1_Ride on_change={ ({ pro_freight }) => { Truck_1_Freight = pro_freight; } } />
	{#if typeof Truck_1_Freight === "object"}
	
	{/if}
*/

/*
	happening = "mounted"
	happening = "modulated"
*/
import { onMount, onDestroy } from 'svelte'
import { monitor_truck, retrieve_truck } from './index.js'

export let on_change = () => {}

let Truck_Monitor;
onMount (async () => {
	Truck_Monitor = monitor_truck (({ pro_freight }) => {
		on_change ({ 
			pro_freight, 
			happening: "modulated" 
		})
	})
	
	on_change ({ 
		pro_freight: retrieve_truck ().pro_freight, 
		happening: "mounted" 
	})
});
onDestroy (() => {
	Truck_Monitor.stop ()
});


</script>

<div style="position: absolute"></div>