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

@mobilotronic/sbf

v1.0.14

Published

Simple binding framework

Downloads

3

Readme

Simple binding framework (SBF) sbf_logo

Simple binding framework is a small JavaScript library that helps you build data-driven web applications.

Using observables and two-way binding it can auto-magically update the UI, without the need of writing explicit code for updating the DOM.

It has build in support for validation and localization, which makes it easy to validate and localize parts of your application.

Features

  • Declarative binding
  • Two-way binding
  • Default binding handlers
  • Built-in validation
  • Localization support

Declarative binding

Using declarative binding, you can have multiple bindings against an element.

For example a binding declaration like the following

<input data-bind-sbf="value:{observable:SearchValue,keyboardTriggersChange:true};
attr:{placeholder:Type Search,title:TitleAttribute};
events:{keydown:inputSearchKeyDown}"/>

will:

  • Bind the SearchValue observable, of the current binding context, against the input element's value property.
  • Add a placeholder attribute Type Search as value
  • Bind the TitleAttribute observable,of the current binding context, against the title attribute.
  • Will add a keydown event and bind it to the inputSearchKeyDown method of the current binding context.

Two-way binding

Two-way binding simply means that an SBF observable can be updated both programmatically and UI driven changes.

Default binding handlers

There is a number of default binding handlers, that would most likely be enough for an average application.

Attribute binding handler

Add/removes attributes to an element. If the given values are SBF observables, it will update attribute values automatically.

data-bind-sbf="attr:{placeholder:SearchPlaceHolder}"

If the attribute bound value is null, the attribute will be removed.

Click binding handler

As the name implies, this is really a convenience to add a click listener to an element. data-bind-sbf="click:Search

Same can be achieved using the events binding handler.

Css binding handler

Use this to dynamically add/remove css classes to an element.

data-bind-sbf="css:{input-invalid:IsInputSearchInvalid}"

The bound SBF observable must be of type boolean. It will add a class if the bound observable value is true and remove it if it's false

In the example above, the class input-invalid will be added to the element if the IsInputSearchInvalid is true.

Event binding handler

A binding handler for adding event listeners to an element.

data-bind-sbf="events:{keydown:inputSearchKeyDown}"

ForEach binding handler

ForEach binding is a quite powerful binding handler, as it can render dynamically DOM elements, driven by an array of arbitrary objects.

The foreach binding is taking the 1st child element of the element that is bound to and uses that as template, to render the associated data.

Nested foreach declarations are supported.

Quick example, using a pug template.

table
    thead
        tr
            th(data-bind-sbf="text:Shop")
    tbody(data-bind-sbf="foreach:shops")
        tr
            td(data-bind-sbf="text:shopName")
            td
                table
                    thead
                        tr
                            th(data-bind-sbf="text:Price")
                            th(data-bind-sbf="text:Date")
                    tbody(data-bind-sbf="foreach:details")
                        tr
                            td(data-bind-sbf="text:price")
                            td(data-bind-sbf="text:date")

In the example above the foreach is bound against the tbody element. The handler takes as input a table named shops.

The tbody 1st child element is a tr and that will be used as the template.

It will iterate through all data in the shops table and render a tr for each shop.

If there are any nested foreach declarations the same flow/logic will be applied.

Select binding handler

A binding handler specifically for select elements.

data-bind-sbf="select:{data:ResultPages,value:CurrentPage}"

Template binding handler

Another powerful binding handler, as it can render dynamically DOM elements driven by an array of arbitrary objects.

data-bind-sbf="template:{name:searchResultsTemplate,foreachData:SearchResults}"

In the example above, the handler will look for an HTMLTemplateElement with an id of searchResultsTemplate and render its contents

Text binding handler

A binding handler that sets the value of the textContent of the bound element.

data-bind-sbf="text:About"

Value binding handler

A binding handler specifically for input or textarea elements.

data-bind-sbf="value:{observable:SearchValue,keyboardTriggersChange:true}"

Visible binding handler

A binding handler to control the visibility of an element.

data-bind-sbf="visible:CanShowElement"