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

@amarajs/plugin-dom

v0.1.0

Published

Provides virtual DOM for AmaraJS web applications.

Downloads

7

Readme

@amarajs/plugin-dom

Plugin middleware for AmaraJS to add HTML to DOM nodes dynamically.

Installation

npm install --save @amarajs/plugin-dom

Usage

// https://github.com/Matt-Esch/virtual-dom
import virtualDom from 'virtual-dom';

import Amara from '@amarajs/core';
import AmaraDOM from '@amarajs/plugin-dom';
import AmaraBrowser from '@amarajs/plugin-engine-browser';
const amara = new Amara([
    AmaraDOM(virtualDom),
    AmaraBrowser()
]);

Feature Type

The @amarajs/plugin-dom middleware allows you to create features of type "dom".

Return Values

For {type: "dom"} features, your apply function should return either an array of virtual DOM nodes or a single root DOM node with optional children.

import h from 'virtual-dom/h';

amara.add({
    type: 'dom',
    targets: ['main'],
    apply: () => [
        h('div', [
            h('p', 'some text'),
            h('p', 'some more text')
        ])
    ]
});

amara.add({
    type: 'dom',
    targets: ['main > div'],
    apply: () => h('p', '... and even more text')
});

Using JSX

You can use JSX instead of creating virtual DOM directly. Simply add the @jsx pragma to the top of your file and use the appropriate configuration for your build process.

For example, the following index.js and rollup.config.js will produce a simple hello world application:

// index.js
/** @jsx h */

import vDOM from 'virtual-dom';
import Amara from '@amarajs/core';
import AmaraDOM from '@amarajs/plugin-dom';
import AmaraBrowser from '@amarajs/plugin-engine-browser';

const h = vDOM.h;

new Amara([
    AmaraBrowser(),
    AmaraDOM(vDOM)
])
    .add({
        type: 'dom',
        targets: ['main'],
        apply: () => (<p>Hello, world!</p>)
    })
    .bootstrap(document.querySelector('body'));
// rollup.config.js
import buble from 'rollup-plugin-buble';
import resolve from 'rollup-plugin-node-resolve';

export default {
    entry: 'index.js',
	useStrict: false,
	plugins: [
        resolve({
            jsnext: true,
            main: true,
            browser: true
        }),
        buble()
    ]
};

Applying Multiple Results to the Same Target

If multiple {type: "dom"} features target the same DOM, the DOM will be appended to the target node in the order the features were applied.

Customization

Construct the @amarajs/plugin-dom instance by providing an instance of VirtualDOM. See https://github.com/Matt-Esch/virtual-dom for details.

Bundled Dependencies

@amarajs/plugin-dom comes bundled with the excellent vdom-parser library to ensure HTML isn't overwritten when applying "dom" features to existing DOM targets.

Contributing

If you have a feature request, please create a new issue so the community can discuss it.

If you find a defect, please submit a bug report that includes a working link to reproduce the problem (for example, using jsBin). Of course, pull requests to fix open issues are always welcome!

License

The MIT License (MIT)

Copyright (c) Dan Barnes

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.