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 🙏

© 2025 – Pkg Stats / Ryan Hefner

data-context-binding

v2.0.0-rc.3

Published

Simple and lightweight solution for binding data to DOM elements.

Downloads

46

Readme

Data Context Binding

Simple and lightweight solution for binding data to DOM elements. This manual is also available in HTML5.

Table of contents

Introduction

Data context binding library for browser. This library is a simple and lightweight solution for binding data to DOM elements. Used when building a single-page application (SPA), this library offers a modern approach. This module is part of the 'conextra' framework, which is a simple and easy-to-use single-page application (SPA) framework. You have to try it! A different solution than MVC (model–view–controller).

frontend workflow: data > 'data-context' > 'data-context-binding' > DOM elements backend to frontend workflow: file > 'fs-broker' > 'data-context' > 'ws-user' > 'tiny-https-server' > 'ws13' > browser > 'ws-user' > 'data-context' > 'data-context-binding' > DOM elements

Please note, this version is not backward compatible with version 1.x Requires 'data-context' module version 2.x Note the restrictive requirements of the 'data-context' module.

Features

  • Bind data to the DOM elements.
  • template engine for rendering HTML.
  • Watch for changes in the data and update the DOM elements.

Testing

To test, open the 'index.test.html' file. The tests will run and the results will be displayed.

or on the command line in the project directory 'data-context-binding':

npm test

Usage

This example demonstrates a simple and effective way to bind data to DOM elements using the data-context-binding library.

Summary

  • Import Modules: Load the required JavaScript libraries.
  • Add Data: Define the data in a script tag with type application/json.
  • Bind Data: Use path and bind attributes to bind data to DOM elements.
  • Editable Fields: Allow users to edit data and reflect changes in real-time.
  • Live Changes: Listen for data changes and update the DOM dynamically.

hello-world.html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>data-context-binding</title>
    <!-- STEP 1. Import the modules 'data-context' and 'data-context-binding'.
        Import for an HTML page hosted on the server. -->
    <!--<script src="./datacontext.js"></script>-->
    <!--<script src="./browser.js"></script>-->
    <!-- STEP 1. Import the modules 'data-context' and 'data-context-binding'.
        Import for a standalone HTML page. -->
    <script async src="https://cdn.jsdelivr.net/npm/data-context"></script>
    <script async src="https://cdn.jsdelivr.net/npm/data-context-binding"></script>
    <!-- STEP 2. Add the data to a container with the ID 'data'. Its contents will be read automatically. -->
    <script id="data" type="application/json">
        {
            "doc": {
                /* 1: The metadata-title context object */
                /* 2: The metadata-title context object */
                "title": "Hello World", // The title comment
                /* The metadata-description context object */
                "description": "This is a simple example of data context binding.", // The description comment
                /* { "hidden": "This is a must be hidden value." } */
                "debug": false
            }
        }
    </script>
</head>
<body>
    <!-- STEP 3. Bind data to the DOM elements.
        In this container we use the 'doc' object.
        The 'path' attribute is part of property path. -->
    <div path="doc">
        <div>
            <!-- STEP 3. Bind data to the DOM elements.
            The `path` attribute  is property path in the data object.
            The `bind` attribute is performed data binding. -->
            <h1 path="title" bind>Title</h1>
            <!-- STEP 3. Bind data to the DOM elements.
            The `path` attribute  is property path in the data object.
            The `bind` attribute is performed data binding. -->
            <p path="description" bind>Description</p>
        </div>
    </div>
    <hr />
    <h3>Edit the values:</h3>
    <label for="title">Title:</label>
    <br />
    <!-- STEP 3. Bind data to the DOM elements.
    The `path` attribute  is property path in the data object.
    The `bind` attribute is performed data binding. -->
    <input type="text" path="doc.title" bind style="width:380px" />
    <br />
    <br />
    <label>Description:</label>
    <br />
    <!-- STEP 3. Bind data to the DOM elements.
    The `path` attribute  is property path in the data object.
    The `bind` attribute is performed data binding. -->
    <input type="text" path="doc.description" bind style="width:380px" />
    <hr />
    <label>Live changes:</label>
    <br />
    <!-- STEP 3. Bind data to the DOM elements.
    The `bind` attribute is performed data binding. 
    Listens for data context changes -->
    <textarea cols="50" rows="10" bind="change"></textarea>
</body>
</html>

Here is also a DEMO

References

License

This project is licensed under the MIT License.

Copyright © Manuel Lõhmus

Donate

Donations are welcome and will go towards further development of this project.