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

brynja

v4.0.7

Published

Brynja is a virtual DOM implementation with a declarative chaining based javascript API.

Downloads

30

Readme

NPM Version Size Available types License CircleCI Test coverage

Logo

Brynja is a virtual DOM implementation with a declarative chaining based javascript API.

Why Brynja

  • It's small. Less than 4kb gzipped.
  • It requires NO transpilation, everything runs as is in the browser.
  • Everything is 100% typed and ready for Typescript!

Installation

NPM:

npm install brynja

CDN:

<script src="https://cdn.jsdelivr.net/npm/brynja/cdn/brynja.js"></script>

Upgrading from 3.x to 4.x

See upgrading guide

Help me help you

Please ⭐️ this repository!

Demos

Setup - Hello World

You can setup brynja in one of two ways.

Using the default "render" method

The default render method expects a dom element with id 'root' to exsist.

import { render } from 'brynja';

render(_=>_
  .child('p', _=>_
    .text('Hello World!')
  )
);

Setting up your own Renderer instance

import { Renderer } from 'brynja';

const { render } = new Renderer({
  rootElement: document.getElementById('root')
});

render(_=>_
  .child('p', _=>_
    .text('Hello World!')
  )
);

Operations

In brynja, method that are exposed on the chaining api is referred to as operations and are divided into 4 categories; Nesting operations, Mutating operations, Control flow operations, and Effect free operations.

Nesting operations

Nesting operations are used to append children to the current vdom node.

.child(tagName, ctx)

render(_=>_
  .child('div', _=>_
    .text('Hello World!')
  )
);
<div><!--Root-->
  <div>
    Hello World!
  </div>
</div>

.children(tagName, count | items[], ctx)

render(_=>_
  .children('div', 3, (_, i)=>_
    .text(i)
  )
  .children('div', ['a', 'b', 'c'], (_, item)=>_
    .text(item)
  )
);
<div><!--Root-->
  <div>0</div>
  <div>1</div>
  <div>2</div>
  <div>a</div>
  <div>b</div>
  <div>c</div>
</div>

Mutating operations

Mutating operations are used for adding and modifying data on the current vdom node.

.id(value)

render(_=>_
  .child('div', _=>_
    .id('foo')
  )
);
<div><!--Root-->
  <div id="foo"></div>
</div>

.class(valuesArr)

render(_=>_
  .child('div', _=>_
    .class('foo', 'bar')
    .class('biz')
  )
);
<div><!--Root-->
  <div class="foo bar biz"></div>
</div>

.name(value)

render(_=>_
  .child('div', _=>_
    .name('foo')
  )
);
<div><!--Root-->
  <div name="foo"></div>
</div>

.value(value)

render(_=>_
  .child('div', _=>_
    .value('foo')
  )
);
<div><!--Root-->
  <div value="foo"></div>
</div>

.text(value)

render(_=>_
  .child('div', _=>_
    .text('Foo')
  )
);
<div><!--Root-->
  <div>Foo</div>
</div>

.prop(key, value)

render(_=>_
  .child('div', _=>_
    .prop('foo', 'bar')
  )
);
<div><!--Root-->
  <div foo="bar"></div>
</div>

.on(eventName, callback)

render(_=>_
  .child('div', _=>_
    .on('click', e => console.log(e))
  )
);
<div><!--Root-->
  <div><!-- The dom element has the onClick event registered --></div>
</div>

.style(styleObject)

render(_=>_
  .child('div', _=>_
    .text('Hello')
    .style({
      background: 'blue',
      ':hover': {
        background: 'red'
      }
    })
  )
);
<div><!--Root-->
  <div class="brynja-k8xf37">Hello</div>
  <style>
    .brynja-k8xf37 {
      background:  blue;
    }
    .brynja-k8xf37:hover {
      background:  red;
    }
  </style>
</div>

Control flow operations

Control flow operations are used for conditional rendering.

.when(booleanExpression, then_ctx, else_ctx?)

render(_=>_
  .when(true, _=>_
    .child('h1', _=>_)
  )
  .when(false, _=>_
    .child('h1', _=>_)
  ,_=>_
    .child('h2', _=>_)
  )
);
<div><!--Root-->
  <h1><!-- First when: true --></h1>
  <h2><!-- Second when: false --></h2>
</div>

.while(predicate, ctx)

render(_=>_
  .while(i => i < 3, (_, i)=>_
    .child('div', _=>_
      .text(i)
    )
  )
);
<div><!--Root-->
  <div>0</div>
  <div>1</div>
  <div>2</div>
</div>

.do(ctx)

import { createComponent } from 'brynja';

const Image = createComponent((width, height, src) => _=>_
  .child('img', _=>_
    .prop('width', width)
    .prop('height', heigh)
    .prop('src', src)
    .prop('alt', src.substring(src.lastIndexOf('/'), src.lastIndexOf('.')))
  )
);

render(_=>_
  .do(
    Image(64, 64, '/assets/logo_small.png'),
    Image(192, 192, '/assets/logo_medium.png')
  )
);
<div><!--Root-->
  <img src="/assets/logo_small.png" height="64" width="64" alt="logo_small">
  <img src="/assets/logo_medium.png" height="192" width="192" alt="logo_medium">
</div>

Effect free operations

When using Effect free operations you can be sure that no changes will be made in either the dom nor the vdom.

.peek(callback)

Peek at the current vdom node.

render(_=>_
  .peek(console.log)
);
> { tag: 'div', value: null,  text: '', events: {}, props: {}, children: [] }

Legal

Licensed under MIT. See LICENSE.