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

aberdeen

v0.0.17

Published

A TypeScript/JavaScript library for quickly building performant declarative user interfaces without the use of a virtual DOM.

Downloads

9

Readme

A TypeScript/JavaScript library for quickly building performant declarative user interfaces without the use of a virtual DOM.

The key insight is the use of many small anonymous functions, that will automatically rerun when the underlying data changes. In order to trigger updates, that data should be encapsulated in any number of Store objects. They can hold anything, from simple values to deeply nested data structures, in which case user-interface functions can (automatically) subscribe to just the parts they depend upon.

Why use Aberdeen?

  • It provides a flexible and simple to understand model for reactive user-interface building.
  • It allows you to express user-interfaces in plain JavaScript (or TypeScript) in an easy to read form, without (JSX-like) compilation steps.
  • It's fast, as it doesn't use a virtual DOM and only reruns small pieces of code in response to updated data. It also makes displaying and updating sorted lists very easy and very fast.
  • It's lightweight, at about 15kb minimized.

Examples

To get a quick impression of what Aberdeen code looks like, this is all of the JavaScript for the above Tic-tac-toe demo:

import {node, prop, mount, Store, text} from 'https://cdn.jsdelivr.net/npm/aberdeen/+esm';

const store = new Store({
	squares: [],
	turn: 'X',
	history: [{}],
})

const drawSquare = (position) => {
	node('button.square', () => {
		let value = store.get('squares', position)
		if (value) text(value)
		else prop('click', () => fillSquare(position))
	})
}

const drawBoard = () => {
	for(let y=0; y<3; y++) {
		node('div.board-row', () => {
			for(let x=0; x<3; x++) {
				drawSquare(y*3 + x)
			}
		})
	}
}

const drawInfo = () => {
	node('div', () => {
		let winner = calculateWinner(store.get('squares'))
		if (winner) {
			text(`Winner: ${winner}`)
		} else {
			text(`Next player: ${store.get('turn')}`)			
		}
	})
	node('ol', () => {
		store.onEach('history', item => {
			node('li', () => {
				node('button', () => {
					text(item.index() ? `Go to move ${item.index()}` : `Go to game start`)
					prop('click', () => {
						store.set('historyPos', item.index())
						store.set('squares', item.get())
					})
				})
			})
		})
	})
}

const fillSquare = (position) => {
	// If there's already a winner, don't allow a new square to be filled
	if (calculateWinner(store.get('squares'))) return

	// Fill the square
	store.set('squares', position, store.get('turn'))
	
	// Next player's turn
	store.set('turn', store.get('turn')==='X' ? 'O' : 'X')
	
	if (store.get('historyPos') != null) {
		// Truncate everything after history pos
		store.set('history', store.get('history').slice(0,store.get('historyPos')+1))
		// Stop 'time traveling'
		store.delete('historyPos')
	}
	
	// Append the current squares-state to the history array 
	store.push('history', store.get('squares'))
}

const calculateWinner = (squares) => {
	const lines = [
		[0, 1, 2], [3, 4, 5], [6, 7, 8], // horizontal
		[0, 3, 6], [1, 4, 7], [2, 5, 8], // vertical
		[0, 4, 8], [2, 4, 6] // diagonal
	];
	for (const [a, b, c] of lines) {
		if (squares[a] && squares[a] === squares[b] && squares[a] === squares[c]) {
			return squares[a];
		}
	}
}
 
mount(document.body, () => {
	node('div.game', () => {
		node('div.game-board', drawBoard)
		node('div.game-info', drawInfo)
	})
})

Reference documentation

https://vanviegen.github.io/aberdeen/modules.html