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

interbind

v0.1.0

Published

A binding and event library useful for implementing the MVC pattern

Downloads

4

Readme

interbind

latest release npm version minified size license

A binding and event library useful for implementing the MVC pattern for JavaScript/TypeScript.

WARNING: This library is in early stages of development. Breaking API changes are expected to happen. See the GitHub issues for more information.

Binding

Binding is the process of establishing a connection between two properties. They are an event-based data flow abstraction managed by the BindingService class and its exposed decorators.

NOTE: The behaviour and function of bindings are similar to data binding in WPF.

Bindings are made up of two components:

  • A bindable, which is the source property in the binding relation. It can have multiple properties targeting it as their source.
  • A bound which is a replica of the bindable property it targets.

Additionally, each binding has a number of optional arguments to configure its behaviour. These include:

  • the mode with which to bind properties.
    • One-way binding causes changes to the bindable property to automatically update the bound property, but changes targeting the bound property are not propegated back to the bindable property.
    • Two-way binding causes changes to either the bindable property or the bound property to automatically update the other.
  • the action which allows the class of the bound property to respond to changes (e.g. refresing a view).
  • the transform to use on the bindable data when updating the bound property. (Only available on one-way bindings.)

Usage

Import the binding components of the library you would like to use.

import { /* BindingService, Bindable, Bind, etc. */ } from "interbind";

bindable

A bindable can be created in the following ways:

  • declaratively using a TypeScript decorator:
class Source {
    @Bindable
    public text?: string;
}
  • imperatively using the BindingService class: NOTE: The imperative definition of binding components is subject to change in the very near future.
class Source {
    public text?: string;

    constructor() {
        BindingService.markBindable(this, "text", String);
        BindingService.makeBindable(this, "text");
    }
}

bound

A bound can be created similarly, using either a declarative or imperative syntax. For example, a binding to an instance of the previously defined bindable would look like this:

  • delaratively using the TypeScript decorator: NOTE: The use of the BindingService.init() call is mandatory to initialize all bound properties declared using decorators. (Static properties reside on their class and thus have to be initialised seperately from instanced properties.)
let src: Source = new Source();

class Replica {
    @Bind(src, "text")
    public text?: string;

    constructor() {
        BindingService.init(this);
    }
}
  • imperatively using the BindingService class:
let src: Source = new Source();

class Replica {
    public text?: string;

    constructor() {
        BindingService.bind(this, "text", src, "text");
    }
}

Example

Here is an example for use with a React component (and corresponding backing store):

import { BindingService, Bindable, Bind, ReactBind } from "interbind";

BindingService.defaultBindAction = ReactBind;

public class User {
    public username: string;
}

public abstract class UserManager {
    @Bindable
    public static currentUser: User;
}

public class Navigation extends React.Component<any, any> {
    @Bind(UserManager, "currentUser")
    private user: User;

    componentDidMount() {
        BindingService.init(this);
    }

    render() {
        return (
            <div>{this.user ? this.user.username : "login"}</div>
        )
    }
}