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

@homebots/elements

v0.12.3

Published

Microframework to write modern web apps using latest ES/HTML/CSS stuff

Downloads

4

Readme

Elements

This is a microframework that tries to use the latest API's from HTML, Javascript and CSS to run web apps.

Using Custom elements and a few other features, like dependency injection, change detection and lifecycle hooks.

Lifecycle hooks

Every custome element can implement one of the following hooks: OnInit, OnDestroy, onChanges, OnBeforeCheck

Change detection

Every instance has its own change detection context, but when a component changes something, the change detection looks at all observed properties in that context and all children, starting from the root element.

This is to ensure that changes that affect the parent elements can also be checked.

As an alternative, change detection (via Zone.js) can be used as well.

Examples

A minimalistic todo app:

// app.component.ts
import { Component } from '@homebots/elements';

@Component({
  tag: 'todo-app',
  template: `
    <form (submit.stop)="this.addTask(newtask.value); newtask.value = ''">
      <input #newtask />
      <button type="submit">add</button>
    </form>
    <ul>
      <template *for="'task'" [of]="this.tasks">
        <li><input type="checkbox" (change.stop)="task.done = !task.done" [value]="task.done" /> {{ task.title }}</li>
      </template>
    </ul>
  `,
})
export class TodoApp extends HTMLElement {
  tasks = [];

  addTask(title: string) {
    return this.tasks.push({ done: false, title });
  }
}

Then bootstrap the application:

// index.ts
import { Bootstrap } from '@homebots/elements';
import './app.component.ts';

Bootstrap.createApplication();

Then finally put all together:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Todo</title>
    <script src="https://unpkg.com/reflect-metadata"></script>
    <script type="module" src="./index.ts"></script>
  </head>

  <body>
    <todo-app></todo-app>
  </body>
</html>

Syntax

Most of the syntax is shamelessly copied from Angular and Alpine.js:

<!-- bind an attribute -->
<div @class="this.dynamicClasses"></div>

<!-- bind a property -->
<div [innerText]="this.text"></div>

<!-- listening to events -->
<div (click)="this.onClick()"></div>

<!-- using references -->
<input #name />
<button (click)="name.focus()">click me</button>

<!-- conditional nodes -->
<template *if="this.showName" [else]="noname">Hello, John!</template>
<template #noname>Who are you?</template>

<!-- loops -->
<ul>
  <template *for="'name'" [of]="this.listOfNames">
    <li>{{name}}</li>
  </template>
</ul>

<!-- conditional classes -->
<p [class.highlight]="this.isTextHighlighted">Lorem ipsum</p>

Dependency Injection

// injectable class
@Injectable()
export class UserService {}

@Injectable()
export class AppService {
  // injected service
  @Inject() userService: UserService;

  // injected with symbol
  @Inject(ChangeDetector) userService: ChangeDetector;
}

Dependencies

The Reflect API for Typescript metadata.

<script src="https://unpkg.com/reflect-metadata"></script>