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

bynd

v0.1.0

Published

Featherweight N-way data bindings with ES6 Map indexes

Downloads

1

Readme

bynd

Featherweight N-way data bindings with ES6 Map indexes

Usage

(This part is a bit dry and formal: you might want to skip to the Examples section below to see how this ends up being useful.)

The bynd constructor function exported by this module takes a list of property names to treat as primary index keys, and returns an object presenting the same interface as an ES6 Set for manipulating members of the collection. This object is augmented with two more objects, under the names by and move.

The by object contains getters for the members of the collection, with a getter for each key name under that property name (ie. by.id() is the getter for members by their id property).

The move object is for changing one of the properties on a member object that is being handled as an index. Since bynd doesn't mess with creating proxies for the objects you give it

Magic that might well get cut in the next point release

If every enumerable property on the first object you add (when you add it) should be treated as a primary index, you can just call bynd(), and the indexes will be initialized accordingly on the first add.

What? So?

This lets you, for instance, implement data binding for a model-view framework with an invocation like:

var boundData = bynd('id', 'element');

// somewhere in your view initialization
// docFromDb is the doc we're initializing from
var viewContainer = document.createElement('div') /* snip */
boundData.add({
  model: docFromDb,
  id: docFromDb.id,
  element: viewContainer
});

// Now say you have an input that wants to get the document it's modifying:
// you can find it based only on its DOM hierarchy
var editedDoc = boundData.by.element(targetInput.parent).model;

// Similarly, your code that handles updates from the network can get the
// corresponding DOM node easily:
boundData.by.id(incomingDoc.id)

You can extend this out further to maintain identifiers for the entire hierarchy of your view, where each component element is treated as an index, and any sibling element can be found by looking up that element's object in the collection.