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

barleytea

v0.6.1

Published

Barleytea.js - a simple, familiar framework

Downloads

5

Readme

Barleytea.js

Barleytea.js strives to be a transparent, familiar framework by:

  • keeping things as close to vanilla js as possible
  • providing a lot of the functionality you like from js frameworks you've worked with
  • in small(-ish), readable chunks so that you can modify/replace/copy at will
  • with removable parts in case you don't need all of it

See our Design Goals for more details on what this framework strives for.

It's currently about 3.1 KB minified/gzipped.

Features

Framework includes:

Templating includes:

  • V-DOM-less DOM diffing
  • xss protection
  • element property setters
  • self-closing tags
  • keyed renders

Also:

  • Use defined elements anywhere, no need to render it within an "app" element
  • Same function signature as customElements.define to minimize framework-specific knowledge

Not interested in all of that? Pick and choose what you want

To use:

Here's a customary to-do list with Barleytea.js:

TodoList.js

class TodoList extends HTMLElement {
  state = {
    todos: ['write tests', 'debug code']
  }

  // this makes it possible to quickly add a todo on an "Enter" keypress
  handleKeyDown = e => {
    if (e.key === 'Enter' && e.target.value) {
      e.preventDefault()
      this.addTodo(e.target.value)
      e.target.value = ''
    }
  }

  // add a new todo with the given string value
  addTodo = todo => {
    this.state.todos = [...this.state.todos, todo]
  }

  // remove a todo by index
  removeTodo = idx => {
    this.state.todos = [...this.state.todos.slice(0, idx), ...this.state.todos.slice(idx + 1)]
  }

  render({ html, keyed, state }) {
    return html`
      <div>
        <h1>To dos:</h1>
        <input 
          placeholder='Enter a new item here' 
          .onkeydown=${this.handleKeyDown}>
        <button 
          .onclick=${this.addTodo}>Add</button>
        <ul>
          ${state.todos.map((todo, idx) => keyed(idx)`
            <li>
              ${todo} 
              <button
                .onclick=${() => this.removeTodo(idx)}>X</button>
            </li>`
          )}
        </ul>
      </div>
    `
  }
}

define('todo-list', TodoList)

index.html

<html>
  <script src="barleytea.js"></script>
  <script src="TodoList.js"></script>
  <body>
    <todo-list />
  </body>
</html>

See it in action here

We're using the vanilla.js way to define a custom element but instead of using customElements.define, we're using our own define function. Within the class definition, we have some magic attributes:

To Download

You can download it from here for now, or get the whole thing from /public/barleytea.js in this repo.

Performance

Seems to run DBMonster pretty quickly, even slightly faster than React, on my machine at least. You can read more about that here

Tests

The template code tests can be run [here]((https://andrewfulrich.gitlab.io/barleytea/test/SpecRunner.html)

There's a lot of code examples in the docs that demonstrate each part of the framework.

To run the tests locally (as well as distromaker etc.), you can npm install and then npm run local

Contribution Steps

Here are some general (not always applicable) steps for contributing back changes to the UI.

  1. Make the change in the code. If it's in the templating, change public/parts/templating.js. If it's in the element framework, change public/parts/framework.js.
  2. Run distroMaker and tests locally with npm install; npm run local and go to http://localhost:3000/public/distroMaker.html and http://localhost:3000/public/test/SpecRunner.html
  3. Make a test for the change
  4. Copy the distroMaker output over to barleytea.js and barleytea-common.js
  5. If it's a new feature, make a new section in the docs explaining the new feature and usage, along with a working code example.
  6. Make a Merge Request