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

bind-element

v1.0.6

Published

make binding between dom element and js object

Downloads

3

Readme

bind-element

make binding between dom element and js object

Install

npm install bind-element

Usage & Api


var bind_element = require("bind-element");

ele('divResult3').innerHTML =
	'<span id=sp1 class=ht-cmd onclick="alert(\'original click 1, on\')">sp1</span>';

//bindElement(el, obj, bindItem) or
//bindElement(el, obj, "type", typeOption, member, memberOption )
//return Error if fail, or `true` if success
var ret1 = bind_element('sp1', null, ["event", "click", function () { alert("listen 1") }]);
var ret2 = bind_element('sp1', null, "event", "click", function () { alert("listen 2") });

assert( !(ret1 instanceof Error) && !(ret2 instanceof Error) );

/*
	bind item array:
		an array of bindItem/namePath, that is,
			[ bindItem|namePath, bindItem|namePath, ...  ]
		
		* namePath: refer query-by-name-path @ npm

		* the default namePath is "", for the entry element. 
*/

//return an object mapping namePath to dom id if success.
//return Error if fail.
//.bindElementArray(el, obj, bindItemArray)
var ret3 = bind_element.array('sp1', null, [
	["event", "click", function () { alert("listen 3") }],
	["event", "click", function () { alert("listen 4") }],
]);
assert( !(ret3 instanceof Error) );

console.log(ret3);

Document

bind item:
	an array to configure element binding,
	[ "type", typeOption, member, memberOption ]	//basic format
	where type and typeOption is related to dom object, 
	member and memberOption is related to js object.
	
	or shortcut format,
	[ "type", typeOption | "typeItem", member, memberOption | .biDirection/0x1 | ".notifyEvent" | .watchJs/0x2 ]	//shortcut format
	
		"type"
			dom type string, "on/event|evt/attr/style|css/class/prop|property"
		
		typeOption
			dom type option
			
			".typeItem" / ".item"
				dom type sub-item string;
				shortcut argument is a string;
			
			.valueMapper / .map
				a value mapper for setting dom item, refer to mapValue().
		
		member
			js member
				"propertyName" | "methodName" | function;
		
		memberOption
			js member option
			
			.biDirection / .bi
				set true to bind both from js to dom and from dom to js;
				if not set, bind in default way;
				shortcut argument is a boolean value, or a number value contain 0x1;
				
			.notifyEvent / .notify
				set name string of bi-direction notify event ( will automatically set biDirection=true );
				if not set, use default event "change";
				shortcut argument is a string;
			
			.watchJs / .watch
				if set true, for type "prop", watch dom property change from js ( will automatically set biDirection=true ).
				shortcut argument is a number value contain 0x2;
			
			.valueMapper / .map
				a value mapper for setting js member, refer to mapValue().
			
	type format:
		
		"on":
			event binding by setting GlobalEventHandlers[ "on" + typeItem ],
			
				[ "on", "click", "methodName" | function, extraArgument ]
		
		"evt|event":
			event binding by addEventListener()
			
				[ "event|evt", "click", "methodName" | function, extraArgument={ listenerOptions } ]
		
		"attr":
			attribute binding,
			
				[ "attr", "title", "propertyName", extraArgument={ biDirection } ]
				[ "attr", "title", "methodName" | function, extraArgument ]		//refer to MutationRecord
		
		"css|style":
			style binding
			
				[ "style", "display", "propertyName", extraArgument={ biDirection } ]
				[ "style", "display", "methodName" | function, extraArgument ]		//will also evoke on any other style change; refer to MutationRecord; 
		
		"class":
			element class binding. default binding member is boolean type.
			
				[ "class", "myClass", "propertyName", extraArgument={ biDirection } ]
				[ "class", "myClass", "methodName" | function, extraArgument ]		//will also evoke on any other class change; refer to MutationRecord;
		
		"prop|property":
			property binding,
			
				[ "prop", "value", "propertyName", extraArgument={ notifyEvent, biDirection, watchJs } ]
				[ "prop", "value", "methodName" | function, extraArgument={ notifyEvent, watchJs, listenerOptions } ]